regnet.py 62.1 KB
Newer Older
1
2
3
import math
from collections import OrderedDict
from functools import partial
4
from typing import Any, Callable, Dict, List, Optional, Tuple
5
6

import torch
7
8
from torch import nn, Tensor

9
from ..ops.misc import Conv2dNormActivation, SqueezeExcitation
10
from ..transforms._presets import ImageClassification, InterpolationMode
11
from ..utils import _log_api_usage_once
12
from ._api import register_model, Weights, WeightsEnum
13
from ._meta import _IMAGENET_CATEGORIES
14
from ._utils import _make_divisible, _ovewrite_named_param, handle_legacy_interface
15
16


17
18
__all__ = [
    "RegNet",
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    "RegNet_Y_400MF_Weights",
    "RegNet_Y_800MF_Weights",
    "RegNet_Y_1_6GF_Weights",
    "RegNet_Y_3_2GF_Weights",
    "RegNet_Y_8GF_Weights",
    "RegNet_Y_16GF_Weights",
    "RegNet_Y_32GF_Weights",
    "RegNet_Y_128GF_Weights",
    "RegNet_X_400MF_Weights",
    "RegNet_X_800MF_Weights",
    "RegNet_X_1_6GF_Weights",
    "RegNet_X_3_2GF_Weights",
    "RegNet_X_8GF_Weights",
    "RegNet_X_16GF_Weights",
    "RegNet_X_32GF_Weights",
34
35
36
37
38
39
40
    "regnet_y_400mf",
    "regnet_y_800mf",
    "regnet_y_1_6gf",
    "regnet_y_3_2gf",
    "regnet_y_8gf",
    "regnet_y_16gf",
    "regnet_y_32gf",
41
    "regnet_y_128gf",
42
43
44
45
46
47
48
49
    "regnet_x_400mf",
    "regnet_x_800mf",
    "regnet_x_1_6gf",
    "regnet_x_3_2gf",
    "regnet_x_8gf",
    "regnet_x_16gf",
    "regnet_x_32gf",
]
50
51


52
class SimpleStemIN(Conv2dNormActivation):
53
54
55
56
57
58
59
60
61
    """Simple stem for ImageNet: 3x3, BN, ReLU."""

    def __init__(
        self,
        width_in: int,
        width_out: int,
        norm_layer: Callable[..., nn.Module],
        activation_layer: Callable[..., nn.Module],
    ) -> None:
62
63
64
        super().__init__(
            width_in, width_out, kernel_size=3, stride=2, norm_layer=norm_layer, activation_layer=activation_layer
        )
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84


class BottleneckTransform(nn.Sequential):
    """Bottleneck transformation: 1x1, 3x3 [+SE], 1x1."""

    def __init__(
        self,
        width_in: int,
        width_out: int,
        stride: int,
        norm_layer: Callable[..., nn.Module],
        activation_layer: Callable[..., nn.Module],
        group_width: int,
        bottleneck_multiplier: float,
        se_ratio: Optional[float],
    ) -> None:
        layers: OrderedDict[str, nn.Module] = OrderedDict()
        w_b = int(round(width_out * bottleneck_multiplier))
        g = w_b // group_width

85
        layers["a"] = Conv2dNormActivation(
86
87
            width_in, w_b, kernel_size=1, stride=1, norm_layer=norm_layer, activation_layer=activation_layer
        )
88
        layers["b"] = Conv2dNormActivation(
89
90
            w_b, w_b, kernel_size=3, stride=stride, groups=g, norm_layer=norm_layer, activation_layer=activation_layer
        )
91
92
93
94
95
96
97
98
99
100
101

        if se_ratio:
            # The SE reduction ratio is defined with respect to the
            # beginning of the block
            width_se_out = int(round(se_ratio * width_in))
            layers["se"] = SqueezeExcitation(
                input_channels=w_b,
                squeeze_channels=width_se_out,
                activation=activation_layer,
            )

102
        layers["c"] = Conv2dNormActivation(
103
104
            w_b, width_out, kernel_size=1, stride=1, norm_layer=norm_layer, activation_layer=None
        )
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
        super().__init__(layers)


class ResBottleneckBlock(nn.Module):
    """Residual bottleneck block: x + F(x), F = bottleneck transform."""

    def __init__(
        self,
        width_in: int,
        width_out: int,
        stride: int,
        norm_layer: Callable[..., nn.Module],
        activation_layer: Callable[..., nn.Module],
        group_width: int = 1,
        bottleneck_multiplier: float = 1.0,
        se_ratio: Optional[float] = None,
    ) -> None:
        super().__init__()

        # Use skip connection with projection if shape changes
        self.proj = None
        should_proj = (width_in != width_out) or (stride != 1)
        if should_proj:
128
            self.proj = Conv2dNormActivation(
129
130
                width_in, width_out, kernel_size=1, stride=stride, norm_layer=norm_layer, activation_layer=None
            )
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
        self.f = BottleneckTransform(
            width_in,
            width_out,
            stride,
            norm_layer,
            activation_layer,
            group_width,
            bottleneck_multiplier,
            se_ratio,
        )
        self.activation = activation_layer(inplace=True)

    def forward(self, x: Tensor) -> Tensor:
        if self.proj is not None:
            x = self.proj(x) + self.f(x)
        else:
            x = x + self.f(x)
        return self.activation(x)


class AnyStage(nn.Sequential):
    """AnyNet stage (sequence of blocks w/ the same output shape)."""

    def __init__(
        self,
        width_in: int,
        width_out: int,
        stride: int,
        depth: int,
        block_constructor: Callable[..., nn.Module],
        norm_layer: Callable[..., nn.Module],
        activation_layer: Callable[..., nn.Module],
        group_width: int,
        bottleneck_multiplier: float,
        se_ratio: Optional[float] = None,
        stage_index: int = 0,
    ) -> None:
        super().__init__()

        for i in range(depth):
            block = block_constructor(
                width_in if i == 0 else width_out,
                width_out,
                stride if i == 0 else 1,
                norm_layer,
                activation_layer,
                group_width,
                bottleneck_multiplier,
                se_ratio,
            )

            self.add_module(f"block{stage_index}-{i}", block)


