API Reference: CoreRegistry System¶
Type-safe static registry system for registering and resolving backbones, necks, heads, and loss functions.
Registry System & Decorators¶
corecv.core.registry
¶
CoreRegistry: Type-safe, generic static registry system for CoreCV.
Provides explicit decorators for registering backbones, necks, heads, and losses with pre-instantiation signature validation. All registries are generic over the registered callable type to maintain type safety throughout the framework.
Example
@register_backbone() ... class MobileNetV3(nn.Module): ... def init(self, width_mult: float = 1.0, **kwargs): ... ... BACKBONE_REGISTRY.validate_signature("MobileNetV3", width_mult=1.0) True
CoreRegistry()
¶
Bases: Generic[T]
Generic, type-safe static registry for callable objects.
Stores registered callables (classes or functions) by name and supports
pre-instantiation signature validation via inspect.signature.
Attributes:
| Name | Type | Description |
|---|---|---|
_registry |
dict[str, type[T] | Callable[..., T]]
|
Internal mapping from name to registered callable. |
Initialize an empty registry.
Source code in src/corecv/core/registry.py
contains(name)
¶
Check whether a name is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The lookup key. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
get(name)
¶
Retrieve a registered object by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The lookup key. |
required |
Returns:
| Type | Description |
|---|---|
type[T] | Callable[..., T]
|
The registered callable. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in src/corecv/core/registry.py
list()
¶
Return a sorted list of all registered names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Alphabetically sorted list of registration keys. |
register(name, obj)
¶
Register an object under the given name.
If the name is already taken, a ValueError is raised to prevent
silent overwrites and accidental name collisions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The lookup key for the registered object. |
required |
obj
|
type[T] | Callable[..., T]
|
The class or callable to register. |
required |
Returns:
| Type | Description |
|---|---|
type[T] | Callable[..., T]
|
The registered object unchanged, allowing use as a decorator. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/corecv/core/registry.py
validate_signature(name, *args, **kwargs)
¶
Validate that the registered callable's signature matches provided args.
Performs static pre-instantiation inspection using inspect.signature
to ensure compatibility without actually calling the callable. Checks
required positional args, optional args with defaults, *args, and
**kwargs support, and type hints when present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The registered callable to validate against. |
required |
*args
|
object
|
Positional arguments to check. |
()
|
**kwargs
|
object
|
Keyword arguments to check. |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
TypeError
|
If the signature is incompatible with the provided args. |
Source code in src/corecv/core/registry.py
get_backbone(name)
¶
Retrieve a backbone class by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registration key. |
required |
Returns:
| Type | Description |
|---|---|
type[Module]
|
The backbone class. |
get_head(name)
¶
Retrieve a head class by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registration key. |
required |
Returns:
| Type | Description |
|---|---|
type[Module]
|
The head class. |
get_loss(name)
¶
Retrieve a loss callable by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registration key. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., Tensor]
|
The loss callable. |
get_neck(name)
¶
Retrieve a neck class by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registration key. |
required |
Returns:
| Type | Description |
|---|---|
type[Module]
|
The neck class. |
list_backbones()
¶
List all registered backbone names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of backbone registration keys. |
list_heads()
¶
List all registered head names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of head registration keys. |
list_losses()
¶
List all registered loss names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of loss registration keys. |
list_necks()
¶
List all registered neck names.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of neck registration keys. |
register_backbone(name=None)
¶
Decorator to register a backbone in BACKBONE_REGISTRY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional explicit name. If |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[type[T] | Callable[..., T]], type[T] | Callable[..., T]]
|
A decorator that registers and returns the decorated object unchanged. |
Source code in src/corecv/core/registry.py
register_head(name=None)
¶
Decorator to register a head in HEAD_REGISTRY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional explicit name. If |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[type[T] | Callable[..., T]], type[T] | Callable[..., T]]
|
A decorator that registers and returns the decorated object unchanged. |
Source code in src/corecv/core/registry.py
register_loss(name=None)
¶
Decorator to register a loss in LOSS_REGISTRY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional explicit name. If |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[type[T] | Callable[..., T]], type[T] | Callable[..., T]]
|
A decorator that registers and returns the decorated object unchanged. |
Source code in src/corecv/core/registry.py
register_neck(name=None)
¶
Decorator to register a neck in NECK_REGISTRY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional explicit name. If |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[type[T] | Callable[..., T]], type[T] | Callable[..., T]]
|
A decorator that registers and returns the decorated object unchanged. |