FPN2D#
- pydantic model vision_architectures.nets.fpn_2d.FPN2DBlockConfig[source]#
Bases:
CNNBlockConfigShow JSON schema
{ "title": "FPN2DBlockConfig", "type": "object", "properties": { "in_channels": { "default": null, "description": "Calculated based on other parameters", "title": "In Channels", "type": "null" }, "out_channels": { "default": null, "description": "Calculated based on other parameters", "title": "Out Channels", "type": "null" }, "kernel_size": { "default": 3, "description": "Kernel size for the convolutional layers in the FPN block.", "title": "Kernel Size", "type": "integer" }, "padding": { "anyOf": [ { "type": "integer" }, { "items": { "type": "integer" }, "type": "array" }, { "type": "string" } ], "default": "same", "description": "Padding for the convolution. Can be 'same' or an integer/tuple of integers.", "title": "Padding" }, "stride": { "anyOf": [ { "type": "integer" }, { "items": { "type": "integer" }, "type": "array" } ], "default": 1, "description": "Stride for the convolution", "title": "Stride" }, "conv_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the convolution layer", "title": "Conv Kwargs", "type": "object" }, "transposed": { "default": false, "description": "Whether to perform ConvTranspose instead of Conv", "title": "Transposed", "type": "boolean" }, "normalization": { "default": "batchnorm2d", "title": "Normalization", "type": "string" }, "normalization_pre_args": { "default": [], "description": "Arguments for the normalization layer before providing the dimension. Useful when using GroupNorm layers are being used to specify the number of groups.", "items": {}, "title": "Normalization Pre Args", "type": "array" }, "normalization_post_args": { "default": [], "description": "Arguments for the normalization layer after providing the dimension.", "items": {}, "title": "Normalization Post Args", "type": "array" }, "normalization_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the normalization layer", "title": "Normalization Kwargs", "type": "object" }, "activation": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": "relu", "description": "Activation function type.", "title": "Activation" }, "activation_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the activation function.", "title": "Activation Kwargs", "type": "object" }, "sequence": { "default": "CNA", "description": "Sequence of operations in the block.", "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, "description": "Dropout probability.", "title": "Drop Prob", "type": "number" }, "dim": { "description": "Input channel dimension of the FPN block.", "title": "Dim", "type": "integer" }, "skip_conn_dim": { "description": "Input channel dimension of the skip connection.", "title": "Skip Conn Dim", "type": "integer" }, "interpolation_mode": { "default": "bilinear", "description": "Interpolation mode for the FPN block.", "title": "Interpolation Mode", "type": "string" }, "merge_method": { "default": "add", "description": "Merge method for the FPN block.", "enum": [ "add", "concat" ], "title": "Merge Method", "type": "string" } }, "required": [ "dim", "skip_conn_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 dim:
int[Required]# Input channel dimension of the FPN block.
- Validated by:
-
field kernel_size:
int= 3# Kernel size for the convolutional layers in the FPN block.
- Validated by:
-
field skip_conn_dim:
int[Required]# Input channel dimension of the skip connection.
- Validated by:
-
field interpolation_mode:
str= 'bilinear'# Interpolation mode for the FPN block.
- Validated by:
-
field merge_method:
Literal['add','concat'] = 'add'# Merge method for the FPN block.
- Validated by:
-
field normalization:
str= 'batchnorm2d'# - Validated by:
-
field in_channels:
None= None# Calculated based on other parameters
- Validated by:
-
field out_channels:
None= None# Calculated based on other parameters
- Validated by:
- pydantic model vision_architectures.nets.fpn_2d.FPN2DConfig[source]#
Bases:
CustomBaseModelShow JSON schema
{ "title": "FPN2DConfig", "type": "object", "properties": { "blocks": { "description": "List of configs for the FPN blocks.", "items": { "$ref": "#/$defs/FPN2DBlockConfig" }, "title": "Blocks", "type": "array" } }, "$defs": { "FPN2DBlockConfig": { "properties": { "in_channels": { "default": null, "description": "Calculated based on other parameters", "title": "In Channels", "type": "null" }, "out_channels": { "default": null, "description": "Calculated based on other parameters", "title": "Out Channels", "type": "null" }, "kernel_size": { "default": 3, "description": "Kernel size for the convolutional layers in the FPN block.", "title": "Kernel Size", "type": "integer" }, "padding": { "anyOf": [ { "type": "integer" }, { "items": { "type": "integer" }, "type": "array" }, { "type": "string" } ], "default": "same", "description": "Padding for the convolution. Can be 'same' or an integer/tuple of integers.", "title": "Padding" }, "stride": { "anyOf": [ { "type": "integer" }, { "items": { "type": "integer" }, "type": "array" } ], "default": 1, "description": "Stride for the convolution", "title": "Stride" }, "conv_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the convolution layer", "title": "Conv Kwargs", "type": "object" }, "transposed": { "default": false, "description": "Whether to perform ConvTranspose instead of Conv", "title": "Transposed", "type": "boolean" }, "normalization": { "default": "batchnorm2d", "title": "Normalization", "type": "string" }, "normalization_pre_args": { "default": [], "description": "Arguments for the normalization layer before providing the dimension. Useful when using GroupNorm layers are being used to specify the number of groups.", "items": {}, "title": "Normalization Pre Args", "type": "array" }, "normalization_post_args": { "default": [], "description": "Arguments for the normalization layer after providing the dimension.", "items": {}, "title": "Normalization Post Args", "type": "array" }, "normalization_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the normalization layer", "title": "Normalization Kwargs", "type": "object" }, "activation": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": "relu", "description": "Activation function type.", "title": "Activation" }, "activation_kwargs": { "additionalProperties": true, "default": {}, "description": "Additional keyword arguments for the activation function.", "title": "Activation Kwargs", "type": "object" }, "sequence": { "default": "CNA", "description": "Sequence of operations in the block.", "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, "description": "Dropout probability.", "title": "Drop Prob", "type": "number" }, "dim": { "description": "Input channel dimension of the FPN block.", "title": "Dim", "type": "integer" }, "skip_conn_dim": { "description": "Input channel dimension of the skip connection.", "title": "Skip Conn Dim", "type": "integer" }, "interpolation_mode": { "default": "bilinear", "description": "Interpolation mode for the FPN block.", "title": "Interpolation Mode", "type": "string" }, "merge_method": { "default": "add", "description": "Merge method for the FPN block.", "enum": [ "add", "concat" ], "title": "Merge Method", "type": "string" } }, "required": [ "dim", "skip_conn_dim" ], "title": "FPN2DBlockConfig", "type": "object" } }, "required": [ "blocks" ] }
- Config:
arbitrary_types_allowed: bool = True
extra: str = ignore
validate_default: bool = True
validate_assignment: bool = True
validate_return: bool = True
- Fields:
- Validators:
validate»all fieldsvalidate_before»all fields
-
field blocks:
list[FPN2DBlockConfig] [Required]# List of configs for the FPN blocks.
- Validated by:
- property dim: int#
Returns the input channel dimension of the first block.
- class vision_architectures.nets.fpn_2d.FPN2DBlock(config={}, is_deepest=False, checkpointing_level=0, **kwargs)[source]#
Bases:
ModuleA 2D FPN block to merge features from two scales.
- __init__(config={}, is_deepest=False, checkpointing_level=0, **kwargs)[source]#
Initialize the FPN2DBlock block.
- Parameters:
config (
FPN2DBlockConfig) – An instance of the Config class that contains all the configuration parameters. It can also be passed as a dictionary and the instance will be created automatically.is_deepest (
bool) – Whether the block is the deepest in the net. In this case, there is no deeper feature to interpolate and merge.checkpointing_level (
int) – The level of checkpointing to use for activation checkpointing. Refer toActivationCheckpointingfor more details.**kwargs – Additional keyword arguments for configuration.
- forward(skip_conn_features, deeper_features, channels_first=True)[source]#
Interpolate the features of the deeper scale and merge them with the features of the skip connection.
- Parameters:
skip_conn_features (
Tensor) – Tensor of shape (B, C, Y, X) or (B, Y, X, C) representing the input features.deeper_features (
Tensor|None) – Tensor of shape (B, C, Y, X) or (B, Y, X, C) representing the input features.channels_first (
bool) – Whether the inputs are in channels first format (B, C, …) or not (B, …, C). Assumed to be true for both set of features.
- Return type:
Tensor- Returns:
Tensor of shape (B, C, Y, X) or (B, Y, X, C) representing the output features.
- class vision_architectures.nets.fpn_2d.FPN2D(config={}, checkpointing_level=0, **kwargs)[source]#
Bases:
Module,PyTorchModelHubMixinFeature Pyramid Network 2D
- __init__(config={}, checkpointing_level=0, **kwargs)[source]#
Initialize the FPN2D block.
- Parameters:
config (
FPN2DConfig) – An instance of the Config class that contains all the configuration parameters. It can also be passed as a dictionary and the instance will be created automatically.checkpointing_level (
int) – The level of checkpointing to use for activation checkpointing. Refer toActivationCheckpointingfor more details.**kwargs – Additional keyword arguments for configuration.
- forward(features, channels_first=True)[source]#
Pass the multi-scale features of the encoder through the FPN2D.
- Parameters:
features (
list[Tensor]) – A list of 2D multi-scale features. Tensor of shape (B, C, Y, X) or (B, Y, X, C) representing the input features.channels_first (
bool) – Whether the inputs are in channels first format (B, C, …) or not (B, …, C).
- Return type:
list[Tensor]- Returns:
A list of 2D multi-scale features. Tensor of shape (B, C, Y, X) or (B, Y, X, C) representing the output features.