Exemplo n.º 1
0
    def __init__(self, n_class=None, pretrained_model=None, initialW=None):
        param, path = utils.prepare_pretrained_model({'n_class': n_class},
                                                     pretrained_model,
                                                     self._models)
        self.n_class = param['n_class']

        if initialW is None:
            initialW = chainer.initializers.HeNormal()

        super(SegNetBasic, self).__init__()
        with self.init_scope():
            self.conv1 = L.Convolution2D(None,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv1_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv2 = L.Convolution2D(64,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv2_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv3 = L.Convolution2D(64,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv3_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv4 = L.Convolution2D(64,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv4_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv_decode4 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode4_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv_decode3 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode3_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv_decode2 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode2_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv_decode1 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode1_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv_classifier = L.Convolution2D(64,
                                                   self.n_class,
                                                   1,
                                                   1,
                                                   0,
                                                   initialW=initialW)

        if path:
            chainer.serializers.load_npz(path, self)
Exemplo n.º 2
0
 def __init__(self, in_channel, out_channel, filter_size=(3, 3), stride=(1, 1), pad=(1, 1)):
     super(BN_ReLU_Conv, self).__init__(
         conv=L.Convolution2D(in_channel, out_channel, filter_size, stride, pad),
         bn=L.BatchNormalization(in_channel),
     )
Exemplo n.º 3
0
 def __init__(self, in_ch, out_ch):
     super(TransitionLayer, self).__init__()
     with self.init_scope():
         self.bn = L.BatchNormalization(in_ch)
         self.conv = L.Convolution2D(in_ch, out_ch, 1, 1, 0)
Exemplo n.º 4
0
 def __init__(self):
     super(ResidualBlock_64,
           self).__init__(L.Convolution2D(64, 64, 3, pad=1),
                          L.BatchNormalization(64),
                          L.Convolution2D(64, 64, 3, pad=1),
                          L.BatchNormalization(64))
Exemplo n.º 5
0
 def __init__(self, maps, act=F.relu):
     super(DeconvUnit, self).__init__(
         deconv0=L.Convolution2D(maps, maps, 3, stride=1, pad=1),
         bn0=L.BatchNormalization(maps, decay=0.9, use_cudnn=True),
     )
     self.act = act
Exemplo n.º 6
0
    def __init__(self, in_ch, out_ch):
        super(Model, self).__init__()

        w_init = inits.HeNormal()

        with self.init_scope():
            self.conv0 = L.Convolution2D(in_ch,
                                         12,
                                         ksize=4,
                                         stride=2,
                                         pad=1,
                                         nobias=True,
                                         initialW=w_init)
            self.bn0 = AutomaticBatchRenormalization(12, decay=0.99)

            self.conv1 = Sequential(
                Residual(
                    Unit(in_ch=12,
                         out_ch_list=[15, 18],
                         use_bn_list=[False, True],
                         w_init=w_init)))
            self.conv1.extend(Block(in_ch=18, out_ch_list=[24], w_init=w_init))

            self.conv2 = Block(in_ch=24, out_ch_list=[30, 36], w_init=w_init)
            self.conv3 = Block(in_ch=36, out_ch_list=[42, 48], w_init=w_init)
            self.conv4 = Block(in_ch=48, out_ch_list=[54, 60], w_init=w_init)
            self.conv5 = Block(in_ch=60, out_ch_list=[60, 60], w_init=w_init)
            self.conv6 = Block(in_ch=60, out_ch_list=[60, 60], w_init=w_init)
            self.conv7 = Block(in_ch=60, out_ch_list=[66, 72], w_init=w_init)

            self.oc7 = OCBlock(72, 12, w_init=w_init)

            self.conv6_branch = Block(in_ch=60,
                                      out_ch_list=[66, 72],
                                      w_init=w_init)
            self.oc6 = OCBlock(72, 12, w_init=w_init)

            self.conv5_branch = Block(in_ch=60,
                                      out_ch_list=[66, 72],
                                      w_init=w_init)
            self.oc5 = OCBlock(72, 12, w_init=w_init)

            self.conv4_branch = Block(in_ch=60,
                                      out_ch_list=[66, 72],
                                      w_init=w_init)
            self.oc4 = OCBlock(72, 12, w_init=w_init)

            self.conv3_branch = Block(in_ch=48,
                                      out_ch_list=[54, 60],
                                      w_init=w_init)
            self.oc3 = OCBlock(60, 10, w_init=w_init)

            self.conv2_branch = Block(in_ch=36,
                                      out_ch_list=[42, 48],
                                      w_init=w_init)
            self.conv2_out = L.Convolution2D(48,
                                             8,
                                             ksize=3,
                                             pad=1,
                                             nobias=True,
                                             initialW=w_init)
            self.bn2_out = AutomaticBatchRenormalization(8, decay=0.99)

            self.conv1_branch = Block(in_ch=24,
                                      out_ch_list=[30, 36],
                                      w_init=w_init)
            self.conv1_out = L.Convolution2D(36,
                                             6,
                                             ksize=3,
                                             pad=1,
                                             nobias=True,
                                             initialW=w_init)
            self.bn1_out = AutomaticBatchRenormalization(6, decay=0.99)

            self.conv_out = L.Convolution2D(4 * 12 + 10 + 8 + 6,
                                            out_ch,
                                            ksize=3,
                                            pad=1,
                                            nobias=False,
                                            initialW=w_init)
Exemplo n.º 7
0
 def __init__(self):
     super(A, self).__init__()
     with self.init_scope():
         # TODO(satos) テストケース増やす
         self.l1 = L.Convolution2D(None, 6, (5, 7), stride=(2, 3))
Exemplo n.º 8
0
    def __init__(self,
                 n_class=None,
                 pretrained_model=None,
                 initialW=None,
                 dtype='float32'):
        param, path = utils.prepare_pretrained_model({'n_class': n_class},
                                                     pretrained_model,
                                                     self._models)
        self.n_class = param['n_class']
        self.dtype = dtype

        if initialW is None:
            initialW = chainer.initializers.HeNormal()

        super(SegNetBasic, self).__init__()
        with self.init_scope():
            self.lrn = lambda x: F.local_response_normalization(
                x, 5, 1, 1e-4 / 5., 0.75)

            self.conv1 = L.Convolution2D(None,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv1_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv1_relu = lambda x: F.relu(x)
            self.conv1_pool = lambda x: F.max_pooling_2d(
                x, 2, 2, return_indices=True)

            self.conv2 = L.Convolution2D(64,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv2_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv2_relu = lambda x: F.relu(x)
            self.conv2_pool = lambda x: F.max_pooling_2d(
                x, 2, 2, return_indices=True)

            self.conv3 = L.Convolution2D(64,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv3_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv3_relu = lambda x: F.relu(x)
            self.conv3_pool = lambda x: F.max_pooling_2d(
                x, 2, 2, return_indices=True)

            self.conv4 = L.Convolution2D(64,
                                         64,
                                         7,
                                         1,
                                         3,
                                         nobias=True,
                                         initialW=initialW)
            self.conv4_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv4_relu = lambda x: F.relu(x)
            self.conv4_pool = lambda x: F.max_pooling_2d(
                x, 2, 2, return_indices=True)

            self.upsampling4 = lambda x, indices: self._upsampling_2d(
                x, indices)
            self.conv_decode4 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode4_bn = L.BatchNormalization(64, initial_beta=0.001)

            self.upsampling3 = lambda x, indices: self._upsampling_2d(
                x, indices)
            self.conv_decode3 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode3_bn = L.BatchNormalization(64, initial_beta=0.001)

            self.upsampling2 = lambda x, indices: self._upsampling_2d(
                x, indices)
            self.conv_decode2 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode2_bn = L.BatchNormalization(64, initial_beta=0.001)

            self.upsampling1 = lambda x, indices: self._upsampling_2d(
                x, indices)
            self.conv_decode1 = L.Convolution2D(64,
                                                64,
                                                7,
                                                1,
                                                3,
                                                nobias=True,
                                                initialW=initialW)
            self.conv_decode1_bn = L.BatchNormalization(64, initial_beta=0.001)
            self.conv_classifier = L.Convolution2D(64,
                                                   self.n_class,
                                                   1,
                                                   1,
                                                   0,
                                                   initialW=initialW)

        self.type_cast_ada_loss = None

        if path:
            chainer.serializers.load_npz(path, self)
Exemplo n.º 9
0
    def __init__(self,
                 n_units=256,
                 n_out=0,
                 img_size=112,
                 var=0.18,
                 wvar=0,
                 n_step=2,
                 gpu_id=-1):
        super(BASE, self).__init__(
            # the size of the inputs to each layer will be inferred
            # glimpse network
            # 切り取られた画像を処理する部分 位置情報 (glimpse loc)と画像特徴量の積を出力
            # in 256 * 256 * 3
            #
            # 16 * 16 ->  8 * 8 -> 4 * 4 -> 1
            #         pool      pool      full
            cnn_1_1=L.Convolution2D(3, 32, 3, pad=1),
            cnn_1_2=L.Convolution2D(32, 32, 3, pad=1),
            cnn_2_1=L.Convolution2D(32, 64, 3, pad=1),
            cnn_2_2=L.Convolution2D(64, 64, 3, pad=1),
            cnn_3_1=L.Convolution2D(64, 64, 3, pad=1),
            cnn_3_2=L.Convolution2D(64, 64, 3, pad=1),
            full_1=L.Linear(2 * 2 * 64, 256),
            # full_2=L.Linear(None, 10),
            glimpse_loc=L.Linear(3, 256),
            norm_1_1=L.BatchNormalization(32),
            norm_1_2=L.BatchNormalization(32),
            norm_2_1=L.BatchNormalization(64),
            norm_2_2=L.BatchNormalization(64),
            norm_3_1=L.BatchNormalization(64),
            norm_3_2=L.BatchNormalization(64),
            norm_f1=L.BatchNormalization(256),

            # 記憶を用いるLSTM部分
            rnn_1=L.LSTM(n_units, n_units),
            rnn_2=L.LSTM(n_units, n_units),

            # 注意領域を選択するネットワーク
            attention_loc=L.Linear(n_units, 2),
            attention_scale=L.Linear(n_units, 1),

            # 入力画像を処理するネットワーク
            # 256 * 256 -> 64 * 64 -> 32 * 32 -> 16 * 16
            #           pool
            context_cnn_1=L.Convolution2D(3, 64, 3, pad=1),
            context_cnn_2=L.Convolution2D(64, 64, 3, pad=1),
            context_cnn_3=L.Convolution2D(64, 128, 3, pad=1),
            context_cnn_4=L.Convolution2D(128, 128, 3, pad=1),
            context_cnn_5=L.Convolution2D(128, 128, 3, pad=1),
            context_full=L.Linear(16 * 16 * 128, n_units),
            l_norm_cc1=L.BatchNormalization(64),
            l_norm_cc2=L.BatchNormalization(64),
            l_norm_cc3=L.BatchNormalization(128),
            l_norm_cc4=L.BatchNormalization(128),
            l_norm_cc5=L.BatchNormalization(128),

            # baseline network 強化学習の期待値を学習し、バイアスbとする
            baseline=L.Linear(n_units, 1),
            class_full=L.Linear(n_units, n_out))

        #
        # img parameter
        #
        if gpu_id == 0:
            self.use_gpu = True
        else:
            self.use_gpu = False
        self.img_size = img_size
        self.gsize = 16
        self.train = True
        self.var = var
        if wvar == 0:
            self.vars = var
        else:
            self.vars = wvar
        self.n_unit = n_units
        self.num_class = n_out
        # r determine the rate of position
        self.r = 0.5
        self.r_recognize = 1.0
        self.n_step = n_step
Exemplo n.º 10
0
 def __init__(self, input_channel, output_channel, t_filter_height, t_filter_width, i_filter_height):
     super(SimpleCNN, self).__init__(
         conv_t = L.Convolution2D(input_channel, output_channel, (t_filter_height, t_filter_width)),
         conv_i = L.Convolution2D(input_channel, output_channel, i_filter_height),
     )
    def __init__(self, n_classes):
        initialW = initializers.HeNormal()
        super(YOLOv2Classifier, self).__init__(
            conv1  = L.Convolution2D(3, 16, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn1    = L.BatchNormalization(16, use_beta=False, eps=2e-5),
            bias1  = L.Bias(shape=(16,)),
            conv2  = L.Convolution2D(16, 32, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn2    = L.BatchNormalization(32, use_beta=False, eps=2e-5),
            bias2  = L.Bias(shape=(32,)),
            conv3  = L.Convolution2D(32, 16, ksize=1, stride=1, pad=0, nobias=True, initialW=initialW),
            bn3    = L.BatchNormalization(16, use_beta=False, eps=2e-5),
            bias3  = L.Bias(shape=(16,)),
            conv4  = L.Convolution2D(16, 32, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn4    = L.BatchNormalization(32, use_beta=False, eps=2e-5),
            bias4  = L.Bias(shape=(32,)),
            conv5  = L.Convolution2D(32, 64, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn5    = L.BatchNormalization(64, use_beta=False, eps=2e-5),
            bias5  = L.Bias(shape=(64,)),
            conv6  = L.Convolution2D(64, 32, ksize=1, stride=1, pad=0, nobias=True, initialW=initialW),
            bn6    = L.BatchNormalization(32, use_beta=False, eps=2e-5),
            bias6  = L.Bias(shape=(32,)),
            conv7  = L.Convolution2D(32, 64, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn7    = L.BatchNormalization(64, use_beta=False, eps=2e-5),
            bias7  = L.Bias(shape=(64,)),
            conv8  = L.Convolution2D(64, 128, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn8    = L.BatchNormalization(128, use_beta=False, eps=2e-5),
            bias8  = L.Bias(shape=(128,)),
            conv9  = L.Convolution2D(128, 64, ksize=1, stride=1, pad=0, nobias=True, initialW=initialW),
            bn9    = L.BatchNormalization(64, use_beta=False, eps=2e-5),
            bias9  = L.Bias(shape=(64,)),
            conv10 = L.Convolution2D(64, 128, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn10   = L.BatchNormalization(128, use_beta=False, eps=2e-5),
            bias10 = L.Bias(shape=(128,)),
            conv11 = L.Convolution2D(128, 256, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn11   = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias11 = L.Bias(shape=(256,)),
            conv12 = L.Convolution2D(256, 128, ksize=1, stride=1, pad=0, nobias=True, initialW=initialW),
            bn12   = L.BatchNormalization(128, use_beta=False, eps=2e-5),
            bias12 = L.Bias(shape=(128,)),
            conv13 = L.Convolution2D(128, 256, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn13   = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias13 = L.Bias(shape=(256,)),
            conv14 = L.Convolution2D(256, 512, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn14   = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias14 = L.Bias(shape=(512,)),
            conv15 = L.Convolution2D(512, 256, ksize=1, stride=1, pad=0, nobias=True, initialW=initialW),
            bn15   = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias15 = L.Bias(shape=(256,)),
            conv16 = L.Convolution2D(256, 512, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn16   = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias16 = L.Bias(shape=(512,)),
            conv17 = L.Convolution2D(512, 256, ksize=1, stride=1, pad=0, nobias=True, initialW=initialW),
            bn17   = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias17 = L.Bias(shape=(256,)),
            conv18 = L.Convolution2D(256, 512, ksize=3, stride=1, pad=1, nobias=True, initialW=initialW),
            bn18   = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias18 = L.Bias(shape=(512,)),

            fc19 = L.Linear(512, n_classes),
        )
        self.finetune = False
        self.n_classes = n_classes
 def __init__(self):
     super(WaveNet, self).__init__(
         dc00=L.Convolution2D(1, 1, (2, 1), pad=(1, 0), use_cudnn=False),
         dc01=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc02=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc03=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc04=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc05=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc06=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc07=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc08=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc09=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc10=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc11=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc12=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc13=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc14=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc15=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc16=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc17=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc18=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc19=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc20=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc21=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc22=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc23=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc24=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc25=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc26=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc27=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc28=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         dc29=L.Convolution2D(None, 2, (2, 1), pad=(1, 0), use_cudnn=False),
         c101=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c102=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c103=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c104=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c105=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c106=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c107=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c108=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c109=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c110=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c111=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c112=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c113=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c114=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c115=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c116=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c117=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c118=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c119=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c120=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c121=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c122=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c123=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c124=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c125=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c126=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c127=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         c128=L.Convolution2D(None, 1, (1, 1), use_cudnn=False),
         conv0=L.Convolution2D(None, 128, (1, 1), use_cudnn=False),
         conv1=L.Convolution2D(None, 128, (1, 1), use_cudnn=False),
         conv2=L.Convolution2D(None, 254, (1, 1), use_cudnn=False),
     )
Exemplo n.º 13
0
    def __init__(self, initializer, inch, outch, util):
        self.inch = inch
        self.outch = outch
        super(WalpurgisNightBlock, self).__init__()
        with self.init_scope():
            #plain
            self.pconv1 = L.Convolution2D(inch,
                                          outch,
                                          ksize=3,
                                          stride=1,
                                          pad=1,
                                          initialW=initializer)
            util.add(self.pconv1)
            self.pconv2 = L.Convolution2D(outch,
                                          outch,
                                          ksize=3,
                                          stride=1,
                                          pad=1,
                                          initialW=initializer)
            util.add(self.pconv2)
            self.pbnorm1 = L.BatchNormalization(inch)
            self.pbnorm2 = L.BatchNormalization(outch)
            self.pbnorm3 = L.BatchNormalization(outch)

            #noise
            self.nconv1 = L.Convolution2D(inch,
                                          outch,
                                          ksize=3,
                                          stride=1,
                                          pad=1,
                                          initialW=initializer)
            util.add(self.nconv1)
            self.nconv2 = L.Convolution2D(outch,
                                          outch,
                                          ksize=3,
                                          stride=1,
                                          pad=1,
                                          initialW=initializer)
            util.add(self.nconv2)
            self.nbnorm1 = L.BatchNormalization(inch)
            self.nbnorm2 = L.BatchNormalization(outch)
            self.nbnorm3 = L.BatchNormalization(outch)

            #Dropout
            self.dconv1 = L.Convolution2D(inch,
                                          outch,
                                          ksize=3,
                                          stride=1,
                                          pad=1,
                                          initialW=initializer)
            util.add(self.dconv1)
            self.dconv2 = L.Convolution2D(outch,
                                          outch,
                                          ksize=3,
                                          stride=1,
                                          pad=1,
                                          initialW=initializer)
            util.add(self.dconv2)
            self.dbnorm1 = L.BatchNormalization(inch)
            self.dbnorm2 = L.BatchNormalization(outch)
            self.dbnorm3 = L.BatchNormalization(outch)

            #adder
            self.addconv = L.Convolution2D(inch + (outch * 3),
                                           outch,
                                           ksize=1,
                                           stride=1,
                                           pad=0,
                                           nobias=True,
                                           initialW=initializer)
            util.add(self.addconv, nobias=True)
Exemplo n.º 14
0
    def __init__(self, n_z=10, beta=1, k=1, channel_num=3):
        """
        Args:
            n_z (int) :  latent dimension
            beta (int) : Regularization strength for KL divergence.
            k (int) : Number of Monte Carlo samples used in encoded vector.
        """
        super(BaseVAE, self).__init__()
        with self.init_scope():
            # Prameters
            self.beta = beta
            self.k = k
            self.args = {
                "n_z": n_z,
                "beta": beta,
                "k": k,
                "channel_num": channel_num
            }

            initializer = chainer.initializers.GlorotUniform()
            # encoder
            self.conv1 = L.Convolution2D(in_channels=channel_num,
                                         out_channels=32,
                                         ksize=4,
                                         stride=2,
                                         pad=1,
                                         initialW=initializer)
            self.conv2 = L.Convolution2D(in_channels=32,
                                         out_channels=32,
                                         ksize=4,
                                         stride=2,
                                         pad=1,
                                         initialW=initializer)
            self.conv3 = L.Convolution2D(in_channels=32,
                                         out_channels=64,
                                         ksize=4,
                                         stride=2,
                                         pad=1,
                                         initialW=initializer)
            self.conv4 = L.Convolution2D(in_channels=64,
                                         out_channels=64,
                                         ksize=4,
                                         stride=2,
                                         pad=1,
                                         initialW=initializer)
            self.fc1 = L.Linear(1024, 256, initialW=initializer)
            self.fc2_mu = L.Linear(256, n_z, initialW=initializer)
            self.fc2_ln_var = L.Linear(256, n_z, initialW=initializer)
            # decoder
            self.fc3 = L.Linear(n_z, 256, initialW=initializer)
            self.fc4 = L.Linear(256, 1024, initialW=initializer)
            self.deconv1 = L.Deconvolution2D(in_channels=64,
                                             out_channels=64,
                                             ksize=4,
                                             stride=2,
                                             pad=1,
                                             initialW=initializer)
            self.deconv2 = L.Deconvolution2D(in_channels=64,
                                             out_channels=32,
                                             ksize=4,
                                             stride=2,
                                             pad=1,
                                             initialW=initializer)
            self.deconv3 = L.Deconvolution2D(in_channels=32,
                                             out_channels=32,
                                             ksize=4,
                                             stride=2,
                                             pad=1,
                                             initialW=initializer)
            self.deconv4 = L.Deconvolution2D(in_channels=32,
                                             out_channels=channel_num,
                                             ksize=4,
                                             stride=2,
                                             pad=1,
                                             initialW=initializer)
Exemplo n.º 15
0
Arquivo: fcn16s.py Projeto: tpys/fcn
    def __init__(self, n_class=21):
        self.n_class = n_class
        super(self.__class__, self).__init__(
            conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=100),
            conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1),

            conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1),
            conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1),

            conv3_1=L.Convolution2D(128, 256, 3, stride=1, pad=1),
            conv3_2=L.Convolution2D(256, 256, 3, stride=1, pad=1),
            conv3_3=L.Convolution2D(256, 256, 3, stride=1, pad=1),

            conv4_1=L.Convolution2D(256, 512, 3, stride=1, pad=1),
            conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),

            conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),

            fc6=L.Convolution2D(512, 4096, 7, stride=1, pad=0),
            fc7=L.Convolution2D(4096, 4096, 1, stride=1, pad=0),

            score_fr=L.Convolution2D(4096, self.n_class, 1, stride=1, pad=0),
            score_pool4=L.Convolution2D(512, self.n_class, 1, stride=1, pad=0),

            upscore2=L.Deconvolution2D(self.n_class, self.n_class, 4,
                                       stride=2),
            upscore16=L.Deconvolution2D(self.n_class, self.n_class, 32,
                                        stride=16),
        )
        self.train = False
Exemplo n.º 16
0
 def __init__(self):
     super(VGG_multi, self).__init__(
         conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=1),
         conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1),
         conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1),
         conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1),
         conv3_1=L.Convolution2D(128, 256, 3, stride=1, pad=1),
         conv3_2=L.Convolution2D(256, 256, 3, stride=1, pad=1),
         conv3_3=L.Convolution2D(256, 256, 3, stride=1, pad=1),
         conv4_1=L.Convolution2D(256, 512, 3, stride=1, pad=1),
         conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
         conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
         conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1),
         conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
         conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
         fc6=L.Linear(2048, 4096),
         fc7=L.Linear(4096, 4096),
         fc8=L.Linear(4096, 768),
     )
     self.train = True
Exemplo n.º 17
0
 def __init__(self):
     super().__init__(
         conv=L.Convolution2D(3, 32, 3, stride=2, pad=0),
         conv_1=L.Convolution2D(32, 32, 3, stride=1, pad=0),
         conv_2=L.Convolution2D(32, 64, 3, stride=1, pad=1),
         conv_3=L.Convolution2D(64, 80, 1, stride=1, pad=0),
         conv_4=L.Convolution2D(80, 192, 3, stride=1, pad=0),
         bn_conv=L.BatchNormalization(32),
         bn_conv_1=L.BatchNormalization(32),
         bn_conv_2=L.BatchNormalization(64),
         bn_conv_3=L.BatchNormalization(80),
         bn_conv_4=L.BatchNormalization(192),
         mixed=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(192, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(192, 48, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(48)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(48, 64, 5, stride=1,
                                                pad=2)),
                     ('bn_conv_1', L.BatchNormalization(64)),
                     ('_relu_1', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(192, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(64, 96, 3, stride=1,
                                                pad=1)),
                     ('bn_conv_1', L.BatchNormalization(96)),
                     ('_relu_1', F.relu),
                     ('conv_2', L.Convolution2D(96, 96, 3, stride=1,
                                                pad=1)),
                     ('bn_conv_2', L.BatchNormalization(96)),
                     ('_relu_2', F.relu)])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(192, 32, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(32)),
                     ('_relu', F.relu)]))
         ]),
         mixed_1=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(256, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(256, 48, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(48)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(48, 64, 5, stride=1,
                                                pad=2)),
                     ('bn_conv_1', L.BatchNormalization(64)),
                     ('_relu_1', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(256, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(64, 96, 3, stride=1,
                                                pad=1)),
                     ('bn_conv_1', L.BatchNormalization(96)),
                     ('_relu_1', F.relu),
                     ('conv_2', L.Convolution2D(96, 96, 3, stride=1,
                                                pad=1)),
                     ('bn_conv_2', L.BatchNormalization(96)),
                     ('_relu_2', F.relu)])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(256, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu)]))
         ]),
         mixed_2=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(288, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(288, 48, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(48)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(48, 64, 5, stride=1,
                                                pad=2)),
                     ('bn_conv_1', L.BatchNormalization(64)),
                     ('_relu_1', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(288, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(64, 96, 3, stride=1,
                                                pad=1)),
                     ('bn_conv_1', L.BatchNormalization(96)),
                     ('_relu_1', F.relu),
                     ('conv_2', L.Convolution2D(96, 96, 3, stride=1,
                                                pad=1)),
                     ('bn_conv_2', L.BatchNormalization(96)),
                     ('_relu_2', F.relu)])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(288, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu)]))
         ]),
         mixed_3=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(288, 384, 3, stride=2,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(384)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(288, 64, 1, stride=1, pad=0)),
                     ('bn_conv', L.BatchNormalization(64)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(64, 96, 3, stride=1,
                                                pad=1)),
                     ('bn_conv_1', L.BatchNormalization(96)),
                     ('_relu_1', F.relu),
                     ('conv_2', L.Convolution2D(96, 96, 3, stride=2,
                                                pad=0)),
                     ('bn_conv_2', L.BatchNormalization(96)),
                     ('_relu_2', F.relu)])),
             ('pool', Tower([('_pooling', _max_pooling_2d_320)]))
         ]),
         mixed_4=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(768, 128, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(128)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(128,
                                      128, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_1', L.BatchNormalization(128)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(128,
                                      192, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_2', L.BatchNormalization(192)),
                     ('_relu_2', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(768, 128, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(128)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(128,
                                      128, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_1', L.BatchNormalization(128)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(128,
                                      128, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_2', L.BatchNormalization(128)),
                     ('_relu_2', F.relu),
                     ('conv_3',
                      L.Convolution2D(128,
                                      128, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_3', L.BatchNormalization(128)),
                     ('_relu_3', F.relu),
                     ('conv_4',
                      L.Convolution2D(128,
                                      192, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_4', L.BatchNormalization(192)),
                     ('_relu_4', F.relu)])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)]))
         ]),
         mixed_5=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(768, 160, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(160)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(160,
                                      160, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_1', L.BatchNormalization(160)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(160,
                                      192, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_2', L.BatchNormalization(192)),
                     ('_relu_2', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(768, 160, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(160)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(160,
                                      160, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_1', L.BatchNormalization(160)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(160,
                                      160, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_2', L.BatchNormalization(160)),
                     ('_relu_2', F.relu),
                     ('conv_3',
                      L.Convolution2D(160,
                                      160, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_3', L.BatchNormalization(160)),
                     ('_relu_3', F.relu),
                     ('conv_4',
                      L.Convolution2D(160,
                                      192, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_4', L.BatchNormalization(192)),
                     ('_relu_4', F.relu)])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)]))
         ]),
         mixed_6=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(768, 160, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(160)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(160,
                                      160, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_1', L.BatchNormalization(160)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(160,
                                      192, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_2', L.BatchNormalization(192)),
                     ('_relu_2', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(768, 160, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(160)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(160,
                                      160, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_1', L.BatchNormalization(160)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(160,
                                      160, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_2', L.BatchNormalization(160)),
                     ('_relu_2', F.relu),
                     ('conv_3',
                      L.Convolution2D(160,
                                      160, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_3', L.BatchNormalization(160)),
                     ('_relu_3', F.relu),
                     ('conv_4',
                      L.Convolution2D(160,
                                      192, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_4', L.BatchNormalization(192)),
                     ('_relu_4', F.relu)])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)]))
         ]),
         mixed_7=Mixed([
             ('conv',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)])),
             ('tower',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(192,
                                      192, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_1', L.BatchNormalization(192)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(192,
                                      192, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_2', L.BatchNormalization(192)),
                     ('_relu_2', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(192,
                                      192, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_1', L.BatchNormalization(192)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(192,
                                      192, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_2', L.BatchNormalization(192)),
                     ('_relu_2', F.relu),
                     ('conv_3',
                      L.Convolution2D(192,
                                      192, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_3', L.BatchNormalization(192)),
                     ('_relu_3', F.relu),
                     ('conv_4',
                      L.Convolution2D(192,
                                      192, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_4', L.BatchNormalization(192)),
                     ('_relu_4', F.relu)])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)]))
         ]),
         mixed_8=Mixed([
             ('tower',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(192,
                                                320,
                                                3,
                                                stride=2,
                                                pad=0)),
                     ('bn_conv_1', L.BatchNormalization(320)),
                     ('_relu_1', F.relu)])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(768, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu),
                     ('conv_1',
                      L.Convolution2D(192,
                                      192, (1, 7),
                                      stride=1,
                                      pad=(0, 3))),
                     ('bn_conv_1', L.BatchNormalization(192)),
                     ('_relu_1', F.relu),
                     ('conv_2',
                      L.Convolution2D(192,
                                      192, (7, 1),
                                      stride=1,
                                      pad=(3, 0))),
                     ('bn_conv_2', L.BatchNormalization(192)),
                     ('_relu_2', F.relu),
                     ('conv_3', L.Convolution2D(192,
                                                192,
                                                3,
                                                stride=2,
                                                pad=0)),
                     ('bn_conv_3', L.BatchNormalization(192)),
                     ('_relu_3', F.relu)])),
             ('pool', Tower([('_pooling', _max_pooling_2d_320)]))
         ]),
         mixed_9=Mixed([
             ('conv',
              Tower([
                  ('conv', L.Convolution2D(1280, 320, 1, stride=1, pad=0)),
                  ('bn_conv', L.BatchNormalization(320)),
                  ('_relu', F.relu),
              ])),
             ('tower',
              Tower([('conv', L.Convolution2D(1280, 384, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(384)),
                     ('_relu', F.relu),
                     ('mixed',
                      Mixed([('conv',
                              Tower([
                                  ('conv',
                                   L.Convolution2D(384,
                                                   384, (1, 3),
                                                   stride=1,
                                                   pad=(0, 1))),
                                  ('bn_conv', L.BatchNormalization(384)),
                                  ('_relu', F.relu),
                              ])),
                             ('conv_1',
                              Tower([
                                  ('conv_1',
                                   L.Convolution2D(384,
                                                   384, (3, 1),
                                                   stride=1,
                                                   pad=(1, 0))),
                                  ('bn_conv_1', L.BatchNormalization(384)),
                                  ('_relu_1', F.relu),
                              ]))]))])),
             ('tower_1',
              Tower([('conv', L.Convolution2D(1280, 448, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(448)),
                     ('_relu', F.relu),
                     ('conv_1', L.Convolution2D(448,
                                                384,
                                                3,
                                                stride=1,
                                                pad=1)),
                     ('bn_conv_1', L.BatchNormalization(384)),
                     ('_relu_1', F.relu),
                     ('mixed',
                      Mixed([('conv',
                              Tower([
                                  ('conv',
                                   L.Convolution2D(384,
                                                   384, (1, 3),
                                                   stride=1,
                                                   pad=(0, 1))),
                                  ('bn_conv', L.BatchNormalization(384)),
                                  ('_relu', F.relu),
                              ])),
                             ('conv_1',
                              Tower([
                                  ('conv_1',
                                   L.Convolution2D(384,
                                                   384, (3, 1),
                                                   stride=1,
                                                   pad=(1, 0))),
                                  ('bn_conv_1', L.BatchNormalization(384)),
                                  ('_relu_1', F.relu),
                              ]))]))])),
             ('tower_2',
              Tower([('_pooling', _average_pooling_2d),
                     ('conv', L.Convolution2D(1280, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)]))
         ]),
         mixed_10=Mixed([
             ('conv',
              Tower([
                  ('conv', L.Convolution2D(2048, 320, 1, stride=1, pad=0)),
                  ('bn_conv', L.BatchNormalization(320)),
                  ('_relu', F.relu),
              ])),
             ('tower',
              Tower([('conv', L.Convolution2D(2048, 384, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(384)),
                     ('_relu', F.relu),
                     ('mixed',
                      Mixed([('conv',
                              Tower([
                                  ('conv',
                                   L.Convolution2D(384,
                                                   384, (1, 3),
                                                   stride=1,
                                                   pad=(0, 1))),
                                  ('bn_conv', L.BatchNormalization(384)),
                                  ('_relu', F.relu),
                              ])),
                             ('conv_1',
                              Tower([
                                  ('conv_1',
                                   L.Convolution2D(384,
                                                   384, (3, 1),
                                                   stride=1,
                                                   pad=(1, 0))),
                                  ('bn_conv_1', L.BatchNormalization(384)),
                                  ('_relu_1', F.relu),
                              ]))]))])),
             ('tower_1',
              Tower([
                  ('conv', L.Convolution2D(2048, 448, 1, stride=1, pad=0)),
                  ('bn_conv', L.BatchNormalization(448)), ('_relu', F.relu),
                  ('conv_1', L.Convolution2D(448, 384, 3, stride=1, pad=1)),
                  ('bn_conv_1', L.BatchNormalization(384)),
                  ('_relu_1', F.relu),
                  ('mixed',
                   Mixed([('conv',
                           Tower([('conv',
                                   L.Convolution2D(384,
                                                   384, (1, 3),
                                                   stride=1,
                                                   pad=(0, 1))),
                                  ('bn_conv', L.BatchNormalization(384)),
                                  ('_relu', F.relu)])),
                          ('conv_1',
                           Tower([('conv_1',
                                   L.Convolution2D(384,
                                                   384, (3, 1),
                                                   stride=1,
                                                   pad=(1, 0))),
                                  ('bn_conv_1', L.BatchNormalization(384)),
                                  ('_relu_1', F.relu)]))]))
              ])),
             ('tower_2',
              Tower([('_pooling', _max_pooling_2d),
                     ('conv', L.Convolution2D(2048, 192, 1, stride=1,
                                              pad=0)),
                     ('bn_conv', L.BatchNormalization(192)),
                     ('_relu', F.relu)]))
         ]),
         logit=L.Linear(2048, 1008))
Exemplo n.º 18
0
"""
构建ResNet网络模型:由109个卷积层和1个全连接层组成
"""
from branchynet.net import BranchyNet
from branchynet.links import *
from networks.resblock import ResBlock
import chainer.functions as F
import chainer.links as L
import chainer

conv = lambda n: [L.Convolution2D(n, 32, 3, stride=1, pad=1), FL(F.relu)]
cap = lambda n: [L.Linear(n, 10)]


class ResNet:
    def build(self, n=3, percentTrainKeeps=1):
        # 第一个分支网络(由3个卷积层和1个全连接层组成)
        # branch1 = [L.Convolution2D(16, 64, 5, stride=1, pad=2)] + self.norm() + conv(64) + conv(32) + cap(32 * 32 * 32)
        # 第1个分支网络(由2个卷积层和1个全连接层组成)
        branch1 = [ResBlock(16, 16), L.Linear(16 * 32 * 32, 10)]
        # 第2个分支网络(由1个卷积层和1个全连接层组成)
        branch2 = conv(32) + cap(32 * 16 * 16)

        network = self.gen_2b(n, branch1, branch2)
        net = BranchyNet(network, percentTrianKeeps=percentTrainKeeps)

        return net

    # 构建主体网络(并添加两个分支网络)
    def gen_2b(self, n, branch1, branch2):
Exemplo n.º 19
0
# オンライン学習のための1サイクル分のデータセット
def make_cycle(num_of_data):
    cycle = np.zeros((num_of_data, 1, 55, 55))
    cycle = cycle.astype(np.float32)
    output = np.zeros((num_of_data))
    output = output.astype(np.int32)
    for num in range(num_of_data):
        now_code = num2code[num]
        image_list = dataset[now_code]
        cycle[num, :, :, :] = functions.process_img(image_list[random.randint(0, len(image_list) - 1)], image_size, image_center, image_scale, thresh, original_image_size)
        output[num] = code2num[now_code]
    return cycle, output

# model作成
model = chainer.FunctionSet(conv1=L.Convolution2D(1, 32, 6),
                            conv2=L.Convolution2D(32, 64, 6),
                            conv3=L.Convolution2D(64, 128, 5),
                            l1 = L.Linear(4608, 4096),
                            l2 = L.Linear(4096, 6870))

if gpu_flag >= 0:
    cuda.get_device(gpu_flag).use()
    model.to_gpu()

# optimizer
optimizer = optimizers.RMSpropGraves()
optimizer.setup(model)

for epoch in range(epochs):
    print('start_epoch:' + str(epoch))
Exemplo n.º 20
0
 def __init__(self):
     super(MLP, self).__init__()
     with self.init_scope():
         self.l1 = L.Convolution2D(6, 3, 3, pad=1)
         self.l2 = L.Convolution2D(3, 3, 3, pad=1)
         self.l3 = L.Linear(None, self.n_out)
Exemplo n.º 21
0
 def __init__(self):
     super(ResidualBlock,
           self).__init__(L.Convolution2D(128, 128, 3, pad=1),
                          L.BatchNormalization(128),
                          L.Convolution2D(128, 128, 3, pad=1),
                          L.BatchNormalization(128))
Exemplo n.º 22
0
 def __init__(self):
     super(TINY_D_6ch, self).__init__(
         conv1a=L.Convolution2D(3,
                                64,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn1a=L.BatchNormalization(64, use_beta=False),
         bias1a=L.Bias(shape=(64, )),
         conv1b=L.Convolution2D(3,
                                64,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn1b=L.BatchNormalization(64, use_beta=False),
         bias1b=L.Bias(shape=(64, )),
         # MaxPool(3x3, 2)
         conv2a=L.Convolution2D(64,
                                128,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn2a=L.BatchNormalization(128, use_beta=False),
         bias2a=L.Bias(shape=(128, )),
         conv2b=L.Convolution2D(64,
                                128,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn2b=L.BatchNormalization(128, use_beta=False),
         bias2b=L.Bias(shape=(128, )),
         # MaxPool(3x3, 2)
         conv3a=L.Convolution2D(128,
                                256,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn3a=L.BatchNormalization(256, use_beta=False),
         bias3a=L.Bias(shape=(256, )),
         conv3b=L.Convolution2D(128,
                                256,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn3b=L.BatchNormalization(256, use_beta=False),
         bias3b=L.Bias(shape=(256, )),
         # MaxPool(3x3, 2)
         conv4a=L.Convolution2D(256,
                                512,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn4a=L.BatchNormalization(512, use_beta=False),
         bias4a=L.Bias(shape=(512, )),
         conv4b=L.Convolution2D(256,
                                512,
                                ksize=3,
                                stride=1,
                                pad=1,
                                nobias=True),
         bn4b=L.BatchNormalization(512, use_beta=False),
         bias4b=L.Bias(shape=(512, )),
         ##### F.concat() ####
         conv5=L.Convolution2D(1024,
                               1024,
                               ksize=1,
                               stride=1,
                               pad=0,
                               nobias=True),
         # AvgPool(3x3, 2)
         conv6=L.Convolution2D(1024, 6, ksize=1, stride=1, pad=0),
     )
Exemplo n.º 23
0
    def __init__(self,
                 args,
                 num_chan=3,
                 num_resblock=1,
                 wscale=0.02,
                 side_output_at=[64, 128, 256]):
        self.sent_dim = args.sent_dim
        self.hid_dim = args.hid_dim
        self.emb_dim = args.emb_dim
        self.side_output_at = side_output_at

        enc_dim = self.hid_dim * 4
        super(Discriminator, self).__init__()
        with self.init_scope():
            w = chainer.initializers.Normal(wscale)
            if 64 in self.side_output_at:
                self.fg_img_encoder_64 = ImageDown(64, num_chan, enc_dim)
                self.fg_pair_disc_64 = DiscClassifier(enc_dim,
                                                      self.emb_dim,
                                                      kernel_size=4)
                self.fg_local_img_disc_64 = L.Convolution2D(enc_dim,
                                                            1,
                                                            4,
                                                            pad=0,
                                                            initialW=w,
                                                            initial_bias=w)
                self.fg_context_emb_pipe_64 = L.Linear(self.sent_dim,
                                                       self.emb_dim,
                                                       initialW=w,
                                                       initial_bias=w)

                self.bg_img_encoder_64 = ImageDown(64, num_chan, enc_dim)
                self.bg_pair_disc_64 = DiscClassifier(enc_dim,
                                                      self.emb_dim,
                                                      kernel_size=4)
                self.bg_local_img_disc_64 = L.Convolution2D(enc_dim,
                                                            1,
                                                            4,
                                                            pad=0,
                                                            initialW=w,
                                                            initial_bias=w)
                self.bg_context_emb_pipe_64 = L.Linear(self.sent_dim,
                                                       self.emb_dim,
                                                       initialW=w,
                                                       initial_bias=w)

            if 128 in self.side_output_at:
                self.fg_img_encoder_128 = ImageDown(128, num_chan, enc_dim)
                self.fg_pair_disc_128 = DiscClassifier(enc_dim,
                                                       self.emb_dim,
                                                       kernel_size=4)
                self.fg_local_img_disc_128 = L.Convolution2D(enc_dim,
                                                             1,
                                                             4,
                                                             pad=0,
                                                             initialW=w,
                                                             initial_bias=w)
                self.fg_context_emb_pipe_128 = L.Linear(self.sent_dim,
                                                        self.emb_dim,
                                                        initialW=w,
                                                        initial_bias=w)

                self.bg_img_encoder_128 = ImageDown(128, num_chan, enc_dim)
                self.bg_pair_disc_128 = DiscClassifier(enc_dim,
                                                       self.emb_dim,
                                                       kernel_size=4)
                self.bg_local_img_disc_128 = L.Convolution2D(enc_dim,
                                                             1,
                                                             4,
                                                             pad=0,
                                                             initialW=w,
                                                             initial_bias=w)
                self.bg_context_emb_pipe_128 = L.Linear(self.sent_dim,
                                                        self.emb_dim,
                                                        initialW=w,
                                                        initial_bias=w)

                self.img_encoder_128 = ImageDown(128, num_chan, enc_dim)
                self.pair_disc_128 = DiscClassifier(enc_dim,
                                                    self.emb_dim,
                                                    kernel_size=4)
                self.local_img_disc_128 = L.Convolution2D(enc_dim,
                                                          1,
                                                          4,
                                                          pad=0,
                                                          initialW=w,
                                                          initial_bias=w)
                self.context_emb_pipe_128 = L.Linear(self.sent_dim,
                                                     self.emb_dim,
                                                     initialW=w,
                                                     initial_bias=w)

            if 256 in self.side_output_at:
                self.img_encoder_256 = ImageDown(256, num_chan, enc_dim)
                self.pair_disc_256 = DiscClassifier(enc_dim,
                                                    self.emb_dim,
                                                    kernel_size=4)
                self.pre_encode = conv_norm(enc_dim,
                                            enc_dim,
                                            stride=1,
                                            activation=F.leaky_relu,
                                            kernel_size=5,
                                            padding=0)
                self.local_img_disc_256 = L.Convolution2D(enc_dim,
                                                          1,
                                                          4,
                                                          pad=0,
                                                          initialW=w,
                                                          initial_bias=w)
                self.context_emb_pipe_256 = L.Linear(self.sent_dim,
                                                     self.emb_dim,
                                                     initialW=w,
                                                     initial_bias=w)
Exemplo n.º 24
0
 def __init__(self):
     super(Convolutional, self).__init__()
     with self.init_scope():
         feature_maps = 5
         self.convLayer = L.Convolution2D(None, feature_maps, ksize=5)
         self.fullyConnectedOutput = L.Linear(None, 10)
Exemplo n.º 25
0
    def __init__(self, n_classes, n_boxes):
        super(YOLOv2, self).__init__(
            ##### common layers for both pretrained layers and yolov2 #####
            conv1  = L.Convolution2D(3, 32, ksize=3, stride=1, pad=1, nobias=True),
            bn1    = L.BatchNormalization(32, use_beta=False, eps=2e-5),
            bias1  = L.Bias(shape=(32,)),
            conv2  = L.Convolution2D(32, 64, ksize=3, stride=1, pad=1, nobias=True),
            bn2    = L.BatchNormalization(64, use_beta=False, eps=2e-5),
            bias2  = L.Bias(shape=(64,)),
            conv3  = L.Convolution2D(64, 128, ksize=3, stride=1, pad=1, nobias=True),
            bn3    = L.BatchNormalization(128, use_beta=False, eps=2e-5),
            bias3  = L.Bias(shape=(128,)),
            conv4  = L.Convolution2D(128, 64, ksize=1, stride=1, pad=0, nobias=True),
            bn4    = L.BatchNormalization(64, use_beta=False, eps=2e-5),
            bias4  = L.Bias(shape=(64,)),
            conv5  = L.Convolution2D(64, 128, ksize=3, stride=1, pad=1, nobias=True),
            bn5    = L.BatchNormalization(128, use_beta=False, eps=2e-5),
            bias5  = L.Bias(shape=(128,)),
            conv6  = L.Convolution2D(128, 256, ksize=3, stride=1, pad=1, nobias=True),
            bn6    = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias6  = L.Bias(shape=(256,)),
            conv7  = L.Convolution2D(256, 128, ksize=1, stride=1, pad=0, nobias=True),
            bn7    = L.BatchNormalization(128, use_beta=False, eps=2e-5),
            bias7  = L.Bias(shape=(128,)),
            conv8  = L.Convolution2D(128, 256, ksize=3, stride=1, pad=1, nobias=True),
            bn8    = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias8  = L.Bias(shape=(256,)),
            conv9  = L.Convolution2D(256, 512, ksize=3, stride=1, pad=1, nobias=True),
            bn9    = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias9  = L.Bias(shape=(512,)),
            conv10 = L.Convolution2D(512, 256, ksize=1, stride=1, pad=0, nobias=True),
            bn10   = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias10 = L.Bias(shape=(256,)),
            conv11 = L.Convolution2D(256, 512, ksize=3, stride=1, pad=1, nobias=True),
            bn11   = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias11 = L.Bias(shape=(512,)),
            conv12 = L.Convolution2D(512, 256, ksize=1, stride=1, pad=0, nobias=True),
            bn12   = L.BatchNormalization(256, use_beta=False, eps=2e-5),
            bias12 = L.Bias(shape=(256,)),
            conv13 = L.Convolution2D(256, 512, ksize=3, stride=1, pad=1, nobias=True),
            bn13   = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias13 = L.Bias(shape=(512,)),
            conv14 = L.Convolution2D(512, 1024, ksize=3, stride=1, pad=1, nobias=True),
            bn14   = L.BatchNormalization(1024, use_beta=False, eps=2e-5),
            bias14 = L.Bias(shape=(1024,)),
            conv15 = L.Convolution2D(1024, 512, ksize=1, stride=1, pad=0, nobias=True),
            bn15   = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias15 = L.Bias(shape=(512,)),
            conv16 = L.Convolution2D(512, 1024, ksize=3, stride=1, pad=1, nobias=True),
            bn16   = L.BatchNormalization(1024, use_beta=False, eps=2e-5),
            bias16 = L.Bias(shape=(1024,)),
            conv17 = L.Convolution2D(1024, 512, ksize=1, stride=1, pad=0, nobias=True),
            bn17   = L.BatchNormalization(512, use_beta=False, eps=2e-5),
            bias17 = L.Bias(shape=(512,)),
            conv18 = L.Convolution2D(512, 1024, ksize=3, stride=1, pad=1, nobias=True),
            bn18   = L.BatchNormalization(1024, use_beta=False, eps=2e-5),
            bias18 = L.Bias(shape=(1024,)),

            ###### new layer
            conv19 = L.Convolution2D(1024, 1024, ksize=3, stride=1, pad=1, nobias=True),
            bn19   = L.BatchNormalization(1024, use_beta=False),
            bias19 = L.Bias(shape=(1024,)),
            conv20 = L.Convolution2D(1024, 1024, ksize=3, stride=1, pad=1, nobias=True),
            bn20   = L.BatchNormalization(1024, use_beta=False),
            bias20 = L.Bias(shape=(1024,)),
            conv21 = L.Convolution2D(3072, 1024, ksize=3, stride=1, pad=1, nobias=True),
            bn21   = L.BatchNormalization(1024, use_beta=False),
            bias21 = L.Bias(shape=(1024,)),
            conv22 = L.Convolution2D(1024, n_boxes * (5 + n_classes), ksize=1, stride=1, pad=0, nobias=True),
            bias22 = L.Bias(shape=(n_boxes * (5 + n_classes),)),
        )
        self.train = False
        self.finetune = False
        self.n_boxes = n_boxes
        self.n_classes = n_classes
Exemplo n.º 26
0
    def __init__(self):
        super().__init__()

        with self.init_scope():
            # NOTE: we cannot use Conv2DActiv here since we want to copy
            # the pretrained model, which requires an identical topology
            self.conv1_1 = L.Convolution2D(64, 3, pad=1)
            self.relu1_1 = lambda x: F.relu(x)
            self.conv1_2 = L.Convolution2D(64, 3, pad=1)
            self.relu1_2 = lambda x: F.relu(x)
            self.pool1 = lambda x: F.max_pooling_2d(x, 2)

            self.conv2_1 = L.Convolution2D(128, 3, pad=1)
            self.relu2_1 = lambda x: F.relu(x)
            self.conv2_2 = L.Convolution2D(128, 3, pad=1)
            self.relu2_2 = lambda x: F.relu(x)
            self.pool2 = lambda x: F.max_pooling_2d(x, 2)

            self.conv3_1 = L.Convolution2D(256, 3, pad=1)
            self.relu3_1 = lambda x: F.relu(x)
            self.conv3_2 = L.Convolution2D(256, 3, pad=1)
            self.relu3_2 = lambda x: F.relu(x)
            self.conv3_3 = L.Convolution2D(256, 3, pad=1)
            self.relu3_3 = lambda x: F.relu(x)
            self.pool3 = lambda x: F.max_pooling_2d(x, 2)

            self.conv4_1 = L.Convolution2D(512, 3, pad=1)
            self.relu4_1 = lambda x: F.relu(x)
            self.conv4_2 = L.Convolution2D(512, 3, pad=1)
            self.relu4_2 = lambda x: F.relu(x)
            self.conv4_3 = L.Convolution2D(512, 3, pad=1)
            self.relu4_3 = lambda x: F.relu(x)
            # NOTE: norm4 should be treated as ReLU in adaloss
            # self.norm4 = Normalize(512, initial=initializers.Constant(20))
            self.pool4 = lambda x: F.max_pooling_2d(x, 2)

            self.conv5_1 = L.Convolution2D(512, 3, pad=1)
            self.relu5_1 = lambda x: F.relu(x)
            self.conv5_2 = L.Convolution2D(512, 3, pad=1)
            self.relu5_2 = lambda x: F.relu(x)
            self.conv5_3 = L.Convolution2D(512, 3, pad=1)
            self.relu5_3 = lambda x: F.relu(x)
            self.pool5 = lambda x: F.max_pooling_2d(x, 3, stride=1, pad=1)

            self.conv6 = L.Convolution2D(1024, 3, pad=6, dilate=6)
            self.relu6 = lambda x: F.relu(x)
            self.conv7 = L.Convolution2D(1024, 1)
            self.relu7 = lambda x: F.relu(x)
Exemplo n.º 27
0
 def __init__(self):
     super(Generator, self).__init__(
         l0z=L.Linear(nz, 6 * 6 * 512, wscale=0.02 * math.sqrt(nz)),
         dc1=L.Deconvolution2D(512,
                               256,
                               4,
                               stride=2,
                               pad=1,
                               wscale=0.02 * math.sqrt(4 * 4 * 512)),
         dc2=L.Deconvolution2D(256,
                               128,
                               4,
                               stride=2,
                               pad=1,
                               wscale=0.02 * math.sqrt(4 * 4 * 256)),
         dc3=L.Deconvolution2D(128,
                               64,
                               4,
                               stride=2,
                               pad=1,
                               wscale=0.02 * math.sqrt(4 * 4 * 128)),
         dc4=L.Deconvolution2D(64,
                               3,
                               4,
                               stride=2,
                               pad=1,
                               wscale=0.02 * math.sqrt(4 * 4 * 64)),
         bn0l=L.BatchNormalization(6 * 6 * 512),
         bn0=L.BatchNormalization(512),
         bn1=L.BatchNormalization(256),
         bn2=L.BatchNormalization(128),
         bn3=L.BatchNormalization(64),
         c0=L.Convolution2D(3,
                            64,
                            4,
                            stride=2,
                            pad=1,
                            wscale=0.02 * math.sqrt(4 * 4 * 3)),
         c1=L.Convolution2D(64,
                            128,
                            4,
                            stride=2,
                            pad=1,
                            wscale=0.02 * math.sqrt(4 * 4 * 64)),
         c2=L.Convolution2D(128,
                            256,
                            4,
                            stride=2,
                            pad=1,
                            wscale=0.02 * math.sqrt(4 * 4 * 128)),
         c3=L.Convolution2D(256,
                            512,
                            4,
                            stride=2,
                            pad=1,
                            wscale=0.02 * math.sqrt(4 * 4 * 256)),
         l4l=L.Linear(6 * 6 * 512, nz,
                      wscale=0.02 * math.sqrt(6 * 6 * 512)),
         cbn0=L.BatchNormalization(64),
         cbn1=L.BatchNormalization(128),
         cbn2=L.BatchNormalization(256),
         cbn3=L.BatchNormalization(512),
     )
Exemplo n.º 28
0
    def create_network(self):
        params = self.params

        # stack causal blocks
        self.causal_conv_layers = []
        nobias = params.causal_conv_no_bias
        filter_width = params.causal_conv_filter_width
        ksize = (1, filter_width)

        channels = [(params.quantization_steps, params.causal_conv_channels[0])
                    ]
        channels += zip(params.causal_conv_channels[:-1],
                        params.causal_conv_channels[1:])

        for layer_index, (n_in, n_out) in enumerate(channels):
            std = math.sqrt(2.0 / (filter_width * filter_width * n_in))
            layer = DilatedConvolution1D(n_in,
                                         n_out,
                                         ksize,
                                         filter_width=filter_width,
                                         dilation=1,
                                         nobias=nobias,
                                         wscale=std)
            self.causal_conv_layers.append(layer)

        # stack residual blocks
        self.residual_blocks = []
        nobias_dilation = params.residual_conv_dilation_no_bias
        nobias_projection = params.residual_conv_projection_no_bias
        filter_width = params.residual_conv_filter_width
        n_in = params.causal_conv_channels[-1]
        n_softmax_in = params.softmax_conv_channels[0]

        residual_conv_dilations = []
        dilation = 1
        for _ in params.residual_conv_channels:
            residual_conv_dilations.append(dilation)
            dilation *= filter_width

        for stack in xrange(params.residual_num_blocks):
            residual_conv_layers = []
            for layer_index in xrange(len(params.residual_conv_channels)):
                residual_layer = ResidualConvLayer()
                n_out = params.residual_conv_channels[layer_index]
                # filter
                if layer_index == 0:
                    ksize = (1, filter_width)
                    shape_w = (n_out, n_in, 1, filter_width)
                else:
                    # set filter_width to filter's height to remove transpose operation in DilatedConvolution1D
                    ksize = (filter_width, 1)
                    shape_w = (n_out, n_in, filter_width, 1)

                std = math.sqrt(2.0 / (filter_width * filter_width * n_in))

                # filter
                residual_layer.wf = DilatedConvolution1D(
                    n_in,
                    n_out,
                    ksize,
                    filter_width=filter_width,
                    dilation=filter_width**layer_index,
                    nobias=nobias_dilation,
                    wscale=std)

                # gate
                residual_layer.wg = DilatedConvolution1D(
                    n_in,
                    n_out,
                    ksize,
                    filter_width=filter_width,
                    dilation=filter_width**layer_index,
                    nobias=nobias_dilation,
                    wscale=std)

                # projection
                std = math.sqrt(2.0 / (filter_width * filter_width * n_out))
                residual_layer.projection_block = L.Convolution2D(
                    n_out,
                    n_in,
                    1,
                    stride=1,
                    pad=0,
                    nobias=nobias_projection,
                    wscale=std)
                residual_layer.projection_softmax = L.Convolution2D(
                    n_out,
                    n_softmax_in,
                    1,
                    stride=1,
                    pad=0,
                    nobias=nobias_projection,
                    wscale=std)

                # residual conv block
                residual_conv_layers.append(residual_layer)
            self.residual_blocks.append(residual_conv_layers)

        # softmax block
        self.softmax_conv_layers = []
        nobias = params.softmax_conv_no_bias
        channels = zip(params.softmax_conv_channels[:-1],
                       params.softmax_conv_channels[1:])
        for i, (n_in, n_out) in enumerate(channels):
            self.softmax_conv_layers.append(
                L.Convolution2D(n_in,
                                n_out,
                                ksize=1,
                                stride=1,
                                pad=0,
                                nobias=nobias,
                                wscale=math.sqrt(2.0 / n_out)))
Exemplo n.º 29
0
 def __init__(self):
     super(VGGNet, self).__init__(conv1_1=L.Convolution2D(3,
                                                          64,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv1_2=L.Convolution2D(64,
                                                          64,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv2_1=L.Convolution2D(64,
                                                          128,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv2_2=L.Convolution2D(128,
                                                          128,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv3_1=L.Convolution2D(128,
                                                          256,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv3_2=L.Convolution2D(256,
                                                          256,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv3_3=L.Convolution2D(256,
                                                          256,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv4_1=L.Convolution2D(256,
                                                          512,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv4_2=L.Convolution2D(512,
                                                          512,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv4_3=L.Convolution2D(512,
                                                          512,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv5_1=L.Convolution2D(512,
                                                          512,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv5_2=L.Convolution2D(512,
                                                          512,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  conv5_3=L.Convolution2D(512,
                                                          512,
                                                          3,
                                                          stride=1,
                                                          pad=1),
                                  fc6=L.Linear(7 * 7 * 512, 4096),
                                  fc7=L.Linear(4096, 4096),
                                  fc8=L.Linear(4096, 9))
Exemplo n.º 30
0
    def __init__(self):
        super().__init__(
            conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=1),
            conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1),
            conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1),
            conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1),
            conv3_1=L.Convolution2D(128, 256, 3, stride=1, pad=1),
            conv3_2=L.Convolution2D(256, 256, 3, stride=1, pad=1),
            conv3_3=L.Convolution2D(256, 256, 3, stride=1, pad=1),
            conv4_1=L.Convolution2D(256, 512, 3, stride=1, pad=1),
            conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1),
            fc6=L.Linear(25088, 4096),
            fc7=L.Linear(4096, 4096),
            fc8=L.Linear(4096, 1000)
        )

        self.conv_blocks = [
            [self.conv1_1, self.conv1_2],
            [self.conv2_1, self.conv2_2],
            [self.conv3_1, self.conv3_2, self.conv3_3],
            [self.conv4_1, self.conv4_2, self.conv4_3],
            [self.conv5_1, self.conv5_2, self.conv5_3]
        ]
        self.deconv_blocks= []

        # Keep track of the pooling indices inside each function instance
        self.mps = [F.MaxPooling2D(2, 2, use_cudnn=False) for _ in self.conv_blocks]