ResNet¶
The ResNet model is based on the "Deep Residual Learning for Image Recognition" paper.
Architecture overview¶
This paper introduces a few tricks to maximize the depth of convolutional architectures that can be trained.
The key takeaways from the paper are the following:
- add a shortcut connection in bottleneck blocks to ease the gradient flow
- extensive use of batch normalization layers
Model builders¶
The following model builders can be used to instantiate a ResNeXt model, with or
without pre-trained weights. All the model builders internally rely on the
ResNet base class.
ResNet
¶
ResNet(block: type[BasicBlock | Bottleneck], num_blocks: list[int], planes: list[int], num_classes: int = 10, in_channels: int = 3, zero_init_residual: bool = False, width_per_group: int = 64, conv_layer: Callable[..., Module] | None = None, act_layer: Module | None = None, norm_layer: Callable[[int], Module] | None = None, drop_layer: Callable[..., Module] | None = None, deep_stem: bool = False, stem_pool: bool = True, avg_downsample: bool = False, num_repeats: int = 1, block_args: dict[str, Any] | list[dict[str, Any]] | None = None)
Bases: Sequential
Source code in holocron/models/classification/resnet.py
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 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 | |
resnet18
¶
resnet18(pretrained: bool = False, checkpoint: Checkpoint | None = None, progress: bool = True, **kwargs: Any) -> ResNet
ResNet-18 from "Deep Residual Learning for Image Recognition"
| PARAMETER | DESCRIPTION |
|---|---|
pretrained
|
If True, returns a model pre-trained on ImageNet
TYPE:
|
checkpoint
|
If specified, loads that checkpoint
TYPE:
|
progress
|
If True, displays a progress bar of the download to stderr
TYPE:
|
kwargs
|
keyword args of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResNet
|
classification model |
ResNet18_Checkpoint
¶
Bases: Enum
IMAGENETTE
class-attribute
instance-attribute
¶
IMAGENETTE = _checkpoint(arch='resnet18', url='https://github.com/frgfm/Holocron/releases/download/v0.2.1/resnet18_224-fc07006c.pth', acc1=0.9361, acc5=0.9946, sha256='fc07006c894cac8cf380fed699bc5a68463698753c954632f52bb8595040f781', size=44787043, num_params=11181642, commit='6e32c5b578711a2ef3731a8f8c61760ed9f03e58', train_args='./imagenette2-320/ --arch resnet18 --batch-size 64 --mixup-alpha 0.2 --amp --device 0 --epochs 100 --lr 1e-3 --label-smoothing 0.1 --random-erase 0.1 --train-crop-size 176 --val-resize-size 232 --opt adamw --weight-decay 5e-2')
Source code in holocron/models/classification/resnet.py
resnet34
¶
resnet34(pretrained: bool = False, checkpoint: Checkpoint | None = None, progress: bool = True, **kwargs: Any) -> ResNet
ResNet-34 from "Deep Residual Learning for Image Recognition"
| PARAMETER | DESCRIPTION |
|---|---|
pretrained
|
If True, returns a model pre-trained on ImageNet
TYPE:
|
checkpoint
|
If specified, load that checkpoint on the model
TYPE:
|
progress
|
If True, displays a progress bar of the download to stderr
TYPE:
|
kwargs
|
keyword args of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResNet
|
classification model |
ResNet34_Checkpoint
¶
Bases: Enum
IMAGENETTE
class-attribute
instance-attribute
¶
IMAGENETTE = _checkpoint(arch='resnet34', url='https://github.com/frgfm/Holocron/releases/download/v0.2.1/resnet34_224-412b0792.pth', acc1=0.9381, acc5=0.9949, sha256='412b07927cc1938ee3add8d0f6bb18b42786646182f674d75f1433d086914485', size=85267035, num_params=21289802, commit='6e32c5b578711a2ef3731a8f8c61760ed9f03e58', train_args='./imagenette2-320/ --arch resnet34 --batch-size 64 --mixup-alpha 0.2 --amp --device 0 --epochs 100 --lr 1e-3 --label-smoothing 0.1 --random-erase 0.1 --train-crop-size 176 --val-resize-size 232 --opt adamw --weight-decay 5e-2')
Source code in holocron/models/classification/resnet.py
resnet50
¶
resnet50(pretrained: bool = False, checkpoint: Checkpoint | None = None, progress: bool = True, **kwargs: Any) -> ResNet
ResNet-50 from "Deep Residual Learning for Image Recognition"
| PARAMETER | DESCRIPTION |
|---|---|
pretrained
|
If True, returns a model pre-trained on ImageNet
TYPE:
|
checkpoint
|
If specified, load that checkpoint on the model
TYPE:
|
progress
|
If True, displays a progress bar of the download to stderr
TYPE:
|
kwargs
|
keyword args of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResNet
|
classification model |
ResNet50_Checkpoint
¶
Bases: Enum
IMAGENETTE
class-attribute
instance-attribute
¶
IMAGENETTE = _checkpoint(arch='resnet50', url='https://github.com/frgfm/Holocron/releases/download/v0.2.1/resnet50_224-5b913f0b.pth', acc1=0.9378, acc5=0.9954, sha256='5b913f0b8148b483ba15541ab600cf354ca42b326e4896c4c3dbc51eb1e80e70', size=94384682, num_params=23528522, commit='6e32c5b578711a2ef3731a8f8c61760ed9f03e58', train_args='./imagenette2-320/ --arch resnet50 --batch-size 64 --mixup-alpha 0.2 --amp --device 0 --epochs 100 --lr 1e-3 --label-smoothing 0.1 --random-erase 0.1 --train-crop-size 176 --val-resize-size 232 --opt adamw --weight-decay 5e-2')
Source code in holocron/models/classification/resnet.py
resnet50d
¶
resnet50d(pretrained: bool = False, checkpoint: Checkpoint | None = None, progress: bool = True, **kwargs: Any) -> ResNet
ResNet-50-D from "Bag of Tricks for Image Classification with Convolutional Neural Networks" https://arxiv.org/pdf/1812.01187.pdf`_
| PARAMETER | DESCRIPTION |
|---|---|
pretrained
|
If True, returns a model pre-trained on ImageNet
TYPE:
|
checkpoint
|
If specified, load that checkpoint on the model
TYPE:
|
progress
|
If True, displays a progress bar of the download to stderr
TYPE:
|
kwargs
|
keyword args of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResNet
|
classification model |
ResNet50D_Checkpoint
¶
Bases: Enum
IMAGENETTE
class-attribute
instance-attribute
¶
IMAGENETTE = _checkpoint(arch='resnet50d', url='https://github.com/frgfm/Holocron/releases/download/v0.2.1/resnet50d_224-6218d936.pth', acc1=0.9465, acc5=0.9952, sha256='6218d936fa67c0047f1ec65564213db538aa826d84f2df1d4fa3224531376e6c', size=94464810, num_params=23547754, commit='6e32c5b578711a2ef3731a8f8c61760ed9f03e58', train_args='./imagenette2-320/ --arch resnet50d --batch-size 64 --mixup-alpha 0.2 --amp --device 0 --epochs 100 --lr 1e-3 --label-smoothing 0.1 --random-erase 0.1 --train-crop-size 176 --val-resize-size 232 --opt adamw --weight-decay 5e-2')
Source code in holocron/models/classification/resnet.py
resnet101
¶
resnet101(pretrained: bool = False, checkpoint: Checkpoint | None = None, progress: bool = True, **kwargs: Any) -> ResNet
ResNet-101 from "Deep Residual Learning for Image Recognition"
| PARAMETER | DESCRIPTION |
|---|---|
pretrained
|
If True, returns a model pre-trained on ImageNet
TYPE:
|
checkpoint
|
If specified, load that checkpoint on the model
TYPE:
|
progress
|
If True, displays a progress bar of the download to stderr
TYPE:
|
kwargs
|
keyword args of _resnet
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResNet
|
torch.nn.Module: classification model |
Source code in holocron/models/classification/resnet.py
resnet152
¶
resnet152(pretrained: bool = False, checkpoint: Checkpoint | None = None, progress: bool = True, **kwargs: Any) -> ResNet
ResNet-152 from "Deep Residual Learning for Image Recognition"
| PARAMETER | DESCRIPTION |
|---|---|
pretrained
|
If True, returns a model pre-trained on ImageNet
TYPE:
|
checkpoint
|
If specified, load that checkpoint on the model
TYPE:
|
progress
|
If True, displays a progress bar of the download to stderr
TYPE:
|
kwargs
|
keyword args of
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ResNet
|
classification model |