Embeddings#

vision_architectures.layers.embeddings.get_absolute_position_embeddings_3d(dim, grid_size, spacing=(1.0, 1.0, 1.0), crop_offset=None, channels_first=True)[source]#
Return type:

Tensor

vision_architectures.layers.embeddings.get_timestep_embeddings_1d(dim, indices)[source]#
Return type:

Tensor

vision_architectures.layers.embeddings.get_all_timestep_embeddings_1d(dim, length, device=device(type='cpu'))[source]#
Return type:

Tensor

vision_architectures.layers.embeddings.get_absolute_position_embeddings_1d(dim, length, device=device(type='cpu'))[source]#
Return type:

Tensor

pydantic model vision_architectures.layers.embeddings.RelativePositionEmbeddings3DConfig[source]#

Bases: CustomBaseModel

Show JSON schema
{
   "title": "RelativePositionEmbeddings3DConfig",
   "type": "object",
   "properties": {
      "num_heads": {
         "description": "Number of query attention heads",
         "title": "Num Heads",
         "type": "integer"
      },
      "grid_size": {
         "maxItems": 3,
         "minItems": 3,
         "prefixItems": [
            {
               "type": "integer"
            },
            {
               "type": "integer"
            },
            {
               "type": "integer"
            }
         ],
         "title": "Grid Size",
         "type": "array"
      }
   },
   "required": [
      "num_heads",
      "grid_size"
   ]
}

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_heads: int [Required]#

Number of query attention heads

Validated by:
field grid_size: tuple[int, int, int] [Required]#
Validated by:
property num_patches: int#
validator validate_before  »  all fields[source]#

Base class method for validating data before creating the model.

validator validate  »  all fields[source]#

Base method for validating the model after creation.

pydantic model vision_architectures.layers.embeddings.AbsolutePositionEmbeddings3DConfig[source]#

Bases: CustomBaseModel