class BlockParams:
    def __init__(
        self,
        depths: List[int],
        widths: List[int],
        group_widths: List[int],
        bottleneck_multipliers: List[float],
        strides: List[int],
        se_ratio: Optional[float] = None,
    ) -> None:
        self.depths = depths
        self.widths = widths
        self.group_widths = group_widths
        self.bottleneck_multipliers = bottleneck_multipliers
        self.strides = strides
        self.se_ratio = se_ratio

    @classmethod
    def from_init_params(
        cls,
        depth: int,
        w_0: int,
        w_a: float,
        w_m: float,
        group_width: int,
        bottleneck_multiplier: float = 1.0,
        se_ratio: Optional[float] = None,
        **kwargs: Any,
    ) -> "BlockParams":
        """
215
        Programmatically compute all the per-block settings,
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
        given the RegNet parameters.

        The first step is to compute the quantized linear block parameters,
        in log space. Key parameters are:
        - `w_a` is the width progression slope
        - `w_0` is the initial width
        - `w_m` is the width stepping in the log space

        In other terms
        `log(block_width) = log(w_0) + w_m * block_capacity`,
        with `bock_capacity` ramping up following the w_0 and w_a params.
        This block width is finally quantized to multiples of 8.

        The second step is to compute the parameters per stage,
        taking into account the skip connection and the final 1x1 convolutions.
        We use the fact that the output width is constant within a stage.
        """

        QUANT = 8
        STRIDE = 2

        if w_a < 0 or w_0 <= 0 or w_m <= 1 or w_0 % 8 != 0:
            raise ValueError("Invalid RegNet settings")
        # Compute the block widths. Each stage has one unique block width
        widths_cont = torch.arange(depth) * w_a + w_0
        block_capacity = torch.round(torch.log(widths_cont / w_0) / math.log(w_m))
242
        block_widths = (torch.round(torch.divide(w_0 * torch.pow(w_m, block_capacity), QUANT)) * QUANT).int().tolist()
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
        num_stages = len(set(block_widths))

        # Convert to per stage parameters
        split_helper = zip(
            block_widths + [0],
            [0] + block_widths,
            block_widths + [0],
            [0] + block_widths,
        )
        splits = [w != wp or r != rp for w, wp, r, rp in split_helper]

        stage_widths = [w for w, t in zip(block_widths, splits[:-1]) if t]
        stage_depths = torch.diff(torch.tensor([d for d, t in enumerate(splits) if t])).int().tolist()

        strides = [STRIDE] * num_stages
        bottleneck_multipliers = [bottleneck_multiplier] * num_stages
        group_widths = [group_width] * num_stages

        # Adjust the compatibility of stage widths and group widths
        stage_widths, group_widths = cls._adjust_widths_groups_compatibilty(
            stage_widths, bottleneck_multipliers, group_widths
        )

        return cls(
            depths=stage_depths,
            widths=stage_widths,
            group_widths=group_widths,
            bottleneck_multipliers=bottleneck_multipliers,
            strides=strides,
            se_ratio=se_ratio,
        )

    def _get_expanded_params(self):
276
        return zip(self.widths, self.strides, self.depths, self.group_widths, self.bottleneck_multipliers)
277
278
279

    @staticmethod
    def _adjust_widths_groups_compatibilty(
280
281
        stage_widths: List[int], bottleneck_ratios: List[float], group_widths: List[int]
    ) -> Tuple[List[int], List[int]]:
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
        """
        Adjusts the compatibility of widths and groups,
        depending on the bottleneck ratio.
        """
        # Compute all widths for the current settings
        widths = [int(w * b) for w, b in zip(stage_widths, bottleneck_ratios)]
        group_widths_min = [min(g, w_bot) for g, w_bot in zip(group_widths, widths)]

        # Compute the adjusted widths so that stage and group widths fit
        ws_bot = [_make_divisible(w_bot, g) for w_bot, g in zip(widths, group_widths_min)]
        stage_widths = [int(w_bot / b) for w_bot, b in zip(ws_bot, bottleneck_ratios)]
        return stage_widths, group_widths_min


class RegNet(nn.Module):
    def __init__(
        self,
        block_params: BlockParams,
        num_classes: int = 1000,
        stem_width: int = 32,
        stem_type: Optional[Callable[..., nn.Module]] = None,
        block_type: Optional[Callable[..., nn.Module]] = None,
        norm_layer: Optional[Callable[..., nn.Module]] = None,
        activation: Optional[Callable[..., nn.Module]] = None,
    ) -> None:
        super().__init__()
Kai Zhang's avatar
Kai Zhang committed
308
        _log_api_usage_once(self)
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

        if stem_type is None:
            stem_type = SimpleStemIN
        if norm_layer is None:
            norm_layer = nn.BatchNorm2d
        if block_type is None:
            block_type = ResBottleneckBlock
        if activation is None:
            activation = nn.ReLU

        # Ad hoc stem
        self.stem = stem_type(
            3,  # width_in
            stem_width,
            norm_layer,
            activation,
        )

        current_width = stem_width

        blocks = []
        for i, (
            width_out,
            stride,
            depth,
            group_width,
            bottleneck_multiplier,
        ) in enumerate(block_params._get_expanded_params()):
            blocks.append(
                (
                    f"block{i+1}",
                    AnyStage(
                        current_width,
                        width_out,
                        stride,
                        depth,
                        block_type,
                        norm_layer,
                        activation,
                        group_width,
                        bottleneck_multiplier,
                        block_params.se_ratio,
                        stage_index=i + 1,
                    ),
                )
            )

            current_width = width_out

        self.trunk_output = nn.Sequential(OrderedDict(blocks))

        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
        self.fc = nn.Linear(in_features=current_width, out_features=num_classes)

        # Performs ResNet-style weight initialization
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                # Note that there is no bias due to BN
                fan_out = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
                nn.init.normal_(m.weight, mean=0.0, std=math.sqrt(2.0 / fan_out))
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.ones_(m.weight)
                nn.init.zeros_(m.bias)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, mean=0.0, std=0.01)
                nn.init.zeros_(m.bias)

