def __init__(self, reduction: str = 'mean', **kwargs): r"""""" super().__init__() self.reduce = build_reduce(reduction) self.kwargs = { k: v for k, v in kwargs.items() if k not in ['dim', 'keepdim'] }
def __init__( self, window_size: int = 11, n_channels: int = 3, reduction: str = 'mean', **kwargs, ): r"""""" super().__init__() self.register_buffer('window', create_window(window_size, n_channels)) self.reduce = build_reduce(reduction) self.kwargs = kwargs
def __init__( self, network: str = 'alex', scaling: bool = True, dropout: bool = True, pretrained: bool = True, reduction: str = 'mean', ): r"""""" super().__init__() # ImageNet scaling self.scaling = scaling self.register_buffer('shift', _SHIFT.view(1, -1, 1, 1)) self.register_buffer('scale', _SCALE.view(1, -1, 1, 1)) # Perception layers if network == 'alex': # AlexNet layers = models.alexnet(pretrained=True).features targets = [1, 4, 7, 9, 11] channels = [64, 192, 384, 256, 256] elif network == 'squeeze': # SqueezeNet layers = models.squeezenet1_1(pretrained=True).features targets = [1, 4, 7, 9, 10, 11, 12] channels = [64, 128, 256, 384, 384, 512, 512] elif network == 'vgg': # VGG16 layers = models.vgg16(pretrained=True).features targets = [3, 8, 15, 22, 29] channels = [64, 128, 256, 512, 512] else: raise ValueError('Unknown network architecture ' + network) self.net = Intermediary(layers, targets) for p in self.net.parameters(): p.requires_grad = False # Linear comparators self.lin = nn.ModuleList([ nn.Sequential( nn.Dropout(inplace=True) if dropout else nn.Identity(), nn.Conv2d(c, 1, kernel_size=1, stride=1, padding=0, bias=False), ) for c in channels ]) if pretrained: self.lin.load_state_dict(get_weights(network=network)) self.reduce = build_reduce(reduction)
def __init__(self, reduction: str = 'mean', **kwargs): r"""""" super().__init__() self.reduce = build_reduce(reduction) self.kwargs = kwargs