@@ -208,8 +208,7 @@ def __init__(
208
208
# Add it as an option when we need to use this code to train a backbone.
209
209
210
210
def forward (self , x ):
211
- """Forward function of `BottleneckBlock`.
212
- """
211
+ """Forward function of `BottleneckBlock`."""
213
212
out = self .conv1 (x )
214
213
out = F .relu_ (out )
215
214
@@ -230,8 +229,8 @@ def forward(self, x):
230
229
231
230
class DeformBottleneckBlock (CNNBlockBase ):
232
231
"""
233
- Similar to :class:`BottleneckBlock`, but with
234
- paper `Deformable Convolutional Networks
232
+ Similar to :class:`BottleneckBlock`, but with
233
+ paper `Deformable Convolutional Networks
235
234
<https://arxiv.org/pdf/1703.06211.pdf>`_ in the 3x3 convolution.
236
235
"""
237
236
@@ -320,8 +319,7 @@ def __init__(
320
319
nn .init .constant_ (self .conv2_offset .bias , 0 )
321
320
322
321
def forward (self , x ):
323
- """Forward function of `DeformBottleneckBlock`.
324
- """
322
+ """Forward function of `DeformBottleneckBlock`."""
325
323
out = self .conv1 (x )
326
324
out = F .relu_ (out )
327
325
@@ -373,8 +371,7 @@ def __init__(self, in_channels=3, out_channels=64, norm="BN"):
373
371
weight_init .c2_msra_fill (self .conv1 )
374
372
375
373
def forward (self , x ):
376
- """Forward function of `BasicStem`.
377
- """
374
+ """Forward function of `BasicStem`."""
378
375
x = self .conv1 (x )
379
376
x = F .relu_ (x )
380
377
x = F .max_pool2d (x , kernel_size = 3 , stride = 2 , padding = 1 )
@@ -383,7 +380,7 @@ def forward(self, x):
383
380
384
381
class ResNet (Backbone ):
385
382
"""
386
- Implement paper `Deep Residual Learning for Image Recognition
383
+ Implement paper `Deep Residual Learning for Image Recognition
387
384
<https://arxiv.org/pdf/1512.03385.pdf>`_.
388
385
389
386
Args:
@@ -458,7 +455,7 @@ def forward(self, x):
458
455
"""
459
456
Args:
460
457
x: Tensor of shape (N,C,H,W). H, W must be a multiple of ``self.size_divisibility``.
461
-
458
+
462
459
Returns:
463
460
dict[str->Tensor]: names and the corresponding features
464
461
"""
@@ -492,14 +489,14 @@ def freeze(self, freeze_at=0):
492
489
Freeze the first several stages of the ResNet. Commonly used in
493
490
fine-tuning.
494
491
Layers that produce the same feature map spatial size are defined as one
495
- "stage" by paper `Feature Pyramid Networks for Object Detection
492
+ "stage" by paper `Feature Pyramid Networks for Object Detection
496
493
<https://arxiv.org/pdf/1612.03144.pdf>`_.
497
-
494
+
498
495
Args:
499
496
freeze_at (int): number of stages to freeze.
500
497
`1` means freezing the stem. `2` means freezing the stem and
501
498
one residual stage, etc.
502
-
499
+
503
500
Returns:
504
501
nn.Module: this ResNet itself
505
502
"""
@@ -515,10 +512,10 @@ def freeze(self, freeze_at=0):
515
512
def make_stage (block_class , num_blocks , * , in_channels , out_channels , ** kwargs ):
516
513
"""
517
514
Create a list of blocks of the same type that forms one ResNet stage.
518
-
515
+
519
516
Args:
520
- block_class (type): a subclass of ``detectron2.layers.CNNBlockBase`` that's
521
- used to create all blocks in this stage. A module of this type
517
+ block_class (type): a subclass of ``detectron2.layers.CNNBlockBase`` that's
518
+ used to create all blocks in this stage. A module of this type
522
519
must not change spatial resolution of inputs unless its stride != 1.
523
520
num_blocks (int): number of blocks in this stage
524
521
in_channels (int): input channels of the entire stage.
@@ -528,10 +525,10 @@ def make_stage(block_class, num_blocks, *, in_channels, out_channels, **kwargs):
528
525
argument is a list of values to be passed to each block in the
529
526
stage. Otherwise, the same argument is passed to every block
530
527
in the stage.
531
-
528
+
532
529
Returns:
533
530
list[detectron2.layers.CNNBlockBase]: a list of block module.
534
-
531
+
535
532
Examples:
536
533
::
537
534
stage = ResNet.make_stage(
@@ -540,10 +537,10 @@ def make_stage(block_class, num_blocks, *, in_channels, out_channels, **kwargs):
540
537
stride_per_block=[2, 1, 1],
541
538
dilations_per_block=[1, 1, 2]
542
539
)
543
-
540
+
544
541
Usually, layers that produce the same feature map spatial size are defined as one
545
542
"stage" (in paper `Feature Pyramid Networks for Object Detection
546
- <https://arxiv.org/pdf/1612.03144.pdf>`_).
543
+ <https://arxiv.org/pdf/1612.03144.pdf>`_).
547
544
Under such definition, ``stride_per_block[1:]`` should all be 1.
548
545
"""
549
546
blocks = []
@@ -573,7 +570,7 @@ def make_default_stages(depth, block_class=None, **kwargs):
573
570
Created list of ResNet stages from pre-defined depth (one of 18, 34, 50, 101, 152).
574
571
If it doesn't create the ResNet variant you need, please use :meth:`make_stage`
575
572
instead for fine-grained customization.
576
-
573
+
577
574
Args:
578
575
depth (int): depth of ResNet
579
576
block_class (type): the CNN block class. Has to accept
@@ -583,7 +580,7 @@ def make_default_stages(depth, block_class=None, **kwargs):
583
580
kwargs:
584
581
other arguments to pass to `make_stage`. Should not contain
585
582
stride and channels, as they are predefined for each depth.
586
-
583
+
587
584
Returns:
588
585
list[list[detectron2.layers.CNNBlockBase]]: modules in all stages; see arguments of
589
586
:class:`ResNet`.
@@ -640,11 +637,11 @@ def make_stage(
640
637
deform_num_groups : int = 1 ,
641
638
):
642
639
"""
643
- Modified from `detectron2.modeling.backbone.build_resnet_backbone
640
+ Modified from `detectron2.modeling.backbone.build_resnet_backbone
644
641
<https://github.com/facebookresearch/detectron2/blob/717ab9f0aeca216a2f800e43d705766251ba3a55/detectron2/modeling/backbone/resnet.py#L614>`_
645
642
646
643
Create a list of blocks of the same type that forms one ResNet stage.
647
-
644
+
648
645
Args:
649
646
depth (int): The depth of ResNet. Default: 50.
650
647
norm (str or callable): Normalization for all conv layers.
@@ -656,10 +653,10 @@ def make_stage(
656
653
Default: 64.
657
654
in_channels (int): Output feature channels of the `Stem` Block. Needs
658
655
to be set to 64 for R18 and R34. Default: 64.
659
- out_channels (int): Output width of res2. Scaling this parameters
656
+ out_channels (int): Output width of res2. Scaling this parameters
660
657
will scale the width of all 1x1 convs in ResNet. Default: 256.
661
- stride_in_1x1 (bool): Place the stride 2 conv on the 1x1 filter.
662
- Use True only for the original MSRA ResNet;
658
+ stride_in_1x1 (bool): Place the stride 2 conv on the 1x1 filter.
659
+ Use True only for the original MSRA ResNet;
663
660
use False for C2 and Torch models. Default: False.
664
661
res5_dilation (int): Apply dilation in stage "res5". Default: 1.
665
662
deform_on_per_stage (List[bool]): Apply Deformable Convolution in stages.
@@ -669,10 +666,10 @@ def make_stage(
669
666
(DeformableV2, https://arxiv.org/abs/1811.11168); Use False for DeformableV1.
670
667
Default: False.
671
668
deform_num_groups (int): Number of groups in deformable conv. Default: 1.
672
-
669
+
673
670
Returns:
674
671
list[detectron2.layers.CNNBlockBase]: a list of block module.
675
-
672
+
676
673
Examples:
677
674
::
678
675
from detrex.modeling.backbone import make_stage, ResNet, BasicStem
@@ -737,4 +734,4 @@ def make_stage(
737
734
bottleneck_channels *= 2
738
735
stages .append (blocks )
739
736
740
- return stages
737
+ return stages
0 commit comments