ResNet backbone with frozen BatchNorm.
| 84 | |
| 85 | |
| 86 | class Backbone(BackboneBase): |
| 87 | """ResNet backbone with frozen BatchNorm.""" |
| 88 | def __init__( |
| 89 | self, |
| 90 | name: str, |
| 91 | train_backbone: bool, |
| 92 | dilation: bool, |
| 93 | return_interm_indices: list, |
| 94 | batch_norm=FrozenBatchNorm2d, |
| 95 | ): |
| 96 | if name in ['resnet18', 'resnet34', 'resnet50', 'resnet101']: |
| 97 | # backbone = getattr(torchvision.models, name)( |
| 98 | # replace_stride_with_dilation=[False, False, dilation], |
| 99 | # pretrained=is_main_process(), norm_layer=batch_norm) |
| 100 | backbone = getattr(torchvision.models, name)( |
| 101 | replace_stride_with_dilation=[False, False, dilation], |
| 102 | pretrained=False, |
| 103 | norm_layer=batch_norm) |
| 104 | else: |
| 105 | raise NotImplementedError( |
| 106 | 'Why you can get here with name {}'.format(name)) |
| 107 | |
| 108 | assert name not in ( |
| 109 | 'resnet18', |
| 110 | 'resnet34'), 'Only resnet50 and resnet101 are available.' |
| 111 | assert return_interm_indices in [[0, 1, 2, 3], [1, 2, 3], [3]] |
| 112 | num_channels_all = [256, 512, 1024, 2048] |
| 113 | num_channels = num_channels_all[4 - len(return_interm_indices):] |
| 114 | super().__init__(backbone, train_backbone, num_channels, |
| 115 | return_interm_indices) |
| 116 | |
| 117 | |
| 118 | class Joiner(nn.Sequential): |