Component Registry

Component Registry: Discover and access all building blocks.

The registry provides a unified interface to discover, inspect, and instantiate any component in the torchvision-customizer package.

Example

>>> from torchvision_customizer import registry
>>> registry.list()  # List all components
['conv', 'residual', 'se', 'inception', ...]
>>> registry.list(category='attention')
['channel', 'spatial', 'cbam', 'multihead']
>>> Conv = registry.get('conv')
>>> block = Conv(in_channels=64, out_channels=128)
class ComponentRegistry[source]

Bases: object

Central registry for all neural network components.

The registry allows: - Component discovery via list() and categories() - Component inspection via info() - Component instantiation via get() - Custom component registration via register()

Example

>>> registry = ComponentRegistry()
>>> registry.list()
['conv', 'residual', 'se', ...]
>>> Conv = registry.get('conv')
>>> block = Conv(64, 128)
categories() List[str][source]

List all available categories.

get(name: str, **kwargs) Type[Module] | Module[source]

Get a component class by name, or instantiate if kwargs provided.

Parameters:
  • name – Component name or alias

  • **kwargs – If provided, instantiate the component with these args

Returns:

Component class if no kwargs, instantiated module if kwargs provided

Example

>>> Conv = registry.get('conv')  # Get class
>>> block = registry.get('conv', in_channels=64, out_channels=128)  # Get instance
info(name: str) dict[source]

Get detailed information about a component.

Parameters:

name – Component name or alias

Returns:

Dictionary with component information

list(category: str = None) List[str][source]

List all registered component names.

Parameters:

category – Optional category filter

Returns:

List of component names

register(name: str, category: str = 'custom', aliases: List[str] = None)[source]

Decorator to register a custom component.

Example

>>> @registry.register('my_block', category='block')
... class MyBlock(nn.Module):
...     def __init__(self, channels):
...         super().__init__()
...         self.conv = nn.Conv2d(channels, channels, 3, padding=1)
register(name: str, category: str = 'other')[source]

Decorator to register a new component.

get(name: str, **kwargs)[source]

Get a component class or instance by name.

list(category: str = None) list[source]

List all registered components, optionally filtered by category.

info(name: str) dict[source]

Get detailed information about a component.

categories() list[source]

List all available component categories.

class ComponentRegistry[source]

Bases: object

Central registry for all neural network components.

The registry allows: - Component discovery via list() and categories() - Component inspection via info() - Component instantiation via get() - Custom component registration via register()

Example

>>> registry = ComponentRegistry()
>>> registry.list()
['conv', 'residual', 'se', ...]
>>> Conv = registry.get('conv')
>>> block = Conv(64, 128)
register(name: str, category: str = 'custom', aliases: List[str] = None)[source]

Decorator to register a custom component.

Example

>>> @registry.register('my_block', category='block')
... class MyBlock(nn.Module):
...     def __init__(self, channels):
...         super().__init__()
...         self.conv = nn.Conv2d(channels, channels, 3, padding=1)
get(name: str, **kwargs) Type[Module] | Module[source]

Get a component class by name, or instantiate if kwargs provided.

Parameters:
  • name – Component name or alias

  • **kwargs – If provided, instantiate the component with these args

Returns:

Component class if no kwargs, instantiated module if kwargs provided

Example

>>> Conv = registry.get('conv')  # Get class
>>> block = registry.get('conv', in_channels=64, out_channels=128)  # Get instance
list(category: str = None) List[str][source]

List all registered component names.

Parameters:

category – Optional category filter

Returns:

List of component names

categories() List[str][source]

List all available categories.

info(name: str) dict[source]

Get detailed information about a component.

Parameters:

name – Component name or alias

Returns:

Dictionary with component information

Functions

register(name: str, category: str = 'other')[source]

Decorator to register a new component.

get(name: str, **kwargs)[source]

Get a component class or instance by name.

list(category: str = None) list[source]

List all registered components, optionally filtered by category.

info(name: str) dict[source]

Get detailed information about a component.

categories() list[source]

List all available component categories.