Exemplo n.º 1
0
    def __init__(self, n_layer, pretrained_model=None, initialW=None):
        n_block = self._blocks[n_layer]

        _, path = utils.prepare_pretrained_model({}, pretrained_model,
                                                 self._models[n_layer])

        super(DilatedResNet, self).__init__()
        with self.init_scope():
            self.conv1_1 = Conv2DBNActiv(None,
                                         64,
                                         3,
                                         2,
                                         1,
                                         1,
                                         initialW=initialW)
            self.conv1_2 = Conv2DBNActiv(64, 64, 3, 1, 1, 1, initialW=initialW)
            self.conv1_3 = Conv2DBNActiv(64,
                                         128,
                                         3,
                                         1,
                                         1,
                                         1,
                                         initialW=initialW)
            self.pool1 = lambda x: F.max_pooling_2d(
                x, ksize=3, stride=2, pad=1)
            self.res2 = ResBlock(n_block[0],
                                 128,
                                 64,
                                 256,
                                 1,
                                 1,
                                 initialW=initialW,
                                 stride_first=False)
            self.res3 = ResBlock(n_block[1],
                                 256,
                                 128,
                                 512,
                                 2,
                                 1,
                                 initialW=initialW,
                                 stride_first=False)
            self.res4 = ResBlock(n_block[2],
                                 512,
                                 256,
                                 1024,
                                 1,
                                 2,
                                 initialW=initialW,
                                 stride_first=False)
            self.res5 = ResBlock(n_block[3],
                                 1024,
                                 512,
                                 2048,
                                 1,
                                 4,
                                 initialW=initialW,
                                 stride_first=False)

        if path:
            chainer.serializers.load_npz(path, self, ignore_names=None)
Exemplo n.º 2
0
    def __init__(self,
                 out_size,
                 transform_rois_to_grayscale=False,
                 train_imagenet=False):
        super(SheepLocalizer, self).__init__()
        initialW = initializers.HeNormal(scale=1., fan_option='fan_out')
        kwargs = {"initialW": initialW}
        keys_to_remove = ['fc6', 'prob'] if not train_imagenet else ['prob']
        with self.init_scope():
            self.feature_extractor = MyResNet50Layers(
                keys_to_remove=keys_to_remove, pretrained_model='auto')
            if not train_imagenet:
                self.param_predictor = L.Linear(2048, 6)

                self.res6 = ResBlock(2, None, 1024, 2048, 2, **kwargs)
                self.res7 = ResBlock(2, None, 1024, 2048, 2, **kwargs)

                transform_bias = self.param_predictor.b.data
                transform_bias[[0, 4]] = 0.8
                transform_bias[[2, 5]] = 0
                self.param_predictor.W.data[...] = 0

        self.visual_backprop_anchors = []
        self.out_size = out_size
        self.transform_rois_to_grayscale = transform_rois_to_grayscale
        self.train_imagenet = train_imagenet
Exemplo n.º 3
0
    def __init__(self, n_layer,
                 n_class=None,
                 pretrained_model=None,
                 mean=None, initialW=None, fc_kwargs={}):
        blocks = self._blocks[n_layer]
        self.mean = mean

        if initialW is None:
            initialW = initializers.HeNormal(scale=1., fan_option='fan_out')
        if 'initialW' not in fc_kwargs:
            fc_kwargs['initialW'] = initializers.Normal(scale=0.01)

        kwargs = {
            'groups': 32, 'initialW': initialW, 'stride_first': False,
            'add_seblock': True}

        super(SEResNeXt, self).__init__()
        with self.init_scope():
            self.conv1 = Conv2DBNActiv(None, 64, 3, 1, 1, nobias=True,
                                       initialW=initialW)
            self.res2 = ResBlock(blocks[0], None, 128, 256, 2, **kwargs)
            self.res3 = ResBlock(blocks[1], None, 256, 512, 1, **kwargs)
            self.res4 = ResBlock(blocks[2], None, 512, 1024, 2, **kwargs)
            self.res5 = ResBlock(blocks[3], None, 1024, 2048, 1, **kwargs)
            self.pool5 = lambda x: F.average(x, axis=(2, 3))
            self.fc6 = L.Linear(None, n_class, **fc_kwargs)
