super_gradients.training.models package

Submodules

super_gradients.training.models.all_architectures module

super_gradients.training.models.csp_darknet53 module

CSP Darknet

credits: https://github.com/ultralytics

class super_gradients.training.models.csp_darknet53.Bottleneck(input_channels, output_channels, shortcut=True, groups=1, width_mult_factor: float = 1.0, activation_func_type: type = <class 'torch.nn.modules.activation.Hardswish'>)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.csp_darknet53.BottleneckCSP(input_channels, output_channels, bottleneck_blocks_num=1, shortcut=True, groups=1, expansion=0.5, width_mult_factor: float = 1.0, depth_mult_factor: float = 1.0)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.csp_darknet53.C3(input_channels, output_channels, bottleneck_blocks_num=1, shortcut=True, groups=1, expansion=0.5, width_mult_factor: float = 1.0, depth_mult_factor: float = 1.0, activation_func_type: type = <class 'torch.nn.modules.activation.SiLU'>)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.csp_darknet53.CSPDarknet53(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.csp_darknet53.Conv(input_channels, output_channels, kernel=1, stride=1, padding=None, groups=1, activation_func_type: type = <class 'torch.nn.modules.activation.Hardswish'>)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

fuseforward(x)[source]
training: bool
class super_gradients.training.models.csp_darknet53.Focus(input_channels, output_channels, kernel=1, stride=1, padding=None, groups=1, width_mult_factor: float = 1.0)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
exception super_gradients.training.models.csp_darknet53.NumClassesMissingException[source]

Bases: Exception

class super_gradients.training.models.csp_darknet53.SPP(input_channels, output_channels, k=(5, 9, 13), width_mult_factor: float = 1.0)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.csp_darknet53.SPPF(input_channels, output_channels, k: int = 5, width_mult_factor: float = 1.0, activation_func_type: type = <class 'torch.nn.modules.activation.SiLU'>)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.csp_darknet53.ViewModule(features=1024)[source]

Bases: torch.nn.modules.module.Module

Returns a reshaped version of the input, to be used in None-Backbone Mode

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.csp_darknet53.autopad(kernel, padding=None)[source]
super_gradients.training.models.csp_darknet53.width_multiplier(original, factor)[source]

super_gradients.training.models.darknet53 module

Darknet

credits: https://github.com/ultralytics

class super_gradients.training.models.darknet53.DarkResidualBlock(in_channels, shortcut=True)[source]

Bases: torch.nn.modules.module.Module

DarkResidualBlock - The Darknet Residual Block

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.darknet53.Darknet53(arch_params=None, backbone_mode=True, num_classes=None)[source]

Bases: super_gradients.training.models.darknet53.Darknet53Base

forward(x)[source]
forward - Forward pass on the modules list
param x

The input data

return

forward pass for backbone pass or classification pass

get_modules_list()[source]
training: bool
class super_gradients.training.models.darknet53.Darknet53Base[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.darknet53.ViewModule(features=1024)[source]

Bases: torch.nn.modules.module.Module

Returns a reshaped version of the input, to be used in None-Backbone Mode

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.darknet53.create_conv_module(in_channels, out_channels, kernel_size=3, stride=1)[source]

super_gradients.training.models.ddrnet module

class super_gradients.training.models.ddrnet.AnyBackBoneDDRNet23(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.ddrnet.DDRNetCustom

training: bool
class super_gradients.training.models.ddrnet.BasicDDRBackBone(block: type, width: int, layers: list, input_channels: int)[source]

Bases: super_gradients.training.models.ddrnet.DDRBackBoneBase

training: bool
super_gradients.training.models.ddrnet.ConvBN(in_channels: int, out_channels: int, kernel_size: int, bias=True, stride=1, padding=0, add_relu=False)[source]
class super_gradients.training.models.ddrnet.DAPPM(in_planes: int, branch_planes: int, out_planes: int, kernel_sizes: list, strides: list, inter_mode: str = 'bilinear')[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.ddrnet.DAPPMBranch(kernel_size: int, stride: int, in_planes: int, branch_planes: int, inter_mode: str = 'bilinear')[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

All branches of the DAPPM but the first one receive the output of the previous branch as a second input :param x: in branch 0 - the original input of the DAPPM. in other branches - a list containing the original input and the output of the previous branch.

training: bool
class super_gradients.training.models.ddrnet.DDRBackBoneBase[source]

Bases: torch.nn.modules.module.Module

A base class defining functions that must be supported by DDRBackBones

get_backbone_output_number_of_channels()[source]

Return a dictionary of the shapes of each output of the backbone to determine the in_channels of the skip and compress layers

training: bool
validate_backbone_attributes()[source]
class super_gradients.training.models.ddrnet.DDRNet(backbone: type, additional_layers: list, upscale_module: torch.nn.modules.module.Module, num_classes: int, highres_planes: int, spp_width: int, head_width: int, aux_head: bool = False, ssp_inter_mode: str = 'bilinear', segmentation_inter_mode: str = 'bilinear', skip_block: Optional[type] = None, layer5_block: type = <class 'super_gradients.training.models.resnet.Bottleneck'>, layer5_bottleneck_expansion: int = 2, classification_mode=False, spp_kernel_sizes: list = [1, 5, 9, 17, 0], spp_strides: list = [1, 2, 4, 8, 0])[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.ddrnet.DDRNet23(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.ddrnet.DDRNetCustom

training: bool
class super_gradients.training.models.ddrnet.DDRNet23Slim(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.ddrnet.DDRNetCustom

training: bool
class super_gradients.training.models.ddrnet.DDRNetCustom(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.ddrnet.DDRNet

training: bool
class super_gradients.training.models.ddrnet.RegnetDDRBackBone(regnet_module: type)[source]

Bases: super_gradients.training.models.ddrnet.DDRBackBoneBase

Translation of Regnet to fit DDR model

training: bool
class super_gradients.training.models.ddrnet.SegmentHead(in_planes: int, inter_planes: int, out_planes: int, scale_factor: int, inter_mode: str = 'bilinear')[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.ddrnet.UpscaleOnline(mode='bilinear')[source]

Bases: torch.nn.modules.module.Module

In some cases the required scale/size for the scaling is known only when the input is received. This class support such cases. only the interpolation mode is set in advance.

forward(x, output_height: int, output_width: int)[source]

Defines 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.

training: bool

super_gradients.training.models.densenet module

super_gradients.training.models.densenet.CustomizedDensnet(arch_params)[source]
class super_gradients.training.models.densenet.DenseNet(growth_rate: int, structure: list, num_init_features: int, bn_size: int, drop_rate: float, num_classes: int)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.densenet.densenet121(arch_params)[source]
super_gradients.training.models.densenet.densenet161(arch_params)[source]
super_gradients.training.models.densenet.densenet169(arch_params)[source]
super_gradients.training.models.densenet.densenet201(arch_params)[source]

super_gradients.training.models.dpn module

Dual Path Networks in PyTorch.

Credits: https://github.com/kuangliu/pytorch-cifar/blob/master/models/dpn.py

class super_gradients.training.models.dpn.Bottleneck(last_planes, in_planes, out_planes, dense_depth, stride, first_layer)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.dpn.DPN(cfg)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.dpn.DPN26()[source]
super_gradients.training.models.dpn.DPN92()[source]
super_gradients.training.models.dpn.test()[source]

super_gradients.training.models.efficientnet module

EfficientNet model class, based on “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks” <https://arxiv.org/abs/1905.11946>` Code source: https://github.com/lukemelas/EfficientNet-PyTorch

class super_gradients.training.models.efficientnet.BlockArgs(num_repeat, kernel_size, stride, expand_ratio, input_filters, output_filters, se_ratio, id_skip)

Bases: tuple

property expand_ratio

Alias for field number 3

property id_skip

Alias for field number 7

property input_filters

Alias for field number 4

property kernel_size

Alias for field number 1

property num_repeat

Alias for field number 0

property output_filters

Alias for field number 5

property se_ratio

Alias for field number 6

property stride

Alias for field number 2

class super_gradients.training.models.efficientnet.BlockDecoder[source]

Bases: object

Block Decoder for readability, straight from the official TensorFlow repository.

static decode(string_list)[source]

Decode a list of string notations to specify blocks inside the network. Args:

string_list (list[str]): A list of strings, each string is a notation of block.

Returns:

blocks_args: A list of BlockArgs namedtuples of block args.

static encode(blocks_args)[source]

Encode a list of BlockArgs to a list of strings. Args:

blocks_args (list[namedtuples]): A list of BlockArgs namedtuples of block args.

Returns:

block_strings: A list of strings, each string is a notation of block.

class super_gradients.training.models.efficientnet.Conv2dDynamicSamePadding(in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True)[source]

Bases: torch.nn.modules.conv.Conv2d

2D Convolutions like TensorFlow, for a dynamic image size. The padding is operated in forward function by calculating dynamically.

bias: Optional[torch.Tensor]
dilation: Tuple[int, ...]
forward(x)[source]

Defines 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.

groups: int
kernel_size: Tuple[int, ...]
out_channels: int
output_padding: Tuple[int, ...]
padding: Union[str, Tuple[int, ...]]
padding_mode: str
stride: Tuple[int, ...]
transposed: bool
weight: torch.Tensor
class super_gradients.training.models.efficientnet.Conv2dStaticSamePadding(in_channels, out_channels, kernel_size, stride=1, image_size=None, **kwargs)[source]

Bases: torch.nn.modules.conv.Conv2d

2D Convolutions like TensorFlow’s ‘SAME’ mode, with the given input image size. The padding mudule is calculated in construction function, then used in forward.

bias: Optional[torch.Tensor]
dilation: Tuple[int, ...]
forward(x)[source]

Defines 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.

groups: int
kernel_size: Tuple[int, ...]
out_channels: int
output_padding: Tuple[int, ...]
padding: Union[str, Tuple[int, ...]]
padding_mode: str
stride: Tuple[int, ...]
transposed: bool
weight: torch.Tensor
super_gradients.training.models.efficientnet.CustomizedEfficientnet(arch_params)[source]
class super_gradients.training.models.efficientnet.EfficientNet(blocks_args=None, arch_params=None)[source]

Bases: super_gradients.training.models.sg_module.SgModule

EfficientNet model. Args:

blocks_args (list[namedtuple]): A list of BlockArgs to construct blocks. arch_params (HpmStruct): A set of global params shared between blocks.

References:

[1] https://arxiv.org/abs/1905.11946 (EfficientNet)

extract_features(inputs)[source]

Use convolution layer to extract feature. Args:

inputs (tensor): Input tensor.

Returns:

Output of the final convolution. layer in the efficientnet model.

forward(inputs)[source]
EfficientNet’s forward function.

Calls extract_features to extract features, applies final linear layer, and returns logits.

Args:

inputs (tensor): Input tensor.

Returns:

Output of this model after processing.

load_state_dict(state_dict, strict=True)[source]

load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone :param state_dict: The state_dict to load :param strict: strict loading (see super() docs)

training: bool
class super_gradients.training.models.efficientnet.Identity[source]

Bases: torch.nn.modules.module.Module

Identity mapping. Send input to output directly.

forward(input)[source]

Defines 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.

training: bool
class super_gradients.training.models.efficientnet.MBConvBlock(block_args, batch_norm_momentum, batch_norm_epsilon, image_size=None)[source]

Bases: torch.nn.modules.module.Module

Mobile Inverted Residual Bottleneck Block. Args:

block_args (namedtuple): BlockArgs. arch_params (HpmStruct): HpmStruct. image_size (tuple or list): [image_height, image_width].

References:

[1] https://arxiv.org/abs/1704.04861 (MobileNet v1) [2] https://arxiv.org/abs/1801.04381 (MobileNet v2) [3] https://arxiv.org/abs/1905.02244 (MobileNet v3)

forward(inputs, drop_connect_rate=None)[source]

MBConvBlock’s forward function. Args:

inputs (tensor): Input tensor. drop_connect_rate (bool): Drop connect rate (float, between 0 and 1).

Returns:

Output of this block after processing.

training: bool
super_gradients.training.models.efficientnet.b0(arch_params)[source]
super_gradients.training.models.efficientnet.b1(arch_params)[source]
super_gradients.training.models.efficientnet.b2(arch_params)[source]
super_gradients.training.models.efficientnet.b3(arch_params)[source]
super_gradients.training.models.efficientnet.b4(arch_params)[source]
super_gradients.training.models.efficientnet.b5(arch_params)[source]
super_gradients.training.models.efficientnet.b6(arch_params)[source]
super_gradients.training.models.efficientnet.b7(arch_params)[source]
super_gradients.training.models.efficientnet.b8(arch_params)[source]
super_gradients.training.models.efficientnet.build_efficientnet(width, depth, res, dropout, arch_params)[source]
Parameters
  • width

  • depth

  • res

  • dropout

  • arch_params

Returns

super_gradients.training.models.efficientnet.calculate_output_image_size(input_image_size, stride)[source]
Calculates the output image size when using Conv2dSamePadding with a stride.

Necessary for static padding. Thanks to mannatsingh for pointing this out.

Args:

input_image_size (int, tuple or list): Size of input image. stride (int, tuple or list): Conv2d operation’s stride.

Returns:

output_image_size: A list [H,W].

super_gradients.training.models.efficientnet.drop_connect(inputs, p, training)[source]

Drop connect.

Args:

inputs (tensor: BCWH): Input of this structure. p (float: 0.0~1.0): Probability of drop connection. training (bool): The running mode.

Returns:

output: Output after drop connection.

super_gradients.training.models.efficientnet.get_same_padding_conv2d(image_size=None)[source]
Chooses static padding if you have specified an image size, and dynamic padding otherwise.

Static padding is necessary for ONNX exporting of models.

Args:

image_size (int or tuple): Size of the image.

Returns:

Conv2dDynamicSamePadding or Conv2dStaticSamePadding.

super_gradients.training.models.efficientnet.l2(arch_params)[source]
super_gradients.training.models.efficientnet.round_filters(filters, width_coefficient, depth_divisor, min_depth)[source]
Calculate and round number of filters based on width multiplier.

Use width_coefficient, depth_divisor and min_depth.

Args:

filters (int): Filters number to be calculated. Params from arch_params: width_coefficient (int): model’s width coefficient. Used as the multiplier. depth_divisor (int): model’s depth divisor. Used as the divisor. and min_depth (int): model’s minimal depth, if given.

Returns:

new_filters: New filters number after calculating.

super_gradients.training.models.efficientnet.round_repeats(repeats, depth_coefficient)[source]
Calculate module’s repeat number of a block based on depth multiplier.

Use depth_coefficient.

Args:

repeats (int): num_repeat to be calculated. depth_coefficient (int): the depth coefficient of the model. this func uses it as the multiplier.

Returns:

new repeat: New repeat number after calculating.

super_gradients.training.models.googlenet module

Googlenet code based on https://pytorch.org/vision/stable/_modules/torchvision/models/googlenet.html

class super_gradients.training.models.googlenet.BasicConv2d(in_channels, out_channels, **kwargs)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.googlenet.GoogLeNet(num_classes=1000, aux_logits=True, init_weights=True, backbone_mode=False, dropout=0.3)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

load_state_dict(state_dict, strict=True)[source]

load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone :param state_dict: The state_dict to load :param strict: strict loading (see super() docs)

training: bool
class super_gradients.training.models.googlenet.GoogLeNetOutputs(log_, aux_logits2, aux_logits1)

Bases: tuple

property aux_logits1

Alias for field number 2

property aux_logits2

Alias for field number 1

property log_

Alias for field number 0

class super_gradients.training.models.googlenet.Inception(in_channels, ch1x1, ch3x3red, ch3x3, ch5x5red, ch5x5, pool_proj, conv_block=None)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.googlenet.InceptionAux(in_channels, num_classes, conv_block=None)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.googlenet.googlenet_v1(arch_params)[source]

super_gradients.training.models.laddernet module

class super_gradients.training.models.laddernet.BaseNet(nclass, backbone, aux, se_loss, dilated=True, norm_layer=None, base_size=576, crop_size=608, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225], root='~/.encoding/models')[source]

Bases: torch.nn.modules.module.Module

base_forward(x)[source]
training: bool
class super_gradients.training.models.laddernet.BasicBlock(inplanes, planes, stride=1, rate=1, downsample=None)[source]

Bases: torch.nn.modules.module.Module

expansion = 1
forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.Bottleneck(inplanes, planes, stride=1, downsample=None)[source]

Bases: torch.nn.modules.module.Module

expansion = 4
forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.Decoder(planes, layers, kernel=3, block=<class 'super_gradients.training.models.laddernet.BasicBlock'>)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.FCNHead(in_channels, out_channels, norm_layer)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.Final_LadderBlock(planes, layers, kernel=3, block=<class 'super_gradients.training.models.laddernet.BasicBlock'>, inplanes=3)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.Initial_LadderBlock(planes, layers, kernel=3, block=<class 'super_gradients.training.models.laddernet.BasicBlock'>, inplanes=3)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.LadderBlock(planes, layers, kernel=3, block=<class 'super_gradients.training.models.laddernet.BasicBlock'>)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.LadderBottleneck(inplanes, planes, stride=1, dilation=1, downsample=None, previous_dilation=1, norm_layer=None)[source]

Bases: torch.nn.modules.module.Module

ResNet Bottleneck

expansion = 4
forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.LadderHead(base_inchannels, base_outchannels, out_channels, norm_layer, se_loss, nclass, up_kwargs)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.LadderNet(nclass, backbone, aux=True, se_loss=True, lateral=False, arch_params=None, norm_layer=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>, dilated=False, **kwargs)[source]

Bases: super_gradients.training.models.laddernet.BaseNet

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.laddernet.LadderNet101(*args, **kwargs)[source]

Bases: super_gradients.training.models.laddernet.LadderNet

training: bool
class super_gradients.training.models.laddernet.LadderNet50(*args, **kwargs)[source]

Bases: super_gradients.training.models.laddernet.LadderNet

training: bool
class super_gradients.training.models.laddernet.LadderNet503433(*args, **kwargs)[source]

Bases: super_gradients.training.models.laddernet.LadderNet

training: bool
class super_gradients.training.models.laddernet.LadderNetBackBone101(num_classes: int)[source]

Bases: super_gradients.training.models.laddernet.LadderResNet

training: bool
class super_gradients.training.models.laddernet.LadderNetBackBone50(num_classes: int)[source]

Bases: super_gradients.training.models.laddernet.LadderResNet

training: bool
class super_gradients.training.models.laddernet.LadderNetBackBone503433(num_classes: int)[source]

Bases: super_gradients.training.models.laddernet.LadderResNet

training: bool
class super_gradients.training.models.laddernet.LadderResNet(block, layers, num_classes=1000, dilated=False, norm_layer=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>)[source]

Bases: torch.nn.modules.module.Module

Dilated Pre-trained ResNet Model, which preduces the stride of 8 featuremaps at conv5.

blockBlock

Class for the residual block. Options are BasicBlockV1, BottleneckV1.

layerslist of int

Numbers of layers in each block

classesint, default 1000

Number of classification classes.

dilatedbool, default False

Applying dilation strategy to pretrained ResNet yielding a stride-8 model, typically used in Semantic Segmentation.

norm_layerobject

Normalization layer used in backbone network (default: mxnet.gluon.nn.BatchNorm; for Synchronized Cross-GPU BachNormalization).

Reference:

  • He, Kaiming, et al. “Deep residual learning for image recognition.” Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.

  • Yu, Fisher, and Vladlen Koltun. “Multi-scale context aggregation by dilated convolutions.”

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.laddernet.conv3x3(in_planes, out_planes, stride=1)[source]

3x3 convolution with padding

super_gradients.training.models.lenet module

LeNet in PyTorch.

https://yann.lecun.com/exdb/lenet/

class super_gradients.training.models.lenet.LeNet[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool

super_gradients.training.models.mobilenet module

MobileNet in PyTorch.

See the paper “MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications” for more details.

class super_gradients.training.models.mobilenet.Block(in_planes, out_planes, stride=1)[source]

Bases: torch.nn.modules.module.Module

Depthwise conv + Pointwise conv

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.mobilenet.MobileNet(num_classes=10, backbone_mode=False, up_to_layer=None)[source]

Bases: super_gradients.training.models.sg_module.SgModule

cfg = [64, 128, (128, 2), 256, (256, 2), 512, 512, 512, 512, 512, (512, 2), 1024, (1024, 2)]
forward(x)[source]
Parameters

up_to_layer – forward through the net layers up to a specific layer. if None, run all layers

training: bool

super_gradients.training.models.mobilenetv2 module

This is a PyTorch implementation of MobileNetV2 architecture as described in the paper: Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation. https://arxiv.org/pdf/1801.04381

Code taken from https://github.com/tonylins/pytorch-mobilenet-v2 License: Apache Version 2.0, January 2004 http://www.apache.org/licenses/

class super_gradients.training.models.mobilenetv2.InvertedResidual(inp, oup, stride, expand_ratio, grouped_conv_size=1)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.mobilenetv2.MobileNetV2(num_classes, width_mult=1.0, structure=None, backbone_mode: bool = False, grouped_conv_size=1)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.mobilenetv2.conv_1x1_bn(inp, oup)[source]
super_gradients.training.models.mobilenetv2.conv_bn(inp, oup, stride)[source]
super_gradients.training.models.mobilenetv2.custom_mobile_net_v2(arch_params)[source]
Parameters

arch_params

HpmStruct must contain:

’num_classes’: int ‘width_mult’: float ‘structure’ : list. specify the mobilenetv2 architecture

Returns

MobileNetV2: nn.Module

super_gradients.training.models.mobilenetv2.make_divisible(x, divisible_by=8)[source]
super_gradients.training.models.mobilenetv2.mobile_net_v2(arch_params)[source]
Parameters

arch_params – HpmStruct must contain: ‘num_classes’: int

Returns

MobileNetV2: nn.Module

super_gradients.training.models.mobilenetv2.mobile_net_v2_135(arch_params)[source]

This Model achieves 75.73% on Imagenet - similar to Resnet50 :param arch_params: HpmStruct

must contain: ‘num_classes’: int

Returns

MobileNetV2: nn.Module

super_gradients.training.models.mobilenetv3 module

Creates a MobileNetV3 Model as defined in: Andrew Howard, Mark Sandler, Grace Chu, Liang-Chieh Chen, Bo Chen, Mingxing Tan, Weijun Wang, Yukun Zhu, Ruoming Pang, Vijay Vasudevan, Quoc V. Le, Hartwig Adam. (2019). Searching for MobileNetV3 arXiv preprint arXiv:1905.02244.

class super_gradients.training.models.mobilenetv3.InvertedResidual(inp, hidden_dim, oup, kernel_size, stride, use_se, use_hs)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.mobilenetv3.MobileNetV3(cfgs, mode, num_classes=1000, width_mult=1.0)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.mobilenetv3.SELayer(channel, reduction=4)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.mobilenetv3.conv_1x1_bn(inp, oup)[source]
super_gradients.training.models.mobilenetv3.conv_3x3_bn(inp, oup, stride)[source]
class super_gradients.training.models.mobilenetv3.h_sigmoid(inplace=True)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.mobilenetv3.h_swish(inplace=True)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.mobilenetv3.mobilenetv3_custom(arch_params)[source]

Constructs a MobileNetV3-Customized model

super_gradients.training.models.mobilenetv3.mobilenetv3_large(arch_params)[source]

Constructs a MobileNetV3-Large model

super_gradients.training.models.mobilenetv3.mobilenetv3_small(arch_params)[source]

Constructs a MobileNetV3-Small model

super_gradients.training.models.pnasnet module

PNASNet in PyTorch.

Paper: Progressive Neural Architecture Search

https://github.com/kuangliu/pytorch-cifar/blob/master/models/pnasnet.py

class super_gradients.training.models.pnasnet.CellA(in_planes, out_planes, stride=1)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.pnasnet.CellB(in_planes, out_planes, stride=1)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.pnasnet.PNASNet(cell_type, num_cells, num_planes)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.pnasnet.PNASNetA()[source]
super_gradients.training.models.pnasnet.PNASNetB()[source]
class super_gradients.training.models.pnasnet.SepConv(in_planes, out_planes, kernel_size, stride)[source]

Bases: torch.nn.modules.module.Module

Separable Convolution.

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.pnasnet.test()[source]

super_gradients.training.models.preact_resnet module

Pre-activation ResNet in PyTorch.

Reference: [1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun

Identity Mappings in Deep Residual Networks. arXiv:1603.05027

Based on https://github.com/kuangliu/pytorch-cifar/blob/master/models/preact_resnet.py

class super_gradients.training.models.preact_resnet.PreActBlock(in_planes, planes, stride=1)[source]

Bases: torch.nn.modules.module.Module

Pre-activation version of the BasicBlock.

expansion = 1
forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.preact_resnet.PreActBottleneck(in_planes, planes, stride=1)[source]

Bases: torch.nn.modules.module.Module

Pre-activation version of the original Bottleneck module.

expansion = 4
forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.preact_resnet.PreActResNet(block, num_blocks, num_classes=10)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.preact_resnet.PreActResNet101()[source]
super_gradients.training.models.preact_resnet.PreActResNet152()[source]
super_gradients.training.models.preact_resnet.PreActResNet18()[source]
super_gradients.training.models.preact_resnet.PreActResNet34()[source]
super_gradients.training.models.preact_resnet.PreActResNet50()[source]
super_gradients.training.models.preact_resnet.test()[source]

super_gradients.training.models.regnet module

Regnet - from paper: Designing Network Design Spaces - https://arxiv.org/pdf/2003.13678.pdf Implementation of paradigm described in paper published by Facebook AI Research (FAIR) @author: Signatrix GmbH Code taken from: https://github.com/signatrix/regnet - MIT Licence

class super_gradients.training.models.regnet.AnyNetX(ls_num_blocks, ls_block_width, ls_bottleneck_ratio, ls_group_width, stride, num_classes, se_ratio, backbone_mode, dropout_prob=0.0, droppath_prob=0.0, input_channels=3)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

initialize_weight()[source]
training: bool
class super_gradients.training.models.regnet.CustomRegNet(arch_params)[source]

Bases: super_gradients.training.models.regnet.RegNetX

training: bool
class super_gradients.training.models.regnet.Head(num_channels, num_classes, dropout_prob)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.regnet.NASRegNet(arch_params)[source]

Bases: super_gradients.training.models.regnet.RegNetX

training: bool
class super_gradients.training.models.regnet.RegNetX(initial_width, slope, quantized_param, network_depth, bottleneck_ratio, group_width, stride, arch_params, se_ratio=None, input_channels=3)[source]

Bases: super_gradients.training.models.regnet.AnyNetX

training: bool
class super_gradients.training.models.regnet.RegNetY(initial_width, slope, quantized_param, network_depth, bottleneck_ratio, group_width, stride, arch_params, se_ratio, input_channels=3)[source]

Bases: super_gradients.training.models.regnet.RegNetX

training: bool
class super_gradients.training.models.regnet.RegNetY200(arch_params)[source]

Bases: super_gradients.training.models.regnet.RegNetY

training: bool
class super_gradients.training.models.regnet.RegNetY400(arch_params)[source]

Bases: super_gradients.training.models.regnet.RegNetY

training: bool
class super_gradients.training.models.regnet.RegNetY600(arch_params)[source]

Bases: super_gradients.training.models.regnet.RegNetY

training: bool
class super_gradients.training.models.regnet.RegNetY800(arch_params)[source]

Bases: super_gradients.training.models.regnet.RegNetY

training: bool
class super_gradients.training.models.regnet.Stage(num_blocks, in_channels, out_channels, bottleneck_ratio, group_width, stride, se_ratio, droppath_prob)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.regnet.Stem(in_channels, out_channels)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.regnet.XBlock(in_channels, out_channels, bottleneck_ratio, group_width, stride, se_ratio=None, droppath_prob=0.0)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.regnet.verify_correctness_of_parameters(ls_num_blocks, ls_block_width, ls_bottleneck_ratio, ls_group_width)[source]

VERIFY THAT THE GIVEN PARAMETERS FIT THE SEARCH SPACE DEFINED IN THE REGNET PAPER

super_gradients.training.models.repvgg module

Repvgg Pytorch Implementation. This model trains a vgg with residual blocks but during inference (in deployment mode) will convert the model to vgg model. Pretrained models: https://drive.google.com/drive/folders/1Avome4KvNp0Lqh2QwhXO6L5URQjzCjUq Refrerences:

Based on https://github.com/DingXiaoH/RepVGG

class super_gradients.training.models.repvgg.RepVGG(struct, num_classes=1000, width_multiplier=None, build_residual_branches=True, use_se=False, backbone_mode=False, in_channels=3)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

prep_model_for_conversion(input_size: Optional[Union[tuple, list]] = None, **kwargs)[source]

Prepare the model to be converted to ONNX or other frameworks. Typically, this function will freeze the size of layers which is otherwise flexible, replace some modules with convertible substitutes and remove all auxiliary or training related parts. :param input_size: [H,W]

train(mode: bool = True)[source]

Sets the module in training mode.

This has any effect only on certain modules. See documentations of particular modules for details of their behaviors in training/evaluation mode, if they are affected, e.g. Dropout, BatchNorm, etc.

Args:
mode (bool): whether to set training mode (True) or evaluation

mode (False). Default: True.

Returns:

Module: self

training: bool
class super_gradients.training.models.repvgg.RepVGGBlock(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, build_residual_branches=True, use_relu=True, use_se=False)[source]

Bases: torch.nn.modules.module.Module

Repvgg block consists of three branches 3x3: a branch of a 3x3 convolution + batchnorm + relu 1x1: a branch of a 1x1 convolution + batchnorm + relu no_conv_branch: a branch with only batchnorm which will only be used if input channel == output channel (usually in all but the first block of each stage)

forward(inputs)[source]

Defines 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.

fuse_block_residual_branches()[source]

converts a repvgg block from training model (with branches) to deployment mode (vgg like model) :return: :rtype:

training: bool
class super_gradients.training.models.repvgg.RepVggA0(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.RepVggA1(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.RepVggA2(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.RepVggB0(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.RepVggB1(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.RepVggB2(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.RepVggB3(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.RepVggCustom(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVGG

training: bool
class super_gradients.training.models.repvgg.RepVggD2SE(arch_params)[source]

Bases: super_gradients.training.models.repvgg.RepVggCustom

training: bool
class super_gradients.training.models.repvgg.SEBlock(input_channels, internal_neurons)[source]

Bases: torch.nn.modules.module.Module

forward(inputs)[source]

Defines 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.

training: bool
super_gradients.training.models.repvgg.conv_bn(in_channels, out_channels, kernel_size, stride, padding, groups=1, dilation=1)[source]

super_gradients.training.models.resnet module

ResNet in PyTorch. For Pre-activation ResNet, see ‘preact_resnet.py’. Reference: [1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun

Deep Residual Learning for Image Recognition. arXiv:1512.03385

Code adapted from https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

class super_gradients.training.models.resnet.BasicBlock(in_planes, planes, stride=1, expansion=1, final_relu=True)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.resnet.Bottleneck(in_planes, planes, stride=1, expansion=4, final_relu=True)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.resnet.CifarResNet(block, num_blocks, num_classes=10, width_mult=1, expansion=1)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.resnet.CustomizedResnet(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.CustomizedResnet50(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.CustomizedResnet50Cifar(arch_params, num_classes=None)[source]
super_gradients.training.models.resnet.CustomizedResnetCifar(arch_params, num_classes=None)[source]
class super_gradients.training.models.resnet.ResNet(block, num_blocks: list, num_classes: int = 10, width_mult: float = 1, expansion: int = 1, input_batchnorm: bool = False, backbone_mode: bool = False)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

load_state_dict(state_dict, strict=True)[source]

load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone :param state_dict: The state_dict to load :param strict: strict loading (see super() docs)

training: bool
super_gradients.training.models.resnet.ResNet101(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.ResNet152(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.ResNet18(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.ResNet18Cifar(arch_params, num_classes=None)[source]
super_gradients.training.models.resnet.ResNet34(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.ResNet50(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.ResNet50_3343(arch_params, num_classes=None, backbone_mode=None)[source]
super_gradients.training.models.resnet.width_multiplier(original, factor)[source]

super_gradients.training.models.resnext module

ResNeXt in PyTorch.

See the paper “Aggregated Residual Transformations for Deep Neural Networks” for more details.

Code adapted from https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

super_gradients.training.models.resnext.CustomizedResNeXt(arch_params)[source]
class super_gradients.training.models.resnext.GroupedConvBlock(inplanes, planes, stride=1, downsample=None, groups=1, base_width=64, dilation=1, norm_layer=None)[source]

Bases: torch.nn.modules.module.Module

Grouped convolution block.

expansion = 4
forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.resnext.ResNeXt(layers, cardinality, bottleneck_width, num_classes=10, replace_stride_with_dilation=None)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.resnext.ResNeXt101(arch_params)[source]
super_gradients.training.models.resnext.ResNeXt50(arch_params)[source]
super_gradients.training.models.resnext.conv1x1(in_planes, out_planes, stride=1)[source]

1x1 convolution

super_gradients.training.models.resnext.conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1)[source]

3x3 convolution with padding

super_gradients.training.models.senet module

SENet in PyTorch.

SENet is the winner of ImageNet-2017. The paper is not released yet.

Code adapted from https://github.com/fastai/imagenet-fast/blob/master/cifar10/models/cifar10/senet.py

class super_gradients.training.models.senet.BasicBlock(in_planes, planes, stride=1)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.senet.PreActBlock(in_planes, planes, stride=1)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.senet.SENet(block, num_blocks, num_classes=10)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.senet.SENet18()[source]
super_gradients.training.models.senet.test()[source]

super_gradients.training.models.sg_module module

class super_gradients.training.models.sg_module.SgModule[source]

Bases: torch.nn.modules.module.Module

get_exclude_attributes()list[source]

This function is used by the EMA. When updating the EMA model, some attributes of the main model (used in training) are updated to the EMA model along with the model weights. By default, all attributes are updated except for private attributes (starting with ‘_’) You can either set include_attributes or exclude_attributes. By returning a non empty list from this function, you override the default behaviour and attributes named in this list will also be excluded from update. Note: if get_include_attributes is not empty, it will override this list.

return

list of attributes to not update from main model to EMA mode

get_include_attributes()list[source]

This function is used by the EMA. When updating the EMA model, some attributes of the main model (used in training) are updated to the EMA model along with the model weights. By default, all attributes are updated except for private attributes (starting with ‘_’) You can either set include_attributes or exclude_attributes. By returning a non empty list from this function, you override the default behaviour and only attributes named in this list will be updated. Note: This will also override the get_exclude_attributes list.

return

list of attributes to update from main model to EMA model

initialize_param_groups(lr: float, training_params: super_gradients.training.utils.utils.HpmStruct)list[source]
Returns

list of dictionaries containing the key ‘named_params’ with a list of named params

prep_model_for_conversion(input_size: Optional[Union[tuple, list]] = None, **kwargs)[source]

Prepare the model to be converted to ONNX or other frameworks. Typically, this function will freeze the size of layers which is otherwise flexible, replace some modules with convertible substitutes and remove all auxiliary or training related parts. :param input_size: [H,W]

training: bool
update_param_groups(param_groups: list, lr: float, epoch: int, iter: int, training_params: super_gradients.training.utils.utils.HpmStruct, total_batch: int)list[source]
Parameters

param_groups – list of dictionaries containing the params

Returns

list of dictionaries containing the params

super_gradients.training.models.shelfnet module

Shelfnet

paper: https://arxiv.org/abs/1811.11254 based on: https://github.com/juntang-zhuang/ShelfNet

class super_gradients.training.models.shelfnet.AttentionRefinementModule(in_chan, out_chan)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

init_weight()[source]
training: bool
class super_gradients.training.models.shelfnet.ConvBNReLU(in_chan: int, out_chan: int, ks: int = 3, stride: int = 1, padding: int = 1)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetModuleBase

forward(x)[source]

Defines 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.

init_weight()[source]
training: bool
class super_gradients.training.models.shelfnet.DecoderBase(planes: int, layers: int, kernel: int = 3, block=<class 'super_gradients.training.models.shelfnet.ShelfBlock'>)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetModuleBase

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.DecoderHW(planes, layers, block=<class 'super_gradients.training.models.shelfnet.ShelfBlock'>, *args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.DecoderBase

DecoderHW - The Decoder for the Heavy-Weight ShelfNet Architecture

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.DecoderLW(planes, layers, block=<class 'super_gradients.training.models.shelfnet.ShelfBlock'>, *args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.DecoderBase

DecoderLW - The Decoder for the Light-Weight ShelfNet Architecture

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.FCNHead(in_channels, out_channels)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.LadderBlockBase(planes: int, layers: int, kernel: int = 3, block=<class 'super_gradients.training.models.shelfnet.ShelfBlock'>)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetModuleBase

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.LadderBlockHW(planes, layers, block=<class 'super_gradients.training.models.shelfnet.ShelfBlock'>, *args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.LadderBlockBase

LadderBlockHW - LadderBlock for the Heavy-Weight ShelfNet Architecture

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.LadderBlockLW(planes, layers, block=<class 'super_gradients.training.models.shelfnet.ShelfBlock'>, *args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.LadderBlockBase

LadderBlockLW - LadderBlock for the Light-Weight ShelfNet Architecture

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.NetOutput(in_chan: int, mid_chan: int, classes_num: int)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetModuleBase

forward(x)[source]

Defines 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.

init_weight()[source]
training: bool
class super_gradients.training.models.shelfnet.ShelfBlock(in_planes: int, planes: int, stride: int = 1, dropout: float = 0.25)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.ShelfNet101(*args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetHW

training: bool
class super_gradients.training.models.shelfnet.ShelfNet18_LW(*args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetLW

training: bool
class super_gradients.training.models.shelfnet.ShelfNet34_LW(*args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetLW

training: bool
class super_gradients.training.models.shelfnet.ShelfNet50(*args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetHW

training: bool
class super_gradients.training.models.shelfnet.ShelfNet503343(*args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetHW

training: bool
class super_gradients.training.models.shelfnet.ShelfNetBase(backbone: super_gradients.training.models.shelfnet.ShelfResNetBackBone, planes: int, layers: int, classes_num: int = 21, image_size: int = 512, net_output_mid_channels_num: int = 64, arch_params: Optional[super_gradients.training.utils.utils.HpmStruct] = None)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetModuleBase

ShelfNetBase - ShelfNet Base Generic Architecture

forward(x)[source]

Defines 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.

training: bool
update_param_groups(param_groups: list, lr: float, epoch: int, iter: int, training_params: super_gradients.training.utils.utils.HpmStruct, total_batch: int)list[source]

update_optimizer_for_param_groups - Updates the specific parameters with different LR

class super_gradients.training.models.shelfnet.ShelfNetHW(*args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetBase

ShelfNetHW - Heavy-Weight Version of ShelfNet

forward(x)[source]

Defines 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.

initialize_param_groups(lr: float, training_params: super_gradients.training.utils.utils.HpmStruct)list[source]
initialize_optimizer_for_model_param_groups - Initializes the weights of the optimizer

Initializes the Backbone, the Output and the Auxilary Head differently

param optimizer_cls

The nn.optim (optimizer class) to initialize

param lr

lr to set for the optimizer

param training_params

return

list of dictionaries with named params and optimizer attributes

training: bool
class super_gradients.training.models.shelfnet.ShelfNetLW(*args, **kwargs)[source]

Bases: super_gradients.training.models.shelfnet.ShelfNetBase

ShelfNetLW - Light-Weight Implementation for ShelfNet

forward(x)[source]

Defines 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.

initialize_param_groups(lr: float, training_params: super_gradients.training.utils.utils.HpmStruct)list[source]
initialize_optimizer_for_model_param_groups - Initializes the optimizer group params, with 10x learning rate

for all but the backbone

param lr

lr to set for the backbone

param training_params

return

list of dictionaries with named params and optimizer attributes

training: bool
class super_gradients.training.models.shelfnet.ShelfNetModuleBase[source]

Bases: super_gradients.training.models.sg_module.SgModule

ShelfNetModuleBase - Base class for the different Modules of the ShelfNet Architecture

forward(x)[source]

Defines 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.

get_params()[source]
training: bool
class super_gradients.training.models.shelfnet.ShelfResNetBackBone(block, num_blocks, num_classes=10, width_mult=1)[source]

Bases: super_gradients.training.models.resnet.ResNet

ShelfResNetBackBone - A class that Inherits from the original ResNet class and manipulates the forward pass,

to create a backbone for the ShelfNet architecture

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shelfnet.ShelfResNetBackBone101(num_classes: int)[source]

Bases: super_gradients.training.models.shelfnet.ShelfResNetBackBone

training: bool
class super_gradients.training.models.shelfnet.ShelfResNetBackBone18(num_classes: int)[source]

Bases: super_gradients.training.models.shelfnet.ShelfResNetBackBone

training: bool
class super_gradients.training.models.shelfnet.ShelfResNetBackBone34(num_classes: int)[source]

Bases: super_gradients.training.models.shelfnet.ShelfResNetBackBone

training: bool
class super_gradients.training.models.shelfnet.ShelfResNetBackBone50(num_classes: int)[source]

Bases: super_gradients.training.models.shelfnet.ShelfResNetBackBone

training: bool
class super_gradients.training.models.shelfnet.ShelfResNetBackBone503343(num_classes: int)[source]

Bases: super_gradients.training.models.shelfnet.ShelfResNetBackBone

training: bool

super_gradients.training.models.shufflenet module

ShuffleNet in PyTorch.

See the paper “ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices” for more details.

https://github.com/kuangliu/pytorch-cifar/blob/master/models/shufflenet.py

class super_gradients.training.models.shufflenet.Bottleneck(in_planes, out_planes, stride, groups)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.shufflenet.ShuffleBlock(groups)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Channel shuffle: [N,C,H,W] -> [N,g,C/g,H,W] -> [N,C/g,g,H,w] -> [N,C,H,W]

training: bool
class super_gradients.training.models.shufflenet.ShuffleNet(cfg)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.shufflenet.ShuffleNetG2()[source]
super_gradients.training.models.shufflenet.ShuffleNetG3()[source]
super_gradients.training.models.shufflenet.test()[source]

super_gradients.training.models.shufflenetv2 module

ShuffleNetV2 in PyTorch.

See the paper “ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design” for more details. (https://arxiv.org/abs/1807.11164)

Code taken from torchvision/models/shufflenetv2.py

class super_gradients.training.models.shufflenetv2.CustomizedShuffleNetV2(arch_params: super_gradients.training.utils.utils.HpmStruct, num_classes: int = 1000, backbone_mode: bool = False)[source]

Bases: super_gradients.training.models.shufflenetv2.ShuffleNetV2Base

training: bool
class super_gradients.training.models.shufflenetv2.ShuffleNetV2Base(structure: List[int], stages_out_channels: List[int], backbone_mode: bool = False, num_classes: int = 1000, block: torch.nn.modules.module.Module = <class 'super_gradients.training.models.shufflenetv2.ChannelShuffleInvertedResidual'>)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x: torch.Tensor)torch.Tensor[source]

Defines 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.

load_state_dict(state_dict, strict=True)[source]

load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone :param state_dict: The state_dict to load :param strict: strict loading (see super() docs)

training: bool
class super_gradients.training.models.shufflenetv2.ShufflenetV2_x0_5(arch_params: super_gradients.training.utils.utils.HpmStruct, num_classes: int = 1000, backbone_mode: bool = False)[source]

Bases: super_gradients.training.models.shufflenetv2.ShuffleNetV2Base

training: bool
class super_gradients.training.models.shufflenetv2.ShufflenetV2_x1_0(arch_params: super_gradients.training.utils.utils.HpmStruct, num_classes: int = 1000, backbone_mode: bool = False)[source]

Bases: super_gradients.training.models.shufflenetv2.ShuffleNetV2Base

training: bool
class super_gradients.training.models.shufflenetv2.ShufflenetV2_x1_5(arch_params: super_gradients.training.utils.utils.HpmStruct, num_classes: int = 1000, backbone_mode: bool = False)[source]

Bases: super_gradients.training.models.shufflenetv2.ShuffleNetV2Base

training: bool
class super_gradients.training.models.shufflenetv2.ShufflenetV2_x2_0(arch_params: super_gradients.training.utils.utils.HpmStruct, num_classes: int = 1000, backbone_mode: bool = False)[source]

Bases: super_gradients.training.models.shufflenetv2.ShuffleNetV2Base

training: bool

super_gradients.training.models.ssd module

class super_gradients.training.models.ssd.SSD(backbone, arch_params)[source]

Bases: super_gradients.training.models.sg_module.SgModule

paper: https://arxiv.org/pdf/1512.02325.pdf based on code: https://github.com/NVIDIA/DeepLearningExamples

bbox_view(src, loc, conf)[source]

Shape the classifier to the view of bboxes

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.ssd.SSDLiteMobileNetV2(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.ssd.SSD

training: bool
class super_gradients.training.models.ssd.SSDMobileNetV1(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.ssd.SSD

paper: http://ceur-ws.org/Vol-2500/paper_5.pdf

training: bool
super_gradients.training.models.ssd.SeperableConv2d(in_channels, out_channels, kernel_size=1, stride=1, padding=0, bias=True)[source]

Replace Conv2d with a depthwise Conv2d and Pointwise Conv2d.

super_gradients.training.models.vgg module

VGG11/13/16/19 in Pytorch. Adapted from https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py

class super_gradients.training.models.vgg.VGG(vgg_name)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

training: bool
super_gradients.training.models.vgg.test()[source]

super_gradients.training.models.yolov3 module

Yolov3 code adapted from https://github.com/ultralytics/yolov3

class super_gradients.training.models.yolov3.SPPLayer[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.yolov3.TinyYoloV3(num_classes: int = 80, image_size: int = 416, arch_params: Optional[dict] = None, iou_t: float = 0.225, yolo_v3_anchors: Optional[list] = None)[source]

Bases: super_gradients.training.models.yolov3.YoloV3

TinyYoloV3 - Inherits from YoLoV3 class and overloads the relevant methods and members

static concatenate_layer_output(x, layer_index: int, route_layers: list)tuple[source]
Parameters
  • x – input for the layer

  • layer_index – the layer index to decide how to concatenate to

  • route_layers – the route layers list with previous data

Returns

tuple of x, route_layers

create_modules_list(num_classes: int)[source]
create_tiny_modules_list
param num_classes

The Number of different Classes

return

nn.ModuleList with the Tiny-Yolo-V3 Architecture

training: bool
class super_gradients.training.models.yolov3.Upsample(scale_factor, mode='nearest')[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.yolov3.YOLOLayer(anchors_mask: list, classes_num: int, anchors: list, image_size: int, onnx_stride: int, onnx_export_mode: bool = False)[source]

Bases: torch.nn.modules.module.Module

create_grids(img_size=(416, 416), grid_size=(13, 13), device='cpu', data_type=torch.float32)[source]
create_grids - Creates the grids for image sizes that are different than the model’s defualt image size
param img_size

param grid_size

param device

param data_type

forward(img, img_size)[source]

Defines 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.

training: bool
class super_gradients.training.models.yolov3.YoloV3(num_classes: int = 80, image_size: int = 416, arch_params: Optional[super_gradients.training.utils.utils.HpmStruct] = None, iou_t: float = 0.225, yolo_v3_anchors: Optional[list] = None, onnx_export_mode=False)[source]

Bases: super_gradients.training.models.sg_module.SgModule

static add_yolo_layer_to_modules_list(modules_list: torch.nn.modules.container.ModuleList, image_size: int, yolo_v3_anchors: list, anchors_mask: list, num_classes: int, onnx_stride: int, onnx_export_mode: bool = False)torch.nn.modules.container.ModuleList[source]
add_yolo_layer_to_modules_list - Adds a YoLo Head Layer to the nn.ModuleList
param modules_list

The Modules List

param image_size

The YoLo Model Image Size

param yolo_v3_anchors

The Anchors (K-Means) List for the YoLo Layer Initialization

param anchors_mask

the mask to get the relevant anchors

param num_classes

The number of different classes in the data

param onnx_stride

The stride of the layer for ONNX grid points calculation in YoLo Layer init

param onnx_export_mode

Alter the model YoLo Layer for ONNX Export

return

The nn.ModuleList with the Added Yolo layer, and a Bias Initialization

static concatenate_layer_output(x, layer_index: int, route_layers: list)tuple[source]
Parameters
  • x – input for the layer

  • layer_index – the layer index to decide how to concatenate to

  • route_layers – the route layers list with previous data

Returns

tuple of x, route_layers

create_modules_list(num_classes: int)[source]
Parameters

num_classes

Returns

forward(x, var=None)[source]

Defines 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.

get_yolo_layers_indices()[source]
initialize_param_groups(lr: float, training_params: super_gradients.training.utils.utils.HpmStruct)list[source]
initialize_optimizer_for_model_param_groups - Initializes the optimizer group params,

adds weight decay Only to the Conv2D layers

param lr

lr to set for the optimizer

param training_params

return

A dictionary with named params and optimizer attributes

static named_sequential_module(module_name, module)torch.nn.modules.container.Sequential[source]
create_named_nn_sequential_module
param module_name

param module

return

nn.Sequential() with the added relevant names

prep_model_for_conversion(input_size: Optional[Union[tuple, list]] = None, **kwargs)[source]

Method for preparing the Yolov3 and TinyYolov3 for conversion (ONNX, TRT, CoreML etc). :param input_size: used for calculating the grid points.

training: bool

super_gradients.training.models.yolov5 module

YoloV5 code adapted from https://github.com/ultralytics/yolov5/blob/master/models/yolo.py

class super_gradients.training.models.yolov5.AbstractYoLoV5Backbone(arch_params)[source]

Bases: object

forward(x)[source]

:return A list, the length of self._modules_list containing the output of the layer if specified in self._layers_to_extract and None otherwise

class super_gradients.training.models.yolov5.Concat(dimension=1)[source]

Bases: torch.nn.modules.module.Module

CONCATENATE A LIST OF TENSORS ALONG DIMENSION

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.yolov5.Custom_YoLoV5(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.yolov5.YoLoV5Base

training: bool
class super_gradients.training.models.yolov5.Detect(num_classes: int, anchors: super_gradients.training.utils.detection_utils.Anchors, channels: Optional[list] = None, width_mult_factor: float = 1.0)[source]

Bases: torch.nn.modules.module.Module

forward(x)[source]

Defines 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.

training: bool
class super_gradients.training.models.yolov5.YoLoV5Base(backbone: Type[torch.nn.modules.module.Module], arch_params: super_gradients.training.utils.utils.HpmStruct, initialize_module: bool = True)[source]

Bases: super_gradients.training.models.sg_module.SgModule

forward(x)[source]

Defines 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.

get_include_attributes()list[source]

This function is used by the EMA. When updating the EMA model, some attributes of the main model (used in training) are updated to the EMA model along with the model weights. By default, all attributes are updated except for private attributes (starting with ‘_’) You can either set include_attributes or exclude_attributes. By returning a non empty list from this function, you override the default behaviour and only attributes named in this list will be updated. Note: This will also override the get_exclude_attributes list.

return

list of attributes to update from main model to EMA model

initialize_param_groups(lr: float, training_params: super_gradients.training.utils.utils.HpmStruct)list[source]
initialize_optimizer_for_model_param_groups - Initializes the weights of the optimizer

adds weight decay Only to the Conv2D layers

param optimizer_cls

The nn.optim (optimizer class) to initialize

param lr

lr to set for the optimizer

param training_params

return

The optimizer, initialized with the relevant param groups

load_state_dict(state_dict, strict=True)[source]

Copies parameters and buffers from state_dict into this module and its descendants. If strict is True, then the keys of state_dict must exactly match the keys returned by this module’s state_dict() function.

Args:
state_dict (dict): a dict containing parameters and

persistent buffers.

strict (bool, optional): whether to strictly enforce that the keys

in state_dict match the keys returned by this module’s state_dict() function. Default: True

Returns:
NamedTuple with missing_keys and unexpected_keys fields:
  • missing_keys is a list of str containing the missing keys

  • unexpected_keys is a list of str containing the unexpected keys

prep_model_for_conversion(input_size: Optional[Union[tuple, list]] = None, **kwargs)[source]

A method for preparing the YoloV5 model for conversion to other frameworks (ONNX, CoreML etc) :param input_size: expected input size :return:

training: bool
update_param_groups(param_groups: list, lr: float, epoch: int, iter: int, training_params: super_gradients.training.utils.utils.HpmStruct, total_batch: int)list[source]
Parameters

param_groups – list of dictionaries containing the params

Returns

list of dictionaries containing the params

class super_gradients.training.models.yolov5.YoLoV5DarknetBackbone(arch_params)[source]

Bases: super_gradients.training.models.yolov5.AbstractYoLoV5Backbone, super_gradients.training.models.csp_darknet53.CSPDarknet53

Implements the CSP_Darknet53 module and inherit the forward pass to extract layers indicated in arch_params

forward(x)[source]

:return A list, the length of self._modules_list containing the output of the layer if specified in self._layers_to_extract and None otherwise

training: bool
class super_gradients.training.models.yolov5.YoLoV5Head(arch_params)[source]

Bases: torch.nn.modules.module.Module

forward(intermediate_output)[source]
Parameters

intermediate_output – A list of the intermediate prediction of layers specified in the

self._inter_layer_idx_to_extract from the Backbone

training: bool
class super_gradients.training.models.yolov5.YoLoV5L(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.yolov5.YoLoV5Base

training: bool
class super_gradients.training.models.yolov5.YoLoV5M(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.yolov5.YoLoV5Base

training: bool
class super_gradients.training.models.yolov5.YoLoV5S(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.yolov5.YoLoV5Base

training: bool
class super_gradients.training.models.yolov5.YoLoV5X(arch_params: super_gradients.training.utils.utils.HpmStruct)[source]

Bases: super_gradients.training.models.yolov5.YoLoV5Base

training: bool
class super_gradients.training.models.yolov5.YoloV5PostPredictionCallback(conf: float = 0.001, iou: float = 0.6, classes: Optional[List[int]] = None, nms_type: super_gradients.training.utils.detection_utils.NMS_Type = <NMS_Type.ITERATIVE: 'iterative'>, max_predictions: int = 300)[source]

Bases: super_gradients.training.utils.detection_utils.DetectionPostPredictionCallback

Non-Maximum Suppression (NMS) module

forward(x, device: Optional[str] = None)[source]
Parameters
  • x – the output of your model

  • device – the device to move all output tensors into

Returns

a list with length batch_size, each item in the list is a detections with shape: nx6 (x1, y1, x2, y2, confidence, class) where x and y are in range [0,1]

training: bool

Module contents