Bases: _Base
A global dictionary that stores information about the algorithms used and
their corresponding pipeline. It contains a mapping of algorithm names to
the algorithm class object.
| >>> from changedet.algos import AlgoCatalog
>>> import pprint
>>> pprint.pprint(AlgoCatalog)
{'cva': <class 'changedet.algos.cva.CVA'>,
'imgdiff': <class 'changedet.algos.imgdiff.ImageDiff'>,
'ipca': <class 'changedet.algos.ipca.IteratedPCA'>,
'irmad': <class 'changedet.algos.irmad.IRMAD'>}
|
Source code in changedet/algos/catalog.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 | class AlgoCatalog_(_Base):
"""
A global dictionary that stores information about the algorithms used and
their corresponding pipeline. It contains a mapping of algorithm names to
the algorithm class object.
```
>>> from changedet.algos import AlgoCatalog
>>> import pprint
>>> pprint.pprint(AlgoCatalog)
{'cva': <class 'changedet.algos.cva.CVA'>,
'imgdiff': <class 'changedet.algos.imgdiff.ImageDiff'>,
'ipca': <class 'changedet.algos.ipca.IteratedPCA'>,
'irmad': <class 'changedet.algos.irmad.IRMAD'>}
```
"""
def register(self, name: str) -> Callable[[type[MetaAlgo]], type[MetaAlgo]]:
def inner_wrapper(wrapped_class: type[MetaAlgo]) -> type[MetaAlgo]:
if name in self.keys():
raise AssertionError(f"Algorithm {name} already exists.")
self[name] = wrapped_class
return wrapped_class
return inner_wrapper
def get(self, name: str) -> type[MetaAlgo]: # type: ignore[override]
try:
f = self[name]
except KeyError as e:
if isinstance(name, str):
avail_algos = ", ".join(list(self.keys()))
raise KeyError(
f"Algorithm {name} is not registered. Available algorithms are: {avail_algos}"
) from e
else:
f = None
return f
def list(self) -> list[str]:
"""List all registered algorithms.
Returns:
list[str]: List of algorithm names
"""
return list(sorted(self.keys()))
def remove(self, name: str) -> None:
"""
Alias of ``pop``.
"""
self.pop(name)
|
list()
List all registered algorithms.
Returns:
Type |
Description |
list[str]
|
list[str]: List of algorithm names
|
Source code in changedet/algos/catalog.py
| def list(self) -> list[str]:
"""List all registered algorithms.
Returns:
list[str]: List of algorithm names
"""
return list(sorted(self.keys()))
|
remove(name)
Alias of pop
.
Source code in changedet/algos/catalog.py
| def remove(self, name: str) -> None:
"""
Alias of ``pop``.
"""
self.pop(name)
|