Codebook#
- pydantic model vision_architectures.layers.codebook.CodebookConfig[source]#
Bases:
CustomBaseModel
Show JSON schema
{ "title": "CodebookConfig", "type": "object", "properties": { "num_vectors": { "title": "Num Vectors", "type": "integer" }, "dim": { "title": "Dim", "type": "integer" }, "revive_dead_vectors_after_n_steps": { "default": 100, "title": "Revive Dead Vectors After N Steps", "type": "integer" }, "ema_decay": { "anyOf": [ { "type": "number" }, { "type": "null" } ], "default": 0.99, "title": "Ema Decay" } }, "required": [ "num_vectors", "dim" ] }
- Config:
arbitrary_types_allowed: bool = True
extra: str = ignore
validate_default: bool = True
validate_assignment: bool = True
validate_return: bool = True
- Fields:
- Validators:
-
field num_vectors:
int
[Required]# - Validated by:
-
field dim:
int
[Required]# - Validated by:
-
field revive_dead_vectors_after_n_steps:
int
= 100# - Validated by:
-
field ema_decay:
float
|None
= 0.99# - Validated by:
- class vision_architectures.layers.codebook.Codebook(config={}, use_ema=True, **kwargs)[source]#
Bases:
Module
,PyTorchModelHubMixin
- __init__(config={}, use_ema=True, **kwargs)[source]#
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- calculate_perplexity(indices)#
- forward(x, channels_first=None)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.