Models
get_arch_params(config_name, overriding_params=None, recipes_dir_path=None)
Class for creating arch parameters dictionary, taking defaults from yaml files in src/super_gradients/recipes/arch_params.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_name |
str
|
Name of the yaml to load (e.g. "resnet18_cifar_arch_params") |
required |
overriding_params |
Dict
|
Dict, dictionary like object containing entries to override. |
None
|
recipes_dir_path |
Optional[str]
|
Optional. Main directory where every recipe are stored. (e.g. ../super_gradients/recipes) This directory should include a "arch_params" folder, which itself should include the config file named after config_name. |
None
|
Source code in latest/src/super_gradients/training/models/arch_params_factory.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
BaseClassifier
Bases: SgModule
, HasPredict
Source code in latest/src/super_gradients/training/models/classification_models/base_classifer.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
predict(images, batch_size=32, fuse_model=True)
Predict an image or a list of images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
images |
ImageSource
|
Images to predict. |
required |
batch_size |
int
|
Maximum number of images to process at the same time. |
32
|
fuse_model |
bool
|
If True, create a copy of the model, and fuse some of its layers to increase performance. This increases memory usage. |
True
|
Source code in latest/src/super_gradients/training/models/classification_models/base_classifer.py
50 51 52 53 54 55 56 57 58 |
|
predict_webcam(fuse_model=True)
Predict using webcam.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fuse_model |
bool
|
If True, create a copy of the model, and fuse some of its layers to increase performance. This increases memory usage. |
True
|
Source code in latest/src/super_gradients/training/models/classification_models/base_classifer.py
60 61 62 63 64 65 |
|
set_dataset_processing_params(class_names=None, image_processor=None)
Set the processing parameters for the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_names |
Optional[List[str]]
|
(Optional) Names of the dataset the model was trained on. |
None
|
image_processor |
Optional[Processing]
|
(Optional) Image processing objects to reproduce the dataset preprocessing used for training. |
None
|
Source code in latest/src/super_gradients/training/models/classification_models/base_classifer.py
22 23 24 25 26 27 28 29 30 |
|
BEIT: BERT Pre-Training of Image Transformers (https://arxiv.org/abs/2106.08254)
Model from official source: https://github.com/microsoft/unilm/tree/master/beit
At this point only the 1k fine-tuned classification weights and model configs have been added, see original source above for pre-training models and procedure.
Modifications by / Copyright 2021 Ross Wightman, original copyrights below
Beit
Bases: BaseClassifier
Vision Transformer with support for patch or hybrid CNN input stage
Source code in latest/src/super_gradients/training/models/classification_models/beit.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
Mlp
Bases: nn.Module
MLP as used in Vision Transformer, MLP-Mixer and related networks
Source code in latest/src/super_gradients/training/models/classification_models/beit.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
trunc_normal_(tensor, mean=0.0, std=1.0, a=-2.0, b=2.0)
Fills the input Tensor with values drawn from a truncated
normal distribution. The values are effectively drawn from the
normal distribution :math:\mathcal{N}(\text{mean}, \text{std}^2)
with values outside :math:[a, b]
redrawn until they are within
the bounds. The method used for generating the random values works
best when :math:a \leq \text{mean} \leq b
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor |
an n-dimensional |
required | |
mean |
the mean of the normal distribution |
0.0
|
|
std |
the standard deviation of the normal distribution |
1.0
|
|
a |
the minimum cutoff value |
-2.0
|
|
b |
the maximum cutoff value Examples: >>> w = torch.empty(3, 5) >>> nn.init.trunc_normal_(w) |
2.0
|
Source code in latest/src/super_gradients/training/models/classification_models/beit.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
DenseNet
Bases: BaseClassifier
Source code in latest/src/super_gradients/training/models/classification_models/densenet.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
__init__(growth_rate, structure, num_init_features, bn_size, drop_rate, num_classes)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
growth_rate |
int
|
number of filter to add each layer (noted as 'k' in the paper) |
required |
structure |
list
|
how many layers in each pooling block - sequentially |
required |
num_init_features |
int
|
the number of filters to learn in the first convolutional layer |
required |
bn_size |
int
|
multiplicative factor for the number of bottle neck layers (i.e. bn_size * k featurs in the bottleneck) |
required |
drop_rate |
float
|
dropout rate after each dense layer |
required |
num_classes |
int
|
number of classes in the classification task |
required |
Source code in latest/src/super_gradients/training/models/classification_models/densenet.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
Dual Path Networks in PyTorch.
Credits: https://github.com/kuangliu/pytorch-cifar/blob/master/models/dpn.py
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 Pre-trained checkpoints converted to Deci's code base with the reported accuracy can be found in S3 repo
BlockDecoder
Bases: object
Block Decoder for readability, straight from the official TensorFlow repository.
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
decode(string_list)
staticmethod
Decode a list of string notations to specify blocks inside the network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_list |
List[str]
|
List of strings, each string is a notation of block. |
required |
Returns:
Type | Description |
---|---|
List[BlockArgs]
|
List of BlockArgs namedtuples of block args. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
277 278 279 280 281 282 283 284 285 286 287 288 |
|
encode(blocks_args)
staticmethod
Encode a list of BlockArgs to a list of strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blocks_args |
List
|
A list of BlockArgs namedtuples of block args. (list[namedtuples]) |
required |
Returns:
Type | Description |
---|---|
block_strings: A list of strings, each string is a notation of block. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
290 291 292 293 294 295 296 297 298 299 300 |
|
Conv2dDynamicSamePadding
Bases: nn.Conv2d
2D Convolutions like TensorFlow, for a dynamic image size. The padding is operated in forward function by calculating dynamically.
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
Conv2dStaticSamePadding
Bases: nn.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.
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
EfficientNet
Bases: BaseClassifier
EfficientNet model.
References: [1] https://arxiv.org/abs/1905.11946 (EfficientNet)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width_coefficient |
float
|
model's width coefficient. Used as the multiplier. |
required |
depth_coefficient |
float
|
model's depth coefficient. Used as the multiplier. |
required |
image_size |
int
|
Size of input image. |
required |
dropout_rate |
float
|
Dropout probability in final layer |
required |
num_classes |
int
|
Number of classes. |
required |
batch_norm_momentum |
Optional[float]
|
Value used for the running_mean and running_var computation |
0.99
|
batch_norm_epsilon |
Optional[float]
|
Value added to the denominator for numerical stability |
0.001
|
drop_connect_rate |
Optional[float]
|
Connection dropout probability |
0.2
|
depth_divisor |
Optional[int]
|
Model's depth divisor. Used as the divisor. |
8
|
min_depth |
Optional[int]
|
Model's minimal depth, if given. |
None
|
backbone_mode |
Optional[bool]
|
If true, dropping the final linear layer |
False
|
blocks_args |
Optional[list]
|
List of BlockArgs to construct blocks. (list[namedtuple]) |
None
|
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
|
extract_features(inputs)
Use convolution layer to extract feature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
torch.Tensor
|
Input tensor. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
Output of the final convolution layer in the efficientnet model. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
forward(inputs)
EfficientNet's forward function. Calls extract_features to extract features, applies final linear layer, and returns logits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
Input tensor. |
required |
Returns:
Type | Description |
---|---|
Output of this model after processing. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
|
load_state_dict(state_dict, strict=True)
load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_dict |
dict
|
The state_dict to load |
required |
strict |
bool
|
strict loading (see super() docs) |
True
|
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
|
Identity
Bases: nn.Module
Identity mapping. Send input to output directly.
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
205 206 207 208 209 210 211 212 213 214 |
|
MBConvBlock
Bases: nn.Module
Mobile Inverted Residual Bottleneck Block.
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)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_args |
BlockArgs
|
BlockArgs. |
required |
batch_norm_momentum |
float
|
Batch norm momentum. |
required |
batch_norm_epsilon |
float
|
Batch norm epsilon. |
required |
image_size |
Union[Tuple, List]
|
[image_height, image_width]. |
None
|
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
forward(inputs, drop_connect_rate=None)
MBConvBlock's forward function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
torch.Tensor
|
Input tensor. |
required |
drop_connect_rate |
Optional[float]
|
Drop connect rate (float, between 0 and 1). |
None
|
Returns:
Type | Description |
---|---|
torch.Tensor
|
Output of this block after processing. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
calculate_output_image_size(input_image_size, stride)
Calculates the output image size when using Conv2dSamePadding with a stride. Necessary for static padding. Thanks to mannatsingh for pointing this out.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_image_size |
Union[int, Tuple, List]
|
Size of input image. |
required |
stride |
Union[int, Tuple, List]
|
Conv2d operation's stride. |
required |
Returns:
Type | Description |
---|---|
Optional[List[int]]
|
output_image_size: A list [H,W]. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
drop_connect(inputs, p, training)
Drop connect.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
inputs
|
Input of this structure. (tensor: BCWH) |
required |
training |
bool
|
Running mode. |
required |
Returns:
Type | Description |
---|---|
torch.Tensor
|
output: Output after drop connection. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
get_same_padding_conv2d(image_size=None)
Chooses static padding if you have specified an image size, and dynamic padding otherwise. Static padding is necessary for ONNX exporting of models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_size |
Optional[Union[int, Tuple[int, int]]]
|
Size of the image. |
None
|
Returns:
Type | Description |
---|---|
Conv2dDynamicSamePadding or Conv2dStaticSamePadding. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
129 130 131 132 133 134 135 136 137 138 139 |
|
round_filters(filters, width_coefficient, depth_divisor, min_depth)
Calculate and round number of filters based on width multiplier. Use width_coefficient, depth_divisor and min_depth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters |
int
|
Filters number to be calculated. Params from arch_params: |
required |
width_coefficient |
int
|
model's width coefficient. Used as the multiplier. |
required |
depth_divisor |
int
|
model's depth divisor. Used as the divisor. |
required |
min_depth |
int
|
model's minimal depth, if given. |
required |
Returns:
Type | Description |
---|---|
new_filters: New filters number after calculating. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
round_repeats(repeats, depth_coefficient)
Calculate module's repeat number of a block based on depth multiplier. Use depth_coefficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repeats |
int
|
num_repeat to be calculated. |
required |
depth_coefficient |
int
|
the depth coefficient of the model. this func uses it as the multiplier. |
required |
Returns:
Type | Description |
---|---|
new repeat: New repeat number after calculating. |
Source code in latest/src/super_gradients/training/models/classification_models/efficientnet.py
64 65 66 67 68 69 70 71 72 73 74 75 |
|
Googlenet code based on https://pytorch.org/vision/stable/_modules/torchvision/models/googlenet.html
GoogLeNet
Bases: BaseClassifier
Source code in latest/src/super_gradients/training/models/classification_models/googlenet.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
load_state_dict(state_dict, strict=True)
load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_dict |
The state_dict to load |
required | |
strict |
strict loading (see super() docs) |
True
|
Source code in latest/src/super_gradients/training/models/classification_models/googlenet.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
MobileNet in PyTorch.
See the paper "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" for more details.
Block
Bases: nn.Module
Depthwise conv + Pointwise conv
Source code in latest/src/super_gradients/training/models/classification_models/mobilenet.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
MobileNet
Bases: BaseClassifier
Source code in latest/src/super_gradients/training/models/classification_models/mobilenet.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
forward(x)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
up_to_layer |
forward through the net layers up to a specific layer. if None, run all layers |
required |
Source code in latest/src/super_gradients/training/models/classification_models/mobilenet.py
50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
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/
Pre-trained ImageNet model: 'deci-model-repository/mobilenet_v2/ckpt_best.pth'
CustomMobileNetV2
Bases: MobileNetV2
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
__init__(arch_params)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arch_params |
–≠ HpmStruct must contain: 'num_classes': int 'width_mult': float 'structure' : list. specify the mobilenetv2 architecture |
required |
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
InvertedResidual
Bases: nn.Module
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
__init__(inp, oup, stride, expand_ratio, grouped_conv_size=1)
:grouped_conv_size: number of channels per grouped convolution, for depth-wise-separable convolution, use grouped_conv_size=1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inp |
number of input channels |
required | |
oup |
number of output channels |
required | |
stride |
conv stride |
required | |
expand_ratio |
expansion ratio of the hidden layer after pointwise conv |
required |
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
MobileNetV2
Bases: MobileNetBase
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
MobileNetV2Base
Bases: MobileNetV2
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
__init__(arch_params)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arch_params |
HpmStruct must contain: 'num_classes': int |
required |
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
194 195 196 197 198 199 200 201 202 203 204 205 |
|
MobileNetV2_135
Bases: MobileNetV2
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
__init__(arch_params)
This Model achieves–≠ 75.73% on Imagenet - similar to Resnet50
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arch_params |
HpmStruct must contain: 'num_classes': int |
required |
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv2.py
210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
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.
mobilenetv3_custom
Bases: MobileNetV3
Constructs a MobileNetV3-Customized model
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv3.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
mobilenetv3_large
Bases: MobileNetV3
Constructs a MobileNetV3-Large model
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv3.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
mobilenetv3_small
Bases: MobileNetV3
Constructs a MobileNetV3-Small model
Source code in latest/src/super_gradients/training/models/classification_models/mobilenetv3.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
PNASNet in PyTorch.
Paper: Progressive Neural Architecture Search
https://github.com/kuangliu/pytorch-cifar/blob/master/models/pnasnet.py
SepConv
Bases: nn.Module
Separable Convolution.
Source code in latest/src/super_gradients/training/models/classification_models/pnasnet.py
13 14 15 16 17 18 19 20 21 22 |
|
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
PreActBlock
Bases: nn.Module
Pre-activation version of the BasicBlock.
Source code in latest/src/super_gradients/training/models/classification_models/preact_resnet.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
PreActBottleneck
Bases: nn.Module
Pre-activation version of the original Bottleneck module.
Source code in latest/src/super_gradients/training/models/classification_models/preact_resnet.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
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
CustomAnyNet
Bases: AnyNetX
Source code in latest/src/super_gradients/training/models/classification_models/regnet.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
__init__(arch_params)
All parameters must be provided in arch_params other than SE
Source code in latest/src/super_gradients/training/models/classification_models/regnet.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
CustomRegNet
Bases: RegNetX
Source code in latest/src/super_gradients/training/models/classification_models/regnet.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
__init__(arch_params)
All parameters must be provided in arch_params other than SE
Source code in latest/src/super_gradients/training/models/classification_models/regnet.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
NASRegNet
Bases: RegNetX
Source code in latest/src/super_gradients/training/models/classification_models/regnet.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
__init__(arch_params)
All parameters are provided as a single structure list: arch_params.structure
Source code in latest/src/super_gradients/training/models/classification_models/regnet.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
verify_correctness_of_parameters(ls_num_blocks, ls_block_width, ls_bottleneck_ratio, ls_group_width)
VERIFY THAT THE GIVEN PARAMETERS FIT THE SEARCH SPACE DEFINED IN THE REGNET PAPER
Source code in latest/src/super_gradients/training/models/classification_models/regnet.py
226 227 228 229 230 231 232 233 234 235 236 |
|
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: [1] https://github.com/DingXiaoH/RepVGG [2] https://arxiv.org/pdf/2101.03697.pdf
Based on https://github.com/DingXiaoH/RepVGG
RepVGG
Bases: BaseClassifier
Source code in latest/src/super_gradients/training/models/classification_models/repvgg.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
__init__(struct, num_classes=1000, width_multiplier=None, build_residual_branches=True, use_se=False, backbone_mode=False, in_channels=3)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
struct |
list containing number of blocks per repvgg stage |
required | |
num_classes |
number of classes if nut in backbone mode |
1000
|
|
width_multiplier |
list of per stage width multiplier or float if using single value for all stages |
None
|
|
build_residual_branches |
whether to add residual connections or not |
True
|
|
use_se |
use squeeze and excitation layers |
False
|
|
backbone_mode |
if true, dropping the final linear layer |
False
|
|
in_channels |
input channels |
3
|
Source code in latest/src/super_gradients/training/models/classification_models/repvgg.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
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
Pre-trained ImageNet models: 'deci-model-repository/resnet?/ckpt_best.pth' => ? = the type of resnet (e.g. 18, 34...) Pre-trained CIFAR10 models: 'deci-model-repository/CIFAR_NAS_#??????/ckpt_best.pth' => ? = num of model, structure, width_mult
Code adapted from https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py
ResNet
Bases: BaseClassifier
Source code in latest/src/super_gradients/training/models/classification_models/resnet.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
load_state_dict(state_dict, strict=True)
load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_dict |
The state_dict to load |
required | |
strict |
strict loading (see super() docs) |
True
|
Source code in latest/src/super_gradients/training/models/classification_models/resnet.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
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
GroupedConvBlock
Bases: nn.Module
Grouped convolution block.
Source code in latest/src/super_gradients/training/models/classification_models/resnext.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
conv1x1(in_planes, out_planes, stride=1)
1x1 convolution
Source code in latest/src/super_gradients/training/models/classification_models/resnext.py
20 21 22 |
|
conv3x3(in_planes, out_planes, stride=1, groups=1, dilation=1)
3x3 convolution with padding
Source code in latest/src/super_gradients/training/models/classification_models/resnext.py
15 16 17 |
|
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
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
ShuffleBlock
Bases: nn.Module
Source code in latest/src/super_gradients/training/models/classification_models/shufflenet.py
13 14 15 16 17 18 19 20 21 22 |
|
forward(x)
Channel shuffle: [N,C,H,W] -> [N,g,C/g,H,W] -> [N,C/g,g,H,w] -> [N,C,H,W]
Source code in latest/src/super_gradients/training/models/classification_models/shufflenet.py
18 19 20 21 22 |
|
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
ChannelShuffleInvertedResidual
Bases: nn.Module
Implement Inverted Residual block as in [https://arxiv.org/abs/1807.11164] in Fig.3 (c) & (d):
- When stride > 1
- the whole input goes through branch1,
- the whole input goes through branch2 , and the arbitrary number of output channels are produced.
- When stride == 1
- half of input channels in are passed as identity,
- another half of input channels goes through branch2, and the number of output channels after the block remains the same as in input.
Channel shuffle is performed on a concatenation in both cases.
Source code in latest/src/super_gradients/training/models/classification_models/shufflenetv2.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
channel_shuffle(x, groups)
staticmethod
From "ShuffleNet V2: Practical Guidelines for EfficientCNN Architecture Design" (https://arxiv.org/abs/1807.11164): A “channel shuffle” operation is then introduced to enable information communication between different groups of channels and improve accuracy.
The operation preserves x.size(), but shuffles its channels in the manner explained further in the example.
Example: If group = 2 (2 branches with the same # of activation maps were concatenated before channel_shuffle), then activation maps in x are: from_B1, from_B1, ... from_B2, from_B2 After channel_shuffle activation maps in x will be: from_B1, from_B2, ... from_B1, from_B2
Source code in latest/src/super_gradients/training/models/classification_models/shufflenetv2.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
ShuffleNetV2Base
Bases: BaseClassifier
Source code in latest/src/super_gradients/training/models/classification_models/shufflenetv2.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
load_state_dict(state_dict, strict=True)
load_state_dict - Overloads the base method and calls it to load a modified dict for usage as a backbone
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_dict |
The state_dict to load |
required | |
strict |
strict loading (see super() docs) |
True
|
Source code in latest/src/super_gradients/training/models/classification_models/shufflenetv2.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
VGG11/13/16/19 in Pytorch. Adapted from https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py
Vision Transformer in PyTorch. Reference: [1] Dosovitskiy, Alexey, et al. "An image is worth 16x16 words: Transformers for image recognition at scale." arXiv preprint arXiv:2010.11929 (2020)
Code adapted from https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/vit.py
Attention
Bases: nn.Module
self attention layer with residual connection
Source code in latest/src/super_gradients/training/models/classification_models/vit.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
FeedForward
Bases: nn.Module
feed forward block with residual connection
Source code in latest/src/super_gradients/training/models/classification_models/vit.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
PatchEmbed
Bases: nn.Module
2D Image to Patch Embedding Using Conv layers (Faster than rearranging + Linear)
Source code in latest/src/super_gradients/training/models/classification_models/vit.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
ViT
Bases: BaseClassifier
Source code in latest/src/super_gradients/training/models/classification_models/vit.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
__init__(image_size, patch_size, num_classes, hidden_dim, depth, heads, mlp_dim, in_channels=3, dropout_prob=0.0, emb_dropout_prob=0.0, backbone_mode=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_size |
tuple
|
Image size tuple for data processing into patches done within the model. |
required |
patch_size |
tuple
|
Patch size tuple for data processing into patches done within the model. |
required |
num_classes |
int
|
Number of classes for the classification head. |
required |
hidden_dim |
int
|
Output dimension of each transformer block. |
required |
depth |
int
|
Number of transformer blocks |
required |
heads |
int
|
Number of attention heads |
required |
mlp_dim |
int
|
Intermediate dimension of the transformer block's feed forward |
required |
in_channels |
input channels |
3
|
|
dropout |
Dropout ratio between the feed forward layers. |
required | |
emb_dropout |
Dropout ratio between after the embedding layer |
required | |
backbone_mode |
If True output after pooling layer |
False
|
Source code in latest/src/super_gradients/training/models/classification_models/vit.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
ConvertableCompletePipelineModel
Bases: torch.nn.Module
Exportable nn.Module that wraps the model, preprocessing and postprocessing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
torch.nn.Module
|
torch.nn.Module, the main model. takes input from pre_process' output, and feeds pre_process. |
required |
pre_process |
torch.nn.Module
|
torch.nn.Module, preprocessing module, its output will be model's input. When none (default), set to Identity(). |
None
|
**prep_model_for_conversion_kwargs |
for SgModules- args to be passed to model.prep_model_for_conversion prior to torch.onnx.export call. |
{}
|
Source code in latest/src/super_gradients/training/models/conversion.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
convert_from_config(cfg)
Exports model according to cfg.
See: super_gradients/recipes/conversion_params/default_conversion_params.yaml for the full cfg content documentation, and super_gradients/examples/convert_recipe_example/convert_recipe_example.py for usage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg |
DictConfig
|
required |
Returns:
Type | Description |
---|---|
str
|
out_path, the path of the saved .onnx file. |
Source code in latest/src/super_gradients/training/models/conversion.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
convert_to_coreml(model, out_path, input_size=None, pre_process=None, post_process=None, prep_model_for_conversion_kwargs=None, export_as_ml_program=False, torch_trace_kwargs=None)
Exports a given SG model to CoreML mlprogram or package.
:param model: torch.nn.Module, model to export to CoreML.
:param out_path: str, destination path for the .mlmodel file.
:param input_size: Input shape without batch dimensions ([C,H,W]). Batch size assumed to be 1.
:param pre_process: torch.nn.Module, preprocessing pipeline, will be resolved by TransformsFactory()
:param post_process: torch.nn.Module, postprocessing pipeline, will be resolved by TransformsFactory()
:param prep_model_for_conversion_kwargs: dict, for SgModules- args to be passed to model.prep_model_for_conversion
prior to ct.convert call. Supported keys are:
- input_size - Shape of inputs with batch dimension, [C,H,W] for image inputs.
:param export_as_ml_program: Whether to convert to the new program format (better) or legacy coreml proto file
(Supports more iOS versions and devices, but this format will be deprecated at some point).
:param torch_trace_kwargs: kwargs for torch.jit.trace
Returns:
Type | Description |
---|---|
Path |
Source code in latest/src/super_gradients/training/models/conversion.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
convert_to_onnx(model, out_path, input_shape=None, pre_process=None, post_process=None, prep_model_for_conversion_kwargs=None, torch_onnx_export_kwargs=None, simplify=True)
Exports model to ONNX.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
torch.nn.Module
|
torch.nn.Module, model to export to ONNX. |
required |
out_path |
str
|
str, destination path for the .onnx file. |
required |
input_shape |
tuple
|
Input shape without batch dimensions ([C,H,W]). Batch size assumed to be 1. DEPRECATED USE input_size KWARG IN prep_model_for_conversion_kwargs INSTEAD. |
None
|
pre_process |
torch.nn.Module
|
torch.nn.Module, preprocessing pipeline, will be resolved by TransformsFactory() |
None
|
post_process |
torch.nn.Module
|
torch.nn.Module, postprocessing pipeline, will be resolved by TransformsFactory() |
None
|
prep_model_for_conversion_kwargs |
dict, for SgModules- args to be passed to model.prep_model_for_conversion prior to torch.onnx.export call. Supported keys are: - input_size - Shape of inputs with batch dimension, [C,H,W] for image inputs. |
None
|
|
torch_onnx_export_kwargs |
kwargs (EXCLUDING: FIRST 3 KWARGS- MODEL, F, ARGS). to be unpacked in torch.onnx.export call |
None
|
|
simplify |
bool
|
bool,whether to apply onnx simplifier method, same as `python -m onnxsim onnx_path onnx_sim_path. When true, the simplified model will be saved in out_path (default=True). |
True
|
Returns:
Type | Description |
---|---|
out_path |
Source code in latest/src/super_gradients/training/models/conversion.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
onnx_simplify(onnx_path, onnx_sim_path)
onnx simplifier method, same as `python -m onnxsim onnx_path onnx_sim_path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
onnx_path |
str
|
path to onnx model |
required |
onnx_sim_path |
str
|
path for output onnx simplified model |
required |
Source code in latest/src/super_gradients/training/models/conversion.py
276 277 278 279 280 281 282 283 284 285 |
|
prepare_conversion_cfgs(cfg)
Builds the cfg (i.e conversion_params) and experiment_cfg (i.e recipe config according to cfg.experiment_name) to be used by convert_recipe_example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg |
DictConfig
|
DictConfig, converion_params config |
required |
Returns:
Type | Description |
---|---|
cfg, experiment_cfg |
Source code in latest/src/super_gradients/training/models/conversion.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
CSP Darknet
CSPLayer
Bases: nn.Module
CSP Bottleneck with 3 convolutions
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
int, input channels. |
required |
out_channels |
int
|
int, output channels. |
required |
num_bottlenecks |
int
|
int, number of bottleneck conv layers. |
required |
act |
Type[nn.Module]
|
Type[nn.module], activation type. |
required |
shortcut |
bool
|
bool, whether to apply shortcut (i.e add input to result) in bottlenecks (default=True). |
True
|
depthwise |
bool
|
bool, whether to use GroupedConvBlock in last conv in bottlenecks (default=False). |
False
|
expansion |
float
|
float, determines the number of hidden channels (default=0.5). |
0.5
|
Source code in latest/src/super_gradients/training/models/detection_models/csp_darknet53.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
GroupedConvBlock
Bases: nn.Module
Grouped Conv KxK -> usual Conv 1x1
Source code in latest/src/super_gradients/training/models/detection_models/csp_darknet53.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
__init__(input_channels, output_channels, kernel, stride, activation_type, padding=None, groups=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
groups |
int
|
num of groups in the first conv; if None depthwise separable conv will be used (groups = input channels) |
None
|
Source code in latest/src/super_gradients/training/models/detection_models/csp_darknet53.py
42 43 44 45 46 47 48 49 50 |
|
SPP
Bases: BaseDetectionModule
Source code in latest/src/super_gradients/training/models/detection_models/csp_darknet53.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
out_channels
property
Returns:
Type | Description |
---|---|
channels of tensor(s) that will be returned by a module in forward |
ViewModule
Bases: nn.Module
Returns a reshaped version of the input, to be used in None-Backbone Mode
Source code in latest/src/super_gradients/training/models/detection_models/csp_darknet53.py
157 158 159 160 161 162 163 164 165 166 167 |
|
CSPResNetBackbone
Bases: nn.Module
CSPResNet backbone
Source code in latest/src/super_gradients/training/models/detection_models/csp_resnet.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
__init__(layers, channels, activation, return_idx, use_large_stem, width_mult, depth_mult, use_alpha, pretrained_weights=None, in_channels=3)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layers |
Tuple[int, ...]
|
Number of blocks in each stage |
required |
channels |
Tuple[int, ...]
|
Number of channels [stem, stage 0, stage 1, stage 2, ...] |
required |
activation |
Type[nn.Module]
|
Used activation type for all child modules. |
required |
return_idx |
Tuple[int, int, int]
|
Indexes of returned feature maps |
required |
use_large_stem |
bool
|
If True, uses 3 conv+bn+act instead of 2 in stem blocks |
required |
width_mult |
float
|
Scaling factor for a number of channels |
required |
depth_mult |
float
|
Scaling factor for a number of blocks in each stage |
required |
use_alpha |
bool
|
If True, enables additional learnable weighting parameter for 1x1 branch in RepVGGBlock |
required |
pretrained_weights |
Optional[str]
|
None
|
|
in_channels |
int
|
Number of input channels. Default: 3 |
3
|
Source code in latest/src/super_gradients/training/models/detection_models/csp_resnet.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
prep_model_for_conversion(input_size=None, **kwargs)
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_size |
Union[tuple, list]
|
[H,W] |
None
|
Source code in latest/src/super_gradients/training/models/detection_models/csp_resnet.py
232 233 234 235 236 237 238 239 240 241 |
|
CSPResNetBasicBlock
Bases: nn.Module
Source code in latest/src/super_gradients/training/models/detection_models/csp_resnet.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
__init__(in_channels, out_channels, activation_type, use_residual_connection=True, use_alpha=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_channels |
int
|
required | |
out_channels |
int
|
required | |
activation_type |
Type[nn.Module]
|
required | |
use_residual_connection |
bool
|
Whether to add input x to the output |
True
|
use_alpha |
If True, enables additional learnable weighting parameter for 1x1 branch in RepVGGBlock |
False
|
Source code in latest/src/super_gradients/training/models/detection_models/csp_resnet.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
CSPResStage
Bases: nn.Module
Source code in latest/src/super_gradients/training/models/detection_models/csp_resnet.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|