示例#1
0
 def __init__(
     self,
     block: nn.Module,
     layers: List[int],
     output_dims: List[int],
     groups: int = 1,
     width_per_group: int = 64,
     replace_stride_with_dilation: Optional[Tuple[bool, bool, bool]] = None,
     normalization: Normalization = None,
     blocks: int = 4,
     pretrained_settings: Optional[Dict[str,
                                        Union[str, int, float,
                                              List[Union[int,
                                                         float]]]]] = None,
     pretrained: bool = False,
     progress: bool = False,
 ):
     ResNet.__init__(
         self,
         block,
         layers,
         groups=groups,
         width_per_group=width_per_group,
         norm_layer=normalization,
         replace_stride_with_dilation=replace_stride_with_dilation,
     )
     Encoder.__init__(self, output_dims, pretrained_settings, pretrained,
                      progress)
     self.blocks = blocks
示例#2
0
 def __init__(self, pretrained=True, cuda=True):
     #super(ResNet, self).__init__( block=BasicBlock, layers=[2, 2, 2, 2] )
     ResNet.__init__(self, block=BasicBlock, layers=[2, 2, 2, 2])
     if pretrained:
         self.load_state_dict(model_zoo.load_url(resnet_urls['resnet18']))
     self.filter = USM(in_channels=3, kernel_size=5, fixed_coeff=True, sigma=1.667, cuda=cuda, requires_grad=True)
     #self.filter.assign_weight(1.33)
     self.filter_conv1 = USM(in_channels=64, kernel_size=5, fixed_coeff=True, sigma=1.667, cuda=cuda)
示例#3
0
 def __init__(self,
              block,
              layers,
              num_classes=1000,
              kw=4,
              ka=4,
              fp_layers=None,
              align_zero=True,
              use_channel_quant=False,
              use_ckpt=False,
              use_multi_domain=False):
     ResNet.__init__(self, block, layers, num_classes)
     IDQ.__init__(self, ResNet.forward, kw, ka, fp_layers, align_zero,
                  use_channel_quant, use_ckpt, use_multi_domain)
    def __init__(self,
                 block,
                 layers,
                 num_coarse_classes,
                 num_classes=1000,
                 zero_init_residual=True,
                 groups=1,
                 width_per_group=64,
                 replace_stride_with_dilation=None,
                 norm_layer=None,
                 mean=None,
                 std=None):
        _ResNet.__init__(
            self,
            block,
            layers,
            num_classes=num_classes,
            zero_init_residual=zero_init_residual,
            groups=groups,
            width_per_group=width_per_group,
            replace_stride_with_dilation=replace_stride_with_dilation,
            norm_layer=norm_layer)

        if mean is None:
            self.register_buffer(
                'mean',
                torch.tensor(IMAGENET_MEAN).view(1, -1, 1, 1) / 255)
        else:
            self.register_buffer('mean', torch.tensor(mean).view(1, -1, 1, 1))
        if std is None:
            self.register_buffer(
                'std',
                torch.tensor(IMAGENET_STD).view(1, -1, 1, 1) / 255)
        else:
            self.register_buffer('std', torch.tensor(std).view(1, -1, 1, 1))

        self.aux1 = InceptionAux(in_channels=4 * 64,
                                 num_coarse_classes=num_coarse_classes[0],
                                 pool=2)
        self.aux2 = InceptionAux(in_channels=4 * 128,
                                 num_coarse_classes=num_coarse_classes[1],
                                 pool=1)
        self.aux3 = InceptionAux(in_channels=4 * 256,
                                 num_coarse_classes=num_coarse_classes[2])
示例#5
0
 def __init__(self, ngpu):
     ResNet.__init__(self, BasicBlock, [3, 4, 6, 3])
     self.load_state_dict(model_zoo.load_url(model_urls['resnet34']))
     self.ngpu = ngpu
     self.output = nn.Sequential(nn.Linear(512, 1), nn.Sigmoid())