376
377
378
379
380
381
382
383
384
385
    def forward(self, x: Tensor) -> Tensor:
        x = self.stem(x)
        x = self.trunk_output(x)

        x = self.avgpool(x)
        x = x.flatten(start_dim=1)
        x = self.fc(x)

        return x

386

387
388
389
390
391
392
393
394
395
def _regnet(
    block_params: BlockParams,
    weights: Optional[WeightsEnum],
    progress: bool,
    **kwargs: Any,
) -> RegNet:
    if weights is not None:
        _ovewrite_named_param(kwargs, "num_classes", len(weights.meta["categories"]))

396
397
    norm_layer = kwargs.pop("norm_layer", partial(nn.BatchNorm2d, eps=1e-05, momentum=0.1))
    model = RegNet(block_params, norm_layer=norm_layer, **kwargs)
398
399

    if weights is not None:
400
        model.load_state_dict(weights.get_state_dict(progress=progress, check_hash=True))
401

402
403
404
    return model


405
_COMMON_META: Dict[str, Any] = {
406
407
408
409
    "min_size": (1, 1),
    "categories": _IMAGENET_CATEGORIES,
}

410
411
412
413
414
415
_COMMON_SWAG_META = {
    **_COMMON_META,
    "recipe": "https://github.com/facebookresearch/SWAG",
    "license": "https://github.com/facebookresearch/SWAG/blob/main/LICENSE",
}

416
417
418
419
420
421
422
423
424

class RegNet_Y_400MF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_400mf-c65dace8.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 4344144,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#small-models",
425
426
427
428
429
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 74.046,
                    "acc@5": 91.716,
                }
430
            },
431
            "_ops": 0.402,
Nicolas Hug's avatar
Nicolas Hug committed
432
            "_file_size": 16.806,
433
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
434
435
436
437
438
439
440
441
442
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_y_400mf-e6988f5f.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 4344144,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
443
444
445
446
447
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 75.804,
                    "acc@5": 92.742,
                }
448
            },
449
            "_ops": 0.402,
Nicolas Hug's avatar
Nicolas Hug committed
450
            "_file_size": 16.806,
451
452
453
454
455
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
456
457
458
459
460
461
462
463
464
465
466
467
468
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_Y_800MF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_800mf-1b27b58c.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 6432512,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#small-models",
469
470
471
472
473
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 76.420,
                    "acc@5": 93.136,
                }
474
            },
475
            "_ops": 0.834,
Nicolas Hug's avatar
Nicolas Hug committed
476
            "_file_size": 24.774,
477
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
478
479
480
481
482
483
484
485
486
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_y_800mf-58fc7688.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 6432512,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
487
488
489
490
491
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 78.828,
                    "acc@5": 94.502,
                }
492
            },
493
            "_ops": 0.834,
Nicolas Hug's avatar
Nicolas Hug committed
494
            "_file_size": 24.774,
495
496
497
498
499
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
500
501
502
503
504
505
506
507
508
509
510
511
512
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_Y_1_6GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_1_6gf-b11a554e.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 11202430,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#small-models",
513
514
515
516
517
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 77.950,
                    "acc@5": 93.966,
                }
518
            },
519
            "_ops": 1.612,
Nicolas Hug's avatar
Nicolas Hug committed
520
            "_file_size": 43.152,
521
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
522
523
524
525
526
527
528
529
530
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_y_1_6gf-0d7bc02a.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 11202430,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
531
532
533
534
535
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 80.876,
                    "acc@5": 95.444,
                }
536
            },
537
            "_ops": 1.612,
Nicolas Hug's avatar
Nicolas Hug committed
538
            "_file_size": 43.152,
539
540
541
542
543
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
544
545
546
547
548
549
550
551
552
553
554
555
556
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_Y_3_2GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_3_2gf-b5a9779c.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 19436338,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#medium-models",
557
558
559
560
561
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 78.948,
                    "acc@5": 94.576,
                }
562
            },
563
            "_ops": 3.176,
Nicolas Hug's avatar
Nicolas Hug committed
564
            "_file_size": 74.567,
565
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
566
567
568
569
570
571
572
573
574
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_y_3_2gf-9180c971.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 19436338,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
575
576
577
578
579
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 81.982,
                    "acc@5": 95.972,
                }
580
            },
581
            "_ops": 3.176,
Nicolas Hug's avatar
Nicolas Hug committed
582
            "_file_size": 74.567,
583
584
585
586
587
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
588
589
590
591
592
593
594
595
596
597
598
599
600
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_Y_8GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_8gf-d0d0e4a8.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 39381472,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#medium-models",
601
602
603
604
605
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 80.032,
                    "acc@5": 95.048,
                }
606
            },
607
            "_ops": 8.473,
Nicolas Hug's avatar
Nicolas Hug committed
608
            "_file_size": 150.701,
609
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
610
611
612
613
614
615
616
617
618
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_y_8gf-dc2b1b54.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 39381472,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
619
620
621
622
623
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 82.828,
                    "acc@5": 96.330,
                }
624
            },
625
            "_ops": 8.473,
Nicolas Hug's avatar
Nicolas Hug committed
626
            "_file_size": 150.701,