Show JSON schema
{
   "title": "AbsolutePositionEmbeddings3DConfig",
   "type": "object",
   "properties": {
      "dim": {
         "anyOf": [
            {
               "type": "integer"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Dim"
      },
      "grid_size": {
         "anyOf": [
            {
               "maxItems": 3,
               "minItems": 3,
               "prefixItems": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "integer"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Grid Size"
      },
      "learnable": {
         "default": false,
         "title": "Learnable",
         "type": "boolean"
      }
   }
}

Config:
  • arbitrary_types_allowed: bool = True

  • extra: str = ignore

  • validate_default: bool = True

  • validate_assignment: bool = True

  • validate_return: bool = True

Fields:
Validators:
field dim: int | None = None#
Validated by:
field grid_size: tuple[int, int, int] | None = None#
Validated by:
field learnable: bool = False#
Validated by:
property num_patches: int#
validator validate_before  »  all fields[source]#

Base class method for validating data before creating the model.

validator validate  »  all fields[source]#

Base method for validating the model after creation.

pydantic model vision_architectures.layers.embeddings.AbsolutePositionEmbeddings1DConfig[source]#

Bases: CustomBaseModel

Show JSON schema
{
   "title": "AbsolutePositionEmbeddings1DConfig",
   "type": "object",
   "properties": {
      "dim": {
         "anyOf": [
            {
               "type": "integer"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Dim"
      },
      "length": {
         "anyOf": [
            {
               "type": "integer"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Length"
      },
      "learnable": {
         "default": false,
         "title": "Learnable",
         "type": "boolean"
      }
   }
}

Config:
  • arbitrary_types_allowed: bool = True

  • extra: str = ignore

  • validate_default: bool = True

  • validate_assignment: bool = True

  • validate_return: bool = True

Fields:
Validators:
field dim: int | None = None#
Validated by:
field length: int | None = None#
Validated by:
field learnable: bool = False#
Validated by:
validator validate  »  all fields[source]#

Base method for validating the model after creation.

pydantic model vision_architectures.layers.embeddings.PatchEmbeddings3DConfig[source]#

Bases: CNNBlockConfig

Show JSON schema
{
   "title": "PatchEmbeddings3DConfig",
   "type": "object",
   "properties": {
      "in_channels": {
         "title": "In Channels",
         "type": "integer"
      },
      "out_channels": {
         "default": null,
         "title": "Out Channels",
         "type": "null"
      },
      "kernel_size": {
         "default": null,
         "title": "Kernel Size",
         "type": "null"
      },
      "padding": {
         "anyOf": [
            {
               "type": "integer"
            },
            {
               "items": {
                  "type": "integer"
               },
               "type": "array"
            },
            {
               "type": "string"
            }
         ],
         "default": "same",
         "title": "Padding"
      },
      "stride": {
         "default": 1,
         "title": "Stride",
         "type": "integer"
      },
      "conv_kwargs": {
         "additionalProperties": true,
         "default": {},
         "title": "Conv Kwargs",
         "type": "object"
      },
      "transposed": {
         "default": false,
         "description": "Whether to perform ConvTranspose instead of Conv",
         "title": "Transposed",
         "type": "boolean"
      },
      "normalization": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": "batchnorm3d",
         "title": "Normalization"
      },
      "normalization_pre_args": {
         "default": [],
         "items": {},
         "title": "Normalization Pre Args",
         "type": "array"
      },
      "normalization_post_args": {
         "default": [],
         "items": {},
         "title": "Normalization Post Args",
         "type": "array"
      },
      "normalization_kwargs": {
         "additionalProperties": true,
         "default": {},
         "title": "Normalization Kwargs",
         "type": "object"
      },
      "activation": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": "relu",
         "title": "Activation"
      },
      "activation_kwargs": {
         "additionalProperties": true,
         "default": {},
         "title": "Activation Kwargs",
         "type": "object"
      },
      "sequence": {
         "default": "CNA",
         "enum": [
            "C",
            "AC",
            "CA",
            "CD",
            "CN",
            "DC",
            "NC",
            "ACD",
            "ACN",
            "ADC",
            "ANC",
            "CAD",
            "CAN",
            "CDA",
            "CDN",
            "CNA",
            "CND",
            "DAC",
            "DCA",
            "DCN",
            "DNC",
            "NAC",
            "NCA",
            "NCD",
            "NDC",
            "ACDN",
            "ACND",
            "ADCN",
            "ADNC",
            "ANCD",
            "ANDC",
            "CADN",
            "CAND",
            "CDAN",
            "CDNA",
            "CNAD",
            "CNDA",
            "DACN",
            "DANC",
            "DCAN",
            "DCNA",
            "DNAC",
            "DNCA",
            "NACD",
            "NADC",
            "NCAD",
            "NCDA",
            "NDAC",
            "NDCA"
         ],
         "title": "Sequence",
         "type": "string"
      },
      "drop_prob": {
         "default": 0.0,
         "title": "Drop Prob",
         "type": "number"
      },
      "patch_size": {
         "maxItems": 3,
         "minItems": 3,
         "prefixItems": [
            {
               "type": "integer"
            },
            {
               "type": "integer"
            },
            {
               "type": "integer"
            }
         ],
         "title": "Patch Size",
         "type": "array"
      },
      "dim": {
         "title": "Dim",
         "type": "integer"
      },
      "norm_layer": {
         "default": "layernorm",
         "title": "Norm Layer",
         "type": "string"
      }
   },
   "required": [
      "in_channels",
      "patch_size",
      "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 patch_size: tuple[int, int, int] [Required]#
Validated by:
field in_channels: int [Required]#
Validated by:
field dim: int [Required]#
Validated by:
field norm_layer: str = 'layernorm'#
Validated by:
field out_channels: None = None#
Validated by:
field kernel_size: None = None#
Validated by:
validator validate_before  »  all fields[source]#

Base class method for validating data before creating the model.

vision_architectures.layers.embeddings.get_coords_grid(grid_size)[source]#
Return type:

Tensor

class vision_architectures.layers.embeddings.RelativePositionEmbeddings3D(config={}, **kwargs)[source]#

Bases: Module

__init__(config={}, **kwargs)[source]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward()[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.

class vision_architectures.layers.embeddings.RelativePositionEmbeddings3DMetaNetwork(config={}, checkpointing_level=0, **kwargs)[source]#

Bases: Module

__init__(config={}, checkpointing_level=0, **kwargs)[source]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

get_relative_position_embeddings_table()[source]#
forward()[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.

vision_architectures.layers.embeddings.get_sinusoidal_embeddings_3d(dim, grid_size, spacing=(1.0, 1.0, 1.0), crop_offset=None, channels_first=True)[source]#
Return type:

Tensor

class vision_architectures.layers.embeddings.AbsolutePositionEmbeddings3D(config={}, **kwargs)[source]#

Bases: Module

__init__(config={}, **kwargs)[source]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, embedding_type='add', spacings=None, channels_first=True, crop_offsets=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.

vision_architectures.layers.embeddings.get_specific_sinusoidal_embeddings_1d(dim, indices)[source]#
Return type:

Tensor

vision_architectures.layers.embeddings.get_sinusoidal_embeddings_1d(dim, length, device=device(type='cpu'))[source]#
Return type:

Tensor

class vision_architectures.layers.embeddings.AbsolutePositionEmbeddings1D(config={}, **kwargs)[source]#

Bases: Module

__init__(config={}, **kwargs)[source]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, embedding_type='add')[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.

class vision_architectures.layers.embeddings.PatchEmbeddings3D(config={}, checkpointing_level=0, **kwargs)[source]#

Bases: CNNBlock3D

__init__(config={}, checkpointing_level=0, **kwargs)[source]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.