Exemplo n.º 4
0
    def __init__(self,
                 n_layer,
                 n_class=None,
                 pretrained_model=None,
                 mean=None,
                 initialW=None,
                 fc_kwargs={}):
        blocks = self._blocks[n_layer]

        param, path = utils.prepare_pretrained_model(
            {
                'n_class': n_class,
                'mean': mean
            }, pretrained_model, self._models[n_layer], {
                'n_class': 1000,
                'mean': _imagenet_mean
            })
        self.mean = param['mean']

        if initialW is None:
            initialW = initializers.HeNormal(scale=1., fan_option='fan_out')
        if 'initialW' not in fc_kwargs:
            fc_kwargs['initialW'] = initializers.Normal(scale=0.01)
        if pretrained_model:
            # As a sampling process is time-consuming,
            # we employ a zero initializer for faster computation.
            initialW = initializers.constant.Zero()
            fc_kwargs['initialW'] = initializers.constant.Zero()
        kwargs = {
            'groups': 32,
            'initialW': initialW,
            'stride_first': False,
            'add_seblock': True
        }

        super(SEResNeXt, self).__init__()
        with self.init_scope():
            self.conv1 = Conv2DBNActiv(None,
                                       64,
                                       7,
                                       2,
                                       3,
                                       nobias=True,
                                       initialW=initialW)
            self.pool1 = lambda x: F.max_pooling_2d(x, ksize=3, stride=2)
            self.res2 = ResBlock(blocks[0], None, 128, 256, 1, **kwargs)
            self.res3 = ResBlock(blocks[1], None, 256, 512, 2, **kwargs)
            self.res4 = ResBlock(blocks[2], None, 512, 1024, 2, **kwargs)
            self.res5 = ResBlock(blocks[3], None, 1024, 2048, 2, **kwargs)
            self.pool5 = lambda x: F.average(x, axis=(2, 3))
            self.fc6 = L.Linear(None, param['n_class'], **fc_kwargs)
            self.prob = F.softmax

        if path:
            chainer.serializers.load_npz(path, self)
Exemplo n.º 5
0
 def __init__(self, n_layer, initialW, bn_kwargs=None):
     n_block = self._blocks[n_layer]
     super(DilatedResNet, self).__init__()
     with self.init_scope():
         self.conv1_1 = Conv2DBNActiv(None,
                                      64,
                                      3,
                                      2,
                                      1,
                                      1,
                                      initialW=initialW,
                                      bn_kwargs=bn_kwargs)
         self.conv1_2 = Conv2DBNActiv(64,
                                      64,
                                      3,
                                      1,
                                      1,
                                      1,
                                      initialW=initialW,
                                      bn_kwargs=bn_kwargs)
         self.conv1_3 = Conv2DBNActiv(64,
                                      128,
                                      3,
                                      1,
                                      1,
                                      1,
                                      initialW=initialW,
                                      bn_kwargs=bn_kwargs)
         self.pool1 = lambda x: F.max_pooling_2d(
             x, ksize=3, stride=2, pad=1)
         self.res2 = ResBlock(n_block[0],
                              128,
                              64,
                              256,
                              1,
                              1,
                              initialW=initialW,
                              bn_kwargs=bn_kwargs,
                              stride_first=False)
         self.res3 = ResBlock(n_block[1],
                              256,
                              128,
                              512,
                              2,
                              1,
                              initialW=initialW,
                              bn_kwargs=bn_kwargs,
                              stride_first=False)
         self.res4 = ResBlock(n_block[2],
                              512,
                              256,
                              1024,
                              1,
                              2,
                              initialW=initialW,
                              bn_kwargs=bn_kwargs,
                              stride_first=False)
         self.res5 = ResBlock(n_block[3],
                              1024,
                              512,
                              2048,
                              1,
                              4,
                              initialW=initialW,
                              bn_kwargs=bn_kwargs,
                              stride_first=False)