627
628
629
630
631
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
632
633
634
635
636
637
638
639
640
641
642
643
644
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_Y_16GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_16gf-9e6ed7dd.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 83590140,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#large-models",
645
646
647
648
649
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 80.424,
                    "acc@5": 95.240,
                }
650
            },
651
            "_ops": 15.912,
Nicolas Hug's avatar
Nicolas Hug committed
652
            "_file_size": 319.49,
653
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
654
655
656
657
658
659
660
661
662
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_y_16gf-3e4a00f9.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 83590140,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
663
664
665
666
667
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 82.886,
                    "acc@5": 96.328,
                }
668
            },
669
            "_ops": 15.912,
Nicolas Hug's avatar
Nicolas Hug committed
670
            "_file_size": 319.49,
671
672
673
674
675
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
676
677
        },
    )
678
    IMAGENET1K_SWAG_E2E_V1 = Weights(
679
680
681
682
683
684
685
        url="https://download.pytorch.org/models/regnet_y_16gf_swag-43afe44d.pth",
        transforms=partial(
            ImageClassification, crop_size=384, resize_size=384, interpolation=InterpolationMode.BICUBIC
        ),
        meta={
            **_COMMON_SWAG_META,
            "num_params": 83590140,
686
687
688
689
690
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 86.012,
                    "acc@5": 98.054,
                }
691
            },
692
            "_ops": 46.735,
Nicolas Hug's avatar
Nicolas Hug committed
693
            "_file_size": 319.49,
694
695
696
697
            "_docs": """
                These weights are learnt via transfer learning by end-to-end fine-tuning the original
                `SWAG <https://arxiv.org/abs/2201.08371>`_ weights on ImageNet-1K data.
            """,
698
699
        },
    )
700
701
702
703
704
705
706
707
708
    IMAGENET1K_SWAG_LINEAR_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_16gf_lc_swag-f3ec0043.pth",
        transforms=partial(
            ImageClassification, crop_size=224, resize_size=224, interpolation=InterpolationMode.BICUBIC
        ),
        meta={
            **_COMMON_SWAG_META,
            "recipe": "https://github.com/pytorch/vision/pull/5793",
            "num_params": 83590140,
709
710
711
712
713
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 83.976,
                    "acc@5": 97.244,
                }
714
            },
715
            "_ops": 15.912,
Nicolas Hug's avatar
Nicolas Hug committed
716
            "_file_size": 319.49,
717
718
719
720
            "_docs": """
                These weights are composed of the original frozen `SWAG <https://arxiv.org/abs/2201.08371>`_ trunk
                weights and a linear classifier learnt on top of them trained on ImageNet-1K data.
            """,
721
722
        },
    )
723
724
725
726
727
728
729
730
731
732
733
    DEFAULT = IMAGENET1K_V2


class RegNet_Y_32GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_32gf-4dee3f7a.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 145046770,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#large-models",
734
735
736
737
738
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 80.878,
                    "acc@5": 95.340,
                }
739
            },
740
            "_ops": 32.28,
Nicolas Hug's avatar
Nicolas Hug committed
741
            "_file_size": 554.076,
742
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
743
744
745
746
747
748
749
750
751
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_y_32gf-8db6d4b5.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 145046770,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
752
753
754
755
756
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 83.368,
                    "acc@5": 96.498,
                }
757
            },
758
            "_ops": 32.28,
Nicolas Hug's avatar
Nicolas Hug committed
759
            "_file_size": 554.076,
760
761
762
763
764
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
765
766
        },
    )
767
    IMAGENET1K_SWAG_E2E_V1 = Weights(
768
769
770
771
772
773
774
        url="https://download.pytorch.org/models/regnet_y_32gf_swag-04fdfa75.pth",
        transforms=partial(
            ImageClassification, crop_size=384, resize_size=384, interpolation=InterpolationMode.BICUBIC
        ),
        meta={
            **_COMMON_SWAG_META,
            "num_params": 145046770,
775
776
777
778
779
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 86.838,
                    "acc@5": 98.362,
                }
780
            },
781
            "_ops": 94.826,
Nicolas Hug's avatar
Nicolas Hug committed
782
            "_file_size": 554.076,
783
784
785
786
            "_docs": """
                These weights are learnt via transfer learning by end-to-end fine-tuning the original
                `SWAG <https://arxiv.org/abs/2201.08371>`_ weights on ImageNet-1K data.
            """,
787
788
        },
    )
789
790
791
792
793
794
795
796
797
    IMAGENET1K_SWAG_LINEAR_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_32gf_lc_swag-e1583746.pth",
        transforms=partial(
            ImageClassification, crop_size=224, resize_size=224, interpolation=InterpolationMode.BICUBIC
        ),
        meta={
            **_COMMON_SWAG_META,
            "recipe": "https://github.com/pytorch/vision/pull/5793",
            "num_params": 145046770,
798
799
800
801
802
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 84.622,
                    "acc@5": 97.480,
                }
803
            },
804
            "_ops": 32.28,
Nicolas Hug's avatar
Nicolas Hug committed
805
            "_file_size": 554.076,
806
807
808
809
            "_docs": """
                These weights are composed of the original frozen `SWAG <https://arxiv.org/abs/2201.08371>`_ trunk
                weights and a linear classifier learnt on top of them trained on ImageNet-1K data.
            """,
810
811
        },
    )
812
813
814
815
    DEFAULT = IMAGENET1K_V2


class RegNet_Y_128GF_Weights(WeightsEnum):
816
    IMAGENET1K_SWAG_E2E_V1 = Weights(
817
818
819
820
821
822
823
        url="https://download.pytorch.org/models/regnet_y_128gf_swag-c8ce3e52.pth",
        transforms=partial(
            ImageClassification, crop_size=384, resize_size=384, interpolation=InterpolationMode.BICUBIC
        ),
        meta={
            **_COMMON_SWAG_META,
            "num_params": 644812894,
824
825
826
827
828
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 88.228,
                    "acc@5": 98.682,
                }
829
            },
830
            "_ops": 374.57,
Nicolas Hug's avatar
Nicolas Hug committed
831
            "_file_size": 2461.564,
832
833
834
835
            "_docs": """
                These weights are learnt via transfer learning by end-to-end fine-tuning the original
                `SWAG <https://arxiv.org/abs/2201.08371>`_ weights on ImageNet-1K data.
            """,
836
837
        },
    )
838
839
840
841
842
843
844
845
846
    IMAGENET1K_SWAG_LINEAR_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_y_128gf_lc_swag-cbe8ce12.pth",
        transforms=partial(
            ImageClassification, crop_size=224, resize_size=224, interpolation=InterpolationMode.BICUBIC
        ),
        meta={
            **_COMMON_SWAG_META,
            "recipe": "https://github.com/pytorch/vision/pull/5793",
            "num_params": 644812894,
847
848
849
850
851
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 86.068,
                    "acc@5": 97.844,
                }
852
            },
853
            "_ops": 127.518,
Nicolas Hug's avatar
Nicolas Hug committed
854
            "_file_size": 2461.564,
855
856
857
858
            "_docs": """
                These weights are composed of the original frozen `SWAG <https://arxiv.org/abs/2201.08371>`_ trunk
                weights and a linear classifier learnt on top of them trained on ImageNet-1K data.
            """,
859
860
861
        },
    )
    DEFAULT = IMAGENET1K_SWAG_E2E_V1
862
863
864
865
866
867
868
869
870
871


class RegNet_X_400MF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_x_400mf-adf1edd5.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 5495976,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#small-models",
872
873
874
875
876
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 72.834,
                    "acc@5": 90.950,
                }
877
            },
878
            "_ops": 0.414,
Nicolas Hug's avatar
Nicolas Hug committed
879
            "_file_size": 21.258,
880
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
881
882
883
884
885
886
887
888
889
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_x_400mf-62229a5f.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 5495976,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe-with-fixres",
890
891
892
893
894
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 74.864,
                    "acc@5": 92.322,
                }
895
            },
896
            "_ops": 0.414,
Nicolas Hug's avatar
Nicolas Hug committed
897
            "_file_size": 21.257,
898
899
900
901
902
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
903
904
905
906
907
908
909
910
911
912
913
914
915
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_X_800MF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_x_800mf-ad17e45c.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 7259656,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#small-models",
916
917
918
919
920
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 75.212,
                    "acc@5": 92.348,
                }
921
            },
922
            "_ops": 0.8,
Nicolas Hug's avatar
Nicolas Hug committed
923
            "_file_size": 27.945,
924
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
925
926
927
928
929
930
931
932
933
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_x_800mf-94a99ebd.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 7259656,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe-with-fixres",
934
935
936
937
938
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 77.522,
                    "acc@5": 93.826,
                }
939
            },
940
            "_ops": 0.8,
Nicolas Hug's avatar
Nicolas Hug committed
941
            "_file_size": 27.945,
942
943
944
945
946
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
947
948
949
950
951
952
953
954
955
956
957
958
959
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_X_1_6GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_x_1_6gf-e3633e7f.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 9190136,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#small-models",
960
961
962
963
964
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 77.040,
                    "acc@5": 93.440,
                }
965
            },
966
            "_ops": 1.603,
Nicolas Hug's avatar
Nicolas Hug committed
967
            "_file_size": 35.339,
968
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
969
970
971
972
973
974
975
976
977
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_x_1_6gf-a12f2b72.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 9190136,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe-with-fixres",
978
979
980
981
982
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 79.668,
                    "acc@5": 94.922,
                }
983
            },
984
            "_ops": 1.603,
Nicolas Hug's avatar
Nicolas Hug committed
985
            "_file_size": 35.339,
986
987
988
989
990
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_X_3_2GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_x_3_2gf-f342aeae.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 15296552,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#medium-models",
1004
1005
1006
1007
1008
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 78.364,
                    "acc@5": 93.992,
                }
1009
            },
1010
            "_ops": 3.177,
Nicolas Hug's avatar
Nicolas Hug committed
1011
            "_file_size": 58.756,
1012
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
1013
1014
1015
1016
1017
1018
1019
1020
1021
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_x_3_2gf-7071aa85.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 15296552,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
1022
1023
1024
1025
1026
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 81.196,
                    "acc@5": 95.430,
                }
1027
            },
1028
            "_ops": 3.177,
Nicolas Hug's avatar
Nicolas Hug committed
1029
            "_file_size": 58.756,
1030
1031
1032
1033
1034
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_X_8GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_x_8gf-03ceed89.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 39572648,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#medium-models",
1048
1049
1050
1051
1052
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 79.344,
                    "acc@5": 94.686,
                }
1053
            },
1054
            "_ops": 7.995,
Nicolas Hug's avatar
Nicolas Hug committed
1055
            "_file_size": 151.456,
1056
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
1057
1058
1059
1060
1061
1062
1063
1064
1065
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_x_8gf-2b70d774.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 39572648,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
1066
1067
1068
1069
1070
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 81.682,
                    "acc@5": 95.678,
                }
1071
            },
1072
            "_ops": 7.995,
Nicolas Hug's avatar
Nicolas Hug committed
1073
            "_file_size": 151.456,
1074
1075
1076
1077
1078
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_X_16GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_x_16gf-2007eb11.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 54278536,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#medium-models",
1092
1093
1094
1095
1096
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 80.058,
                    "acc@5": 94.944,
                }
1097
            },
1098
            "_ops": 15.941,
Nicolas Hug's avatar
Nicolas Hug committed
1099
            "_file_size": 207.627,
1100
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
1101
1102
1103
1104
1105
1106
1107
1108
1109
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_x_16gf-ba3796d7.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 54278536,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
1110
1111
1112
1113
1114
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 82.716,
                    "acc@5": 96.196,
                }
1115
            },
1116
            "_ops": 15.941,
Nicolas Hug's avatar
Nicolas Hug committed
1117
            "_file_size": 207.627,
1118
1119
1120
1121
1122
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
        },
    )
    DEFAULT = IMAGENET1K_V2


class RegNet_X_32GF_Weights(WeightsEnum):
    IMAGENET1K_V1 = Weights(
        url="https://download.pytorch.org/models/regnet_x_32gf-9d47f8d0.pth",
        transforms=partial(ImageClassification, crop_size=224),
        meta={
            **_COMMON_META,
            "num_params": 107811560,
            "recipe": "https://github.com/pytorch/vision/tree/main/references/classification#large-models",
1136
1137
1138
1139
1140
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 80.622,
                    "acc@5": 95.248,
                }
1141
            },
1142
            "_ops": 31.736,
Nicolas Hug's avatar
Nicolas Hug committed
1143
            "_file_size": 412.039,
1144
            "_docs": """These weights reproduce closely the results of the paper using a simple training recipe.""",
1145
1146
1147
1148
1149
1150
1151
1152
1153
        },
    )
    IMAGENET1K_V2 = Weights(
        url="https://download.pytorch.org/models/regnet_x_32gf-6eb8fdc6.pth",
        transforms=partial(ImageClassification, crop_size=224, resize_size=232),
        meta={
            **_COMMON_META,
            "num_params": 107811560,
            "recipe": "https://github.com/pytorch/vision/issues/3995#new-recipe",
1154
1155
1156
1157
1158
            "_metrics": {
                "ImageNet-1K": {
                    "acc@1": 83.014,
                    "acc@5": 96.288,
                }
1159
            },
1160
            "_ops": 31.736,
Nicolas Hug's avatar
Nicolas Hug committed
1161
            "_file_size": 412.039,
1162
1163
1164
1165
1166
            "_docs": """
                These weights improve upon the results of the original paper by using a modified version of TorchVision's
                `new training recipe
                <https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/>`_.
            """,
1167
1168
1169
1170
1171
        },
    )
    DEFAULT = IMAGENET1K_V2


1172
@register_model()
1173
1174
@handle_legacy_interface(weights=("pretrained", RegNet_Y_400MF_Weights.IMAGENET1K_V1))
def regnet_y_400mf(*, weights: Optional[RegNet_Y_400MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1175
1176
    """
    Constructs a RegNetY_400MF architecture from
1177
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1178
1179

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1180
1181
        weights (:class:`~torchvision.models.RegNet_Y_400MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_400MF_Weights` below for more details and possible values.
1182
1183
1184
1185
1186
1187
1188
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1189
    .. autoclass:: torchvision.models.RegNet_Y_400MF_Weights
1190
        :members:
1191
    """
1192
1193
    weights = RegNet_Y_400MF_Weights.verify(weights)

1194
    params = BlockParams.from_init_params(depth=16, w_0=48, w_a=27.89, w_m=2.09, group_width=8, se_ratio=0.25, **kwargs)
1195
    return _regnet(params, weights, progress, **kwargs)
1196
1197


1198
@register_model()
1199
1200
@handle_legacy_interface(weights=("pretrained", RegNet_Y_800MF_Weights.IMAGENET1K_V1))
def regnet_y_800mf(*, weights: Optional[RegNet_Y_800MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1201
1202
    """
    Constructs a RegNetY_800MF architecture from
1203
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1204
1205

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1206
1207
        weights (:class:`~torchvision.models.RegNet_Y_800MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_800MF_Weights` below for more details and possible values.
1208
1209
1210
1211
1212
1213
1214
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1215
    .. autoclass:: torchvision.models.RegNet_Y_800MF_Weights
1216
        :members:
1217
    """
1218
1219
    weights = RegNet_Y_800MF_Weights.verify(weights)

1220
    params = BlockParams.from_init_params(depth=14, w_0=56, w_a=38.84, w_m=2.4, group_width=16, se_ratio=0.25, **kwargs)
1221
    return _regnet(params, weights, progress, **kwargs)
1222
1223


1224
@register_model()
1225
1226
@handle_legacy_interface(weights=("pretrained", RegNet_Y_1_6GF_Weights.IMAGENET1K_V1))
def regnet_y_1_6gf(*, weights: Optional[RegNet_Y_1_6GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1227
1228
    """
    Constructs a RegNetY_1.6GF architecture from
1229
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1230
1231

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1232
1233
        weights (:class:`~torchvision.models.RegNet_Y_1_6GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_1_6GF_Weights` below for more details and possible values.
1234
1235
1236
1237
1238
1239
1240
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1241
    .. autoclass:: torchvision.models.RegNet_Y_1_6GF_Weights
1242
        :members:
1243
    """
1244
1245
    weights = RegNet_Y_1_6GF_Weights.verify(weights)

1246
1247
1248
    params = BlockParams.from_init_params(
        depth=27, w_0=48, w_a=20.71, w_m=2.65, group_width=24, se_ratio=0.25, **kwargs
    )
1249
    return _regnet(params, weights, progress, **kwargs)
1250
1251


1252
@register_model()
1253
1254
@handle_legacy_interface(weights=("pretrained", RegNet_Y_3_2GF_Weights.IMAGENET1K_V1))
def regnet_y_3_2gf(*, weights: Optional[RegNet_Y_3_2GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1255
1256
    """
    Constructs a RegNetY_3.2GF architecture from
1257
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1258
1259

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1260
1261
        weights (:class:`~torchvision.models.RegNet_Y_3_2GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_3_2GF_Weights` below for more details and possible values.
1262
1263
1264
1265
1266
1267
1268
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1269
    .. autoclass:: torchvision.models.RegNet_Y_3_2GF_Weights
1270
        :members:
1271
    """
1272
1273
    weights = RegNet_Y_3_2GF_Weights.verify(weights)

1274
1275
1276
    params = BlockParams.from_init_params(
        depth=21, w_0=80, w_a=42.63, w_m=2.66, group_width=24, se_ratio=0.25, **kwargs
    )
1277
    return _regnet(params, weights, progress, **kwargs)
1278
1279


1280
@register_model()
1281
1282
@handle_legacy_interface(weights=("pretrained", RegNet_Y_8GF_Weights.IMAGENET1K_V1))
def regnet_y_8gf(*, weights: Optional[RegNet_Y_8GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1283
1284
    """
    Constructs a RegNetY_8GF architecture from
1285
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1286
1287

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1288
1289
        weights (:class:`~torchvision.models.RegNet_Y_8GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_8GF_Weights` below for more details and possible values.
1290
1291
1292
1293
1294
1295
1296
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1297
    .. autoclass:: torchvision.models.RegNet_Y_8GF_Weights
1298
        :members:
1299
    """
1300
1301
    weights = RegNet_Y_8GF_Weights.verify(weights)

1302
1303
1304
    params = BlockParams.from_init_params(
        depth=17, w_0=192, w_a=76.82, w_m=2.19, group_width=56, se_ratio=0.25, **kwargs
    )
1305
    return _regnet(params, weights, progress, **kwargs)
1306
1307


1308
@register_model()
1309
1310
@handle_legacy_interface(weights=("pretrained", RegNet_Y_16GF_Weights.IMAGENET1K_V1))
def regnet_y_16gf(*, weights: Optional[RegNet_Y_16GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1311
1312
    """
    Constructs a RegNetY_16GF architecture from
1313
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1314
1315

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1316
1317
        weights (:class:`~torchvision.models.RegNet_Y_16GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_16GF_Weights` below for more details and possible values.
1318
1319
1320
1321
1322
1323
1324
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1325
    .. autoclass:: torchvision.models.RegNet_Y_16GF_Weights
1326
        :members:
1327
    """
1328
1329
    weights = RegNet_Y_16GF_Weights.verify(weights)

1330
1331
1332
    params = BlockParams.from_init_params(
        depth=18, w_0=200, w_a=106.23, w_m=2.48, group_width=112, se_ratio=0.25, **kwargs
    )
1333
    return _regnet(params, weights, progress, **kwargs)
1334
1335


1336
@register_model()
1337
1338
@handle_legacy_interface(weights=("pretrained", RegNet_Y_32GF_Weights.IMAGENET1K_V1))
def regnet_y_32gf(*, weights: Optional[RegNet_Y_32GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1339
1340
    """
    Constructs a RegNetY_32GF architecture from
1341
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1342
1343

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1344
1345
        weights (:class:`~torchvision.models.RegNet_Y_32GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_32GF_Weights` below for more details and possible values.
1346
1347
1348
1349
1350
1351
1352
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1353
    .. autoclass:: torchvision.models.RegNet_Y_32GF_Weights
1354
        :members:
1355
    """
1356
1357
    weights = RegNet_Y_32GF_Weights.verify(weights)

1358
1359
1360
    params = BlockParams.from_init_params(
        depth=20, w_0=232, w_a=115.89, w_m=2.53, group_width=232, se_ratio=0.25, **kwargs
    )
1361
    return _regnet(params, weights, progress, **kwargs)
1362
1363


1364
@register_model()
1365
1366
@handle_legacy_interface(weights=("pretrained", None))
def regnet_y_128gf(*, weights: Optional[RegNet_Y_128GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1367
1368
    """
    Constructs a RegNetY_128GF architecture from
1369
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1370
1371

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1372
1373
        weights (:class:`~torchvision.models.RegNet_Y_128GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_Y_128GF_Weights` below for more details and possible values.
1374
1375
1376
1377
1378
1379
1380
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1381
    .. autoclass:: torchvision.models.RegNet_Y_128GF_Weights
1382
        :members:
1383
    """
1384
1385
    weights = RegNet_Y_128GF_Weights.verify(weights)

1386
1387
1388
    params = BlockParams.from_init_params(
        depth=27, w_0=456, w_a=160.83, w_m=2.52, group_width=264, se_ratio=0.25, **kwargs
    )
1389
    return _regnet(params, weights, progress, **kwargs)
1390
1391


1392
@register_model()
1393
1394
@handle_legacy_interface(weights=("pretrained", RegNet_X_400MF_Weights.IMAGENET1K_V1))
def regnet_x_400mf(*, weights: Optional[RegNet_X_400MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1395
1396
    """
    Constructs a RegNetX_400MF architecture from
1397
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1398
1399

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1400
1401
        weights (:class:`~torchvision.models.RegNet_X_400MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_400MF_Weights` below for more details and possible values.
1402
1403
1404
1405
1406
1407
1408
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1409
    .. autoclass:: torchvision.models.RegNet_X_400MF_Weights
1410
        :members:
1411
    """
1412
1413
    weights = RegNet_X_400MF_Weights.verify(weights)

1414
    params = BlockParams.from_init_params(depth=22, w_0=24, w_a=24.48, w_m=2.54, group_width=16, **kwargs)
1415
    return _regnet(params, weights, progress, **kwargs)
1416
1417


1418
@register_model()
1419
1420
@handle_legacy_interface(weights=("pretrained", RegNet_X_800MF_Weights.IMAGENET1K_V1))
def regnet_x_800mf(*, weights: Optional[RegNet_X_800MF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1421
1422
    """
    Constructs a RegNetX_800MF architecture from
1423
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.
1424
1425

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1426
1427
        weights (:class:`~torchvision.models.RegNet_X_800MF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_800MF_Weights` below for more details and possible values.
1428
1429
1430
1431
1432
1433
1434
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1435
    .. autoclass:: torchvision.models.RegNet_X_800MF_Weights
1436
        :members:
1437
    """
1438
1439
    weights = RegNet_X_800MF_Weights.verify(weights)

1440
    params = BlockParams.from_init_params(depth=16, w_0=56, w_a=35.73, w_m=2.28, group_width=16, **kwargs)
1441
    return _regnet(params, weights, progress, **kwargs)
1442
1443


1444
@register_model()
1445
1446
@handle_legacy_interface(weights=("pretrained", RegNet_X_1_6GF_Weights.IMAGENET1K_V1))
def regnet_x_1_6gf(*, weights: Optional[RegNet_X_1_6GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1447
1448
    """
    Constructs a RegNetX_1.6GF architecture from
1449
1450
1451
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1452
1453
        weights (:class:`~torchvision.models.RegNet_X_1_6GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_1_6GF_Weights` below for more details and possible values.
1454
1455
1456
1457
1458
1459
1460
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1461
    .. autoclass:: torchvision.models.RegNet_X_1_6GF_Weights
1462
        :members:
1463
    """
1464
1465
    weights = RegNet_X_1_6GF_Weights.verify(weights)

1466
    params = BlockParams.from_init_params(depth=18, w_0=80, w_a=34.01, w_m=2.25, group_width=24, **kwargs)
1467
    return _regnet(params, weights, progress, **kwargs)
1468
1469


1470
@register_model()
1471
1472
@handle_legacy_interface(weights=("pretrained", RegNet_X_3_2GF_Weights.IMAGENET1K_V1))
def regnet_x_3_2gf(*, weights: Optional[RegNet_X_3_2GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1473
1474
    """
    Constructs a RegNetX_3.2GF architecture from
1475
1476
1477
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1478
1479
        weights (:class:`~torchvision.models.RegNet_X_3_2GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_3_2GF_Weights` below for more details and possible values.
1480
1481
1482
1483
1484
1485
1486
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1487
    .. autoclass:: torchvision.models.RegNet_X_3_2GF_Weights
1488
        :members:
1489
    """
1490
1491
    weights = RegNet_X_3_2GF_Weights.verify(weights)

1492
    params = BlockParams.from_init_params(depth=25, w_0=88, w_a=26.31, w_m=2.25, group_width=48, **kwargs)
1493
    return _regnet(params, weights, progress, **kwargs)
1494
1495


1496
@register_model()
1497
1498
@handle_legacy_interface(weights=("pretrained", RegNet_X_8GF_Weights.IMAGENET1K_V1))
def regnet_x_8gf(*, weights: Optional[RegNet_X_8GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1499
1500
    """
    Constructs a RegNetX_8GF architecture from
1501
1502
1503
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1504
1505
        weights (:class:`~torchvision.models.RegNet_X_8GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_8GF_Weights` below for more details and possible values.
1506
1507
1508
1509
1510
1511
1512
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1513
    .. autoclass:: torchvision.models.RegNet_X_8GF_Weights
1514
        :members:
1515
    """
1516
1517
    weights = RegNet_X_8GF_Weights.verify(weights)

1518
    params = BlockParams.from_init_params(depth=23, w_0=80, w_a=49.56, w_m=2.88, group_width=120, **kwargs)
1519
    return _regnet(params, weights, progress, **kwargs)
1520
1521


1522
@register_model()
1523
1524
@handle_legacy_interface(weights=("pretrained", RegNet_X_16GF_Weights.IMAGENET1K_V1))
def regnet_x_16gf(*, weights: Optional[RegNet_X_16GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1525
1526
    """
    Constructs a RegNetX_16GF architecture from
1527
1528
1529
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1530
1531
        weights (:class:`~torchvision.models.RegNet_X_16GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_16GF_Weights` below for more details and possible values.
1532
1533
1534
1535
1536
1537
1538
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1539
    .. autoclass:: torchvision.models.RegNet_X_16GF_Weights
1540
        :members:
1541
    """
1542
1543
    weights = RegNet_X_16GF_Weights.verify(weights)

1544
    params = BlockParams.from_init_params(depth=22, w_0=216, w_a=55.59, w_m=2.1, group_width=128, **kwargs)
1545
    return _regnet(params, weights, progress, **kwargs)
1546
1547


1548
@register_model()
1549
1550
@handle_legacy_interface(weights=("pretrained", RegNet_X_32GF_Weights.IMAGENET1K_V1))
def regnet_x_32gf(*, weights: Optional[RegNet_X_32GF_Weights] = None, progress: bool = True, **kwargs: Any) -> RegNet:
1551
1552
    """
    Constructs a RegNetX_32GF architecture from
1553
1554
1555
    `Designing Network Design Spaces <https://arxiv.org/abs/2003.13678>`_.

    Args:
Nicolas Hug's avatar
Nicolas Hug committed
1556
1557
        weights (:class:`~torchvision.models.RegNet_X_32GF_Weights`, optional): The pretrained weights to use.
            See :class:`~torchvision.models.RegNet_X_32GF_Weights` below for more details and possible values.
1558
1559
1560
1561
1562
1563
1564
            By default, no pretrained weights are used.
        progress (bool, optional): If True, displays a progress bar of the download to stderr. Default is True.
        **kwargs: parameters passed to either ``torchvision.models.regnet.RegNet`` or
            ``torchvision.models.regnet.BlockParams`` class. Please refer to the `source code
            <https://github.com/pytorch/vision/blob/main/torchvision/models/regnet.py>`_
            for more detail about the classes.

Nicolas Hug's avatar
Nicolas Hug committed
1565
    .. autoclass:: torchvision.models.RegNet_X_32GF_Weights
1566
        :members:
1567
    """
1568
    weights = RegNet_X_32GF_Weights.verify(weights)
1569

1570
1571
    params = BlockParams.from_init_params(depth=23, w_0=320, w_a=69.86, w_m=2.0, group_width=168, **kwargs)
    return _regnet(params, weights, progress, **kwargs)