def build(self, x, class_num, channel, wd, train=True):
        self.conv1_1 = _conv_layer(x, [3, 3, channel, 64], 'conv1_1')
        self.conv1_2 = _conv_layer(self.conv1_1, [3, 3, 64, 64], 'conv1_2')
        self.pooling1 = _pooling_layer(self.conv1_2, 'pooling1')

        self.conv2_1 = _conv_layer(self.pooling1, [3, 3, 64, 128], 'conv2_1')
        self.conv2_2 = _conv_layer(self.conv2_1, [3, 3, 128, 128], 'conv2_2')
        self.pooling2 = _pooling_layer(self.conv2_2, 'pooling2')

        self.conv3_1 = _conv_layer(self.pooling2, [3, 3, 128, 256], 'conv3_1')
        self.conv3_2 = _conv_layer(self.conv3_1, [3, 3, 256, 256], 'conv3_2')
        self.conv3_3 = _conv_layer(self.conv3_2, [3, 3, 256, 256], 'conv3_3')
        self.pooling3 = _pooling_layer(self.conv3_3, 'pooling3')

        self.conv4_1 = _conv_layer(self.pooling3, [3, 3, 256, 512], 'conv4_1')
        self.conv4_2 = _conv_layer(self.conv4_1, [3, 3, 512, 512], 'conv4_2')
        self.conv4_3 = _conv_layer(self.conv4_2, [3, 3, 512, 512], 'conv4_3')
        self.pooling4 = _pooling_layer(self.conv4_3, 'pooling4')

        self.conv5_1 = _conv_layer(self.pooling4, [3, 3, 512, 512], 'conv5_1')
        self.conv5_2 = _conv_layer(self.conv5_1, [3, 3, 512, 512], 'conv5_2')
        self.conv5_3 = _conv_layer(self.conv5_2, [3, 3, 512, 512], 'conv5_3')
        self.pooling5 = _pooling_layer(self.conv5_3, 'pooling5')

        self.conv6 = _conv_layer(self.pooling5, [7, 7, 512, 4096], 'conv6')
        if train:
            self.conv6 = tf.nn.dropout(self.conv6, 0.5)
        self.conv7 = _conv_layer(self.conv6, [1, 1, 4096, 4096], 'conv7')
        if train:
            self.conv7 = tf.nn.dropout(self.conv7, 0.5)
        self.score_fr = _conv_layer_without_relu(self.conv7, [1, 1, 4096, 64],
                                                 'conv7_1x1conv',
                                                 wd=wd)

        self.pooling4_conv = _conv_layer_without_relu(self.pooling4,
                                                      [1, 1, 512, 64],
                                                      'pool4_1x1conv',
                                                      wd=wd)

        self.pooling3_conv = _conv_layer_without_relu(self.pooling3,
                                                      [1, 1, 256, 64],
                                                      'pool3_1x1conv',
                                                      wd=wd)

        self.upconv5 = UpSampling2D((2, 2))(self.score_fr)  #1/16
        self.upconv4 = UpSampling2D((2, 2))(self.pooling4_conv)  #1/8
        self.upconv3 = UpSampling2D((8, 8))(self.pooling3_conv)  #1
        self.conv5_feature = self.Dense_decoder_feature_generation(
            self.upconv5)

        self.upconv4 = self.fusion1(self.conv5_feature, self.upconv4)  #1/8
        self.conv4_feature = self.Dense_decoder_feature_generation(
            self.upconv4)

        self.upconv3 = self.fusion2(self.conv5_feature, self.conv4_feature,
                                    self.upconv3)
        self.conv3_feature = self.Dense_decoder_feature_generation(
            self.upconv3)

        self.upscore = conv_bn_relu(
            self.conv3_feature,
            [3, 3, np.shape(self.conv3_feature)[3], 64], 1)
        self.upscore = conv_bn_relu(self.upscore, [3, 3, 64, class_num], 1)

        return self.upscore
Esempio n. 2
0
    def build(self, x, class_num, channel, wd, train=True):
        self.conv1_1 = _conv_layer(x, [3, 3, channel, 64], 'conv1_1')
        self.conv1_2 = _conv_layer(self.conv1_1, [3, 3, 64, 64], 'conv1_2')
        self.pooling1 = _pooling_layer(self.conv1_2, 'pooling1')

        self.conv2_1 = _conv_layer(self.pooling1, [3, 3, 64, 128], 'conv2_1')
        self.conv2_2 = _conv_layer(self.conv2_1, [3, 3, 128, 128], 'conv2_2')
        self.pooling2 = _pooling_layer(self.conv2_2, 'pooling2')

        self.conv3_1 = _conv_layer(self.pooling2, [3, 3, 128, 256], 'conv3_1')
        self.conv3_2 = _conv_layer(self.conv3_1, [3, 3, 256, 256], 'conv3_2')
        self.conv3_3 = _conv_layer(self.conv3_2, [3, 3, 256, 256], 'conv3_3')
        self.pooling3 = _pooling_layer(self.conv3_3, 'pooling3')

        self.conv4_1 = _conv_layer(self.pooling3, [3, 3, 256, 512], 'conv4_1')
        self.conv4_2 = _conv_layer(self.conv4_1, [3, 3, 512, 512], 'conv4_2')
        self.conv4_3 = _conv_layer(self.conv4_2, [3, 3, 512, 512], 'conv4_3')
        self.pooling4 = _pooling_layer(self.conv4_3, 'pooling4')

        self.conv5_1 = _conv_layer(self.pooling4, [3, 3, 512, 512], 'conv5_1')
        self.conv5_2 = _conv_layer(self.conv5_1, [3, 3, 512, 512], 'conv5_2')
        self.conv5_3 = _conv_layer(self.conv5_2, [3, 3, 512, 512], 'conv5_3')
        self.pooling5 = _pooling_layer(self.conv5_3, 'pooling5')

        self.conv6 = _conv_layer(self.pooling5, [7, 7, 512, 4096], 'conv6')
        if train:
            self.conv6 = tf.nn.dropout(self.conv6, 0.5)
        self.conv7 = _conv_layer(self.conv6, [1, 1, 4096, 4096], 'conv7')
        if train:
            self.conv7 = tf.nn.dropout(self.conv7, 0.5)
        self.score_fr = _conv_layer_without_relu(self.conv7,
                                                 [1, 1, 4096, class_num],
                                                 'conv7_1x1conv',
                                                 wd=wd)

        self.pooling4_conv = _conv_layer_without_relu(self.pooling4,
                                                      [1, 1, 512, class_num],
                                                      'pool4_1x1conv',
                                                      wd=wd)

        self.pooling3_conv = _conv_layer_without_relu(self.pooling3,
                                                      [1, 1, 256, class_num],
                                                      'pool3_1x1conv',
                                                      wd=wd)

        self.upscore = _upscore_layer(self.score_fr,
                                      shape=tf.shape(self.pooling4_conv),
                                      ksize=4,
                                      stride=2,
                                      num_class=class_num,
                                      name='upscore')

        self.fuse_pool4 = tf.add(self.pooling4_conv,
                                 self.upscore,
                                 name='fuse_pool4')

        self.fuse_pool4_upscore = _upscore_layer(self.fuse_pool4,
                                                 shape=tf.shape(
                                                     self.pooling3_conv),
                                                 ksize=4,
                                                 stride=2,
                                                 num_class=class_num,
                                                 name='fuse_pool4_upscore')

        self.fuse_pool3 = tf.add(self.pooling3_conv,
                                 self.fuse_pool4_upscore,
                                 name='fuse_pool3')

        self.upscore = _upscore_layer(self.fuse_pool3,
                                      shape=tf.shape(x),
                                      ksize=16,
                                      stride=8,
                                      num_class=class_num,
                                      name='final_upscore')

        return self.upscore
Esempio n. 3
0
    def build(self, x, class_num, channel, wd, train=True):
        # x: [batch_size,rows,cols,channel] batch_size = 256

        self.conv1_1 = _conv_layer(x, [3, 3, channel, 64], 'conv1_1')
        self.conv1_2 = _conv_layer(self.conv1_1, [3, 3, 64, 64], 'conv1_2')
        self.pooling1 = _pooling_layer(self.conv1_2, 'pooling1')

        self.conv2_1 = _conv_layer(self.pooling1, [3, 3, 64, 128], 'conv2_1')
        self.conv2_2 = _conv_layer(self.conv2_1, [3, 3, 128, 128], 'conv2_2')
        self.pooling2 = _pooling_layer(self.conv2_2, 'pooling2')

        self.conv3_1 = _conv_layer(self.pooling2, [3, 3, 128, 256], 'conv3_1')
        self.conv3_2 = _conv_layer(self.conv3_1, [3, 3, 256, 256], 'conv3_2')
        self.conv3_3 = _conv_layer(self.conv3_2, [3, 3, 256, 256], 'conv3_3')
        self.pooling3 = _pooling_layer(self.conv3_3, 'pooling3')

        self.conv4_1 = _conv_layer(self.pooling3, [3, 3, 256, 512], 'conv4_1')
        self.conv4_2 = _conv_layer(self.conv4_1, [3, 3, 512, 512], 'conv4_2')
        self.conv4_3 = _conv_layer(self.conv4_2, [3, 3, 512, 512], 'conv4_3')
        self.pooling4 = _pooling_layer(self.conv4_3, 'pooling4')

        self.conv5_1 = _conv_layer(self.pooling4, [3, 3, 512, 512], 'conv5_1')
        self.conv5_2 = _conv_layer(self.conv5_1, [3, 3, 512, 512], 'conv5_2')
        self.conv5_3 = _conv_layer(self.conv5_2, [3, 3, 512, 512], 'conv5_3')
        self.pooling5 = _pooling_layer(self.conv5_3, 'pooling5')

        self.conv6 = _conv_layer(self.pooling5, [7, 7, 512, 4096], 'conv6')
        if train:
            self.conv6 = tf.nn.dropout(self.conv6, 0.5)
        self.conv7 = _conv_layer(self.conv6, [1, 1, 4096, 4096], 'conv7')
        if train:
            self.conv7 = tf.nn.dropout(self.conv7, 0.5)
        self.score_fr = _conv_layer_without_relu(self.conv7,
                                                 [1, 1, 4096, class_num],
                                                 'conv7_1x1conv',
                                                 wd=wd)  #[256,4,8,2]

        self.upscore = _upscore_layer(self.score_fr,
                                      shape=tf.shape(x),
                                      ksize=64,
                                      stride=32,
                                      num_class=class_num,
                                      name='final_upscore')

        return self.upscore
Esempio n. 4
0
    def build(self, x, class_num, channel, wd, train=True):
        # x: [batch_size,rows,cols,channel]
        # a = tf.expand_dims(x, 0)
        # self.lstm1 = ConvLSTM2D(filters=channel,kernel_size=(1,1),padding='same',return_sequences=True)(a)
        # i = tf.squeeze(self.lstm1,[0])

        self.conv1_1 = _conv_layer(x, [3, 3, channel, 64], 'conv1_1')
        self.conv1_2 = _conv_layer(self.conv1_1, [3, 3, 64, 64], 'conv1_2')
        self.pooling1 = _pooling_layer(self.conv1_2, 'pooling1')

        self.conv2_1 = _conv_layer(self.pooling1, [3, 3, 64, 128], 'conv2_1')
        self.conv2_2 = _conv_layer(self.conv2_1, [3, 3, 128, 128], 'conv2_2')
        self.pooling2 = _pooling_layer(self.conv2_2, 'pooling2')

        self.conv3_1 = _conv_layer(self.pooling2, [3, 3, 128, 256], 'conv3_1')
        self.conv3_2 = _conv_layer(self.conv3_1, [3, 3, 256, 256], 'conv3_2')
        self.conv3_3 = _conv_layer(self.conv3_2, [3, 3, 256, 256], 'conv3_3')
        self.pooling3 = _pooling_layer(self.conv3_3, 'pooling3')

        self.conv4_1 = _conv_layer(self.pooling3, [3, 3, 256, 512], 'conv4_1')
        self.conv4_2 = _conv_layer(self.conv4_1, [3, 3, 512, 512], 'conv4_2')
        self.conv4_3 = _conv_layer(self.conv4_2, [3, 3, 512, 512], 'conv4_3')
        self.pooling4 = _pooling_layer(self.conv4_3, 'pooling4')

        self.conv5_1 = _conv_layer(self.pooling4, [3, 3, 512, 512], 'conv5_1')
        self.conv5_2 = _conv_layer(self.conv5_1, [3, 3, 512, 512], 'conv5_2')
        self.conv5_3 = _conv_layer(self.conv5_2, [3, 3, 512, 512], 'conv5_3')
        self.pooling5 = _pooling_layer(self.conv5_3, 'pooling5')

        self.conv6 = _conv_layer(self.pooling5, [7, 7, 512, 4096], 'conv6')
        if train:
            self.conv6 = tf.nn.dropout(self.conv6, 0.5)
        self.conv7 = _conv_layer(self.conv6, [1, 1, 4096, 4096], 'conv7')
        if train:
            self.conv7 = tf.nn.dropout(self.conv7, 0.5)
        self.score_fr = _conv_layer_without_relu(self.conv7,
                                                 [1, 1, 4096, class_num],
                                                 'conv7_1x1conv',
                                                 wd=wd)
        #reshape score_fr ==> [(samples,time, rows, cols, channels)]
        # self.score_fr = tf.expand_dims(self.score_fr, 0)
        # self.lstm1 = ConvLSTM2D(filters=class_num,kernel_size=(1,1),padding='same',return_sequences=True)(self.score_fr)

        self.pooling4_conv = _conv_layer_without_relu(self.pooling4,
                                                      [1, 1, 512, class_num],
                                                      'pool4_1x1conv',
                                                      wd=wd)
        # reshape pooling4_conv ==> [(samples,time, rows, cols, channels)]
        # self.pooling4_conv = tf.expand_dims(self.pooling4_conv, 0)
        # self.lstm2 = ConvLSTM2D(filters=class_num, kernel_size=(1, 1), padding='same', return_sequences=True)(self.pooling4_conv)

        self.pooling3_conv = _conv_layer_without_relu(self.pooling3,
                                                      [1, 1, 256, class_num],
                                                      'pool3_1x1conv',
                                                      wd=wd)
        # reshape pooling3_conv ==> [(samples,time, rows, cols, channels)]
        # self.pooling3_conv = tf.expand_dims(self.pooling3_conv, 0)
        # self.lstm3 = ConvLSTM2D(filters=class_num, kernel_size=(1, 1), padding='same', return_sequences=True)(self.pooling3_conv)

        #reshape  lstm1,lstm2,lstm3 ,then fuse and upsample

        # self.score_fr = tf.squeeze(self.lstm1, [0])
        # self.pooling4_conv = tf.squeeze(self.lstm2, [0])
        # self.pooling3_conv = tf.squeeze(self.lstm3, [0])

        self.upscore = _upscore_layer(self.score_fr,
                                      shape=tf.shape(self.pooling4_conv),
                                      ksize=4,
                                      stride=2,
                                      num_class=class_num,
                                      name='upscore')

        self.fuse_pool4 = tf.add(self.pooling4_conv,
                                 self.upscore,
                                 name='fuse_pool4')

        self.fuse_pool4_upscore = _upscore_layer(self.fuse_pool4,
                                                 shape=tf.shape(
                                                     self.pooling3_conv),
                                                 ksize=4,
                                                 stride=2,
                                                 num_class=class_num,
                                                 name='fuse_pool4_upscore')

        self.fuse_pool3 = tf.add(self.pooling3_conv,
                                 self.fuse_pool4_upscore,
                                 name='fuse_pool3')

        self.upscore = _upscore_layer(self.fuse_pool3,
                                      shape=tf.shape(x),
                                      ksize=16,
                                      stride=8,
                                      num_class=class_num,
                                      name='final_upscore')

        return self.upscore
Esempio n. 5
0
    def build(self, x, class_num, channel, wd, train=True):
        #conv1
        self.conv1_1 = _conv_layer(x, [3,3,channel, 64], 'conv1_1')
        self.conv1_2 = _conv_layer(self.conv1_1, [3,3,64,64], 'conv1_2')
        self.pooling1 = _pooling_layer(self.conv1_2, 'pooling1')
        print("pooling1:", np.shape(self.pooling1))
        self.conv2_1 = _conv_layer(self.pooling1, [3, 3, 64, 64], 'conv2_1')
        self.conv2_2 = _conv_layer(self.conv2_1, [3, 3, 64, 64], 'conv2_2')
        self.pooling2 = _pooling_layer(self.conv2_2, 'pooling2')
        print("pooling2: ", np.shape(self.pooling2))
        #conv2_x  3 blocks
        self.conv2_block1 = bottleneck_block("conv2_block1", self.pooling2, 64, first_block=True, change_stride=False)
        self.conv2_block2 = bottleneck_block("conv2_block2", self.conv2_block1, 64)
        self.conv2_block3 = bottleneck_block("conv2_block3", self.conv2_block2, 64)
        #conv3_x  4 blocks
        self.conv3_block1 = bottleneck_block("conv3_block1", self.conv2_block3, 128, change_stride=True)
        self.conv3_block2 = bottleneck_block("conv3_block2", self.conv3_block1, 128)
        self.conv3_block3 = bottleneck_block("conv3_block3", self.conv3_block2, 128)
        self.conv3_block4 = bottleneck_block("conv3_block4", self.conv3_block3, 128)
        print("conv3_block4: ", np.shape(self.conv3_block4))
        #conv4_x  23 blocks
        self.conv4_block1 = bottleneck_block("conv4_block1", self.conv3_block4, 256, change_stride=True)
        self.conv4_block2 = bottleneck_block("conv4_block2", self.conv4_block1, 256)
        self.conv4_block3 = bottleneck_block("conv4_block3", self.conv4_block2, 256)
        self.conv4_block4 = bottleneck_block("conv4_block4", self.conv4_block3, 256)
        self.conv4_block5 = bottleneck_block("conv4_block5", self.conv4_block4, 256)
        self.conv4_block6 = bottleneck_block("conv4_block6", self.conv4_block5, 256)
        self.conv4_block7 = bottleneck_block("conv4_block7", self.conv4_block6, 256)
        self.conv4_block8 = bottleneck_block("conv4_block8", self.conv4_block7, 256)
        self.conv4_block9 = bottleneck_block("conv4_block9", self.conv4_block8, 256)
        self.conv4_block10 = bottleneck_block("conv4_block10", self.conv4_block9, 256)
        self.conv4_block11 = bottleneck_block("conv4_block11", self.conv4_block10, 256)
        self.conv4_block12 = bottleneck_block("conv4_block12", self.conv4_block11, 256)
        self.conv4_block13 = bottleneck_block("conv4_block13", self.conv4_block12, 256)
        self.conv4_block14 = bottleneck_block("conv4_block14", self.conv4_block13, 256)
        self.conv4_block15 = bottleneck_block("conv4_block15", self.conv4_block14, 256)
        self.conv4_block16 = bottleneck_block("conv4_block16", self.conv4_block15, 256)
        self.conv4_block17 = bottleneck_block("conv4_block17", self.conv4_block16, 256)
        self.conv4_block18 = bottleneck_block("conv4_block18", self.conv4_block17, 256)
        self.conv4_block19 = bottleneck_block("conv4_block19", self.conv4_block18, 256)
        self.conv4_block20 = bottleneck_block("conv4_block20", self.conv4_block19, 256)
        self.conv4_block21 = bottleneck_block("conv4_block21", self.conv4_block20, 256)
        self.conv4_block22 = bottleneck_block("conv4_block22", self.conv4_block21, 256)
        self.conv4_block23 = bottleneck_block("conv4_block23", self.conv4_block22, 256)
        print(np.shape(self.conv4_block23))
        #conv5_x  3 blocks
        self.conv5_block1 = bottleneck_block("conv5_block1", self.conv4_block23, 512, change_stride=True)
        self.conv5_block2 = bottleneck_block("conv5_block2", self.conv5_block1, 512)
        self.conv5_block3 = bottleneck_block("conv5_block3", self.conv5_block2, 512)
        print(np.shape(self.conv5_block3))

        #1/32
        self.score_32 = _conv_layer_without_relu(self.conv5_block3, [1,1,4*512,class_num], "1x1conv_1", wd=wd)
        #1/16
        self.score_16 = _conv_layer_without_relu(self.conv4_block23, [1,1,4*256,class_num], "1x1conv_2", wd=wd)
        #1/8
        self.score_8 = _conv_layer_without_relu(self.conv3_block4, [1,1,4*128,class_num], "1x1conv_3", wd=wd)

        self.upscore1 = _upscore_layer(self.score_32, shape=tf.shape(self.score_16), ksize=4, stride=2, num_class=class_num, name="upscore1")
        self.fuse1 = tf.add(self.score_16, self.upscore1, name="fuse1")
        self.upscore2 = _upscore_layer(self.fuse1, shape=tf.shape(self.score_8), ksize=4, stride=2, num_class=class_num, name="upscore2")
        self.fuse2 = tf.add(self.score_8, self.upscore2, name="fuse2")
        self.upscore = _upscore_layer(self.fuse2, shape=tf.shape(x), ksize=16, stride=8, num_class=class_num, name="final_upscore")

        return self.upscore
    def build(self, x, class_num, channel, wd, train=True):

        self.conv1_1 = _conv_layer(x, [3, 3, channel, 64], 'conv1_1')
        self.conv1_2 = _conv_layer(self.conv1_1, [3, 3, 64, 64], 'conv1_2')
        self.pooling1 = _pooling_layer(self.conv1_2, 'pooling1')

        self.conv2_1 = _conv_layer(self.pooling1, [3, 3, 64, 128], 'conv2_1')
        self.conv2_2 = _conv_layer(self.conv2_1, [3, 3, 128, 128], 'conv2_2')
        self.pooling2 = _pooling_layer(self.conv2_2, 'pooling2')

        # self.inception_block2_1 = _inception_layer(self.pooling1, in_c=64, out_1=32, out_21=32, out_22=32, out_31=32, out_32=64, out_33=64)
        # self.inception_block2_2 = _inception_layer(self.inception_block2_1, in_c=128, out_1=32, out_21=32, out_22=32, out_31=32,
        #                                            out_32=64, out_33=64)
        # self.pooling2 = _pooling_layer(self.inception_block2_2, 'pooling2')

        # self.conv3_1 = _conv_layer(self.pooling2, [3, 3, 128, 256], 'conv3_1')
        # self.conv3_2 = _conv_layer(self.conv3_1, [3, 3, 256, 256], 'conv3_2')
        # self.conv3_3 = _conv_layer(self.conv3_2, [3, 3, 256, 256], 'conv3_3')
        # self.pooling3 = _pooling_layer(self.conv3_3, 'pooling3')

        self.inception_block3_1 = _inception_layer(
            'inception3_1',
            self.pooling2,
            in_c=128,
            out_1=64,
            out_21=64,
            out_22=64,
            out_31=64,
            out_32=128,
            out_33=64,
            out_41=64,
            out_42=128,
            out_43=64)  # output channel 256
        self.inception_block3_2 = _inception_layer(
            'inception3_2',
            self.inception_block3_1,
            in_c=256,
            out_1=64,
            out_21=64,
            out_22=64,
            out_31=64,
            out_32=128,
            out_33=64,
            out_41=64,
            out_42=128,
            out_43=64)  # output channel 256
        self.inception_block3_3 = _inception_layer(
            'inception3_3',
            self.inception_block3_2,
            in_c=256,
            out_1=64,
            out_21=64,
            out_22=64,
            out_31=64,
            out_32=128,
            out_33=64,
            out_41=64,
            out_42=128,
            out_43=64)  # output channel 256
        self.pooling3 = _pooling_layer(self.inception_block3_3, 'pooling3')

        self.inception_block4_1 = _inception_layer('inception4_1',
                                                   self.pooling3,
                                                   in_c=256,
                                                   out_1=128,
                                                   out_21=128,
                                                   out_22=128,
                                                   out_31=128,
                                                   out_32=256,
                                                   out_33=128,
                                                   out_41=128,
                                                   out_42=256,
                                                   out_43=128)  # output 512
        self.inception_block4_2 = _inception_layer('inception4_2',
                                                   self.inception_block4_1,
                                                   in_c=512,
                                                   out_1=128,
                                                   out_21=128,
                                                   out_22=128,
                                                   out_31=128,
                                                   out_32=256,
                                                   out_33=128,
                                                   out_41=128,
                                                   out_42=256,
                                                   out_43=128)  # output 512
        self.inception_block4_3 = _inception_layer('inception4_3',
                                                   self.inception_block4_2,
                                                   in_c=512,
                                                   out_1=128,
                                                   out_21=128,
                                                   out_22=128,
                                                   out_31=128,
                                                   out_32=256,
                                                   out_33=128,
                                                   out_41=128,
                                                   out_42=256,
                                                   out_43=128)  # output 512
        self.pooling4 = _pooling_layer(self.inception_block4_3, 'pooling4')

        self.inception_block5_1 = _inception_layer('inception5_1',
                                                   self.pooling4,
                                                   in_c=512,
                                                   out_1=128,
                                                   out_21=128,
                                                   out_22=128,
                                                   out_31=128,
                                                   out_32=256,
                                                   out_33=128,
                                                   out_41=128,
                                                   out_42=256,
                                                   out_43=128)  # output 512
        self.inception_block5_2 = _inception_layer('inception5_2',
                                                   self.inception_block5_1,
                                                   in_c=512,
                                                   out_1=128,
                                                   out_21=128,
                                                   out_22=128,
                                                   out_31=128,
                                                   out_32=256,
                                                   out_33=128,
                                                   out_41=128,
                                                   out_42=256,
                                                   out_43=128)  # output 512
        self.inception_block5_3 = _inception_layer('inception5_3',
                                                   self.inception_block5_2,
                                                   in_c=512,
                                                   out_1=128,
                                                   out_21=128,
                                                   out_22=128,
                                                   out_31=128,
                                                   out_32=256,
                                                   out_33=128,
                                                   out_41=128,
                                                   out_42=256,
                                                   out_43=128)  # output 512
        self.pooling5 = _pooling_layer(self.inception_block5_3, 'pooling5')

        self.conv6 = _conv_layer(self.pooling5, [7, 7, 512, 4096], 'conv6')
        if train:
            self.conv6 = tf.nn.dropout(self.conv6, 0.5)
        self.conv7 = _conv_layer(self.conv6, [1, 1, 4096, 4096], 'conv7')
        if train:
            self.conv7 = tf.nn.dropout(self.conv7, 0.5)
        self.score_fr = _conv_layer_without_relu(self.conv7, [1, 1, 4096, 64],
                                                 'conv7_1x1conv',
                                                 wd=wd)

        self.pooling4_conv = _conv_layer_without_relu(self.pooling4,
                                                      [1, 1, 512, 64],
                                                      'pool4_1x1conv',
                                                      wd=wd)

        self.pooling3_conv = _conv_layer_without_relu(self.pooling3,
                                                      [1, 1, 256, 64],
                                                      'pool3_1x1conv',
                                                      wd=wd)

        self.upconv5 = UpSampling2D((2, 2))(self.score_fr)  #1/16
        self.upconv4 = UpSampling2D((2, 2))(self.pooling4_conv)  #1/8
        self.upconv3 = UpSampling2D((8, 8))(self.pooling3_conv)  #1
        self.conv5_feature = self.Dense_decoder_feature_generation(
            self.upconv5, name="gen1")

        self.upconv4 = self.fusion1(self.conv5_feature, self.upconv4)  #1/8
        self.conv4_feature = self.Dense_decoder_feature_generation(
            self.upconv4, name="gen2")

        self.upconv3 = self.fusion2(self.conv5_feature, self.conv4_feature,
                                    self.upconv3)
        self.conv3_feature = self.Dense_decoder_feature_generation(
            self.upconv3, name="gen3")

        self.upscore = conv_bn_relu(
            self.conv3_feature,
            [3, 3, np.shape(self.conv3_feature)[3], 64],
            1,
            name="final1")
        self.upscore = conv_bn_relu(self.upscore, [3, 3, 64, class_num],
                                    1,
                                    name="final2")

        return self.upscore
    def build(self, x, class_num, channel, wd, train=True):
        #conv1
        self.conv1_1 = _conv_layer(x, [3, 3, channel, 64], 'conv1_1')
        self.conv1_2 = _conv_layer(self.conv1_1, [3, 3, 64, 64], 'conv1_2')
        self.pooling1 = _pooling_layer(self.conv1_2, 'pooling1')
        print("pooling1:", np.shape(self.pooling1))
        self.conv2_1 = _conv_layer(self.pooling1, [3, 3, 64, 64], 'conv2_1')
        self.conv2_2 = _conv_layer(self.conv2_1, [3, 3, 64, 64], 'conv2_2')
        self.pooling2 = _pooling_layer(self.conv2_2, 'pooling2')
        print("pooling2: ", np.shape(self.pooling2))
        #conv2_x   3 blocks
        self.conv2_block1 = residual_block("conv2_block1", self.pooling2, 64,
                                           True)
        self.conv2_block2 = residual_block("conv2_block2", self.conv2_block1,
                                           64)
        self.conv2_block3 = residual_block("conv2_block3", self.conv2_block2,
                                           64)
        #conv3_x   4 blocks
        self.conv3_block1 = residual_block("conv3_block1", self.conv2_block3,
                                           128)
        self.conv3_block2 = residual_block("conv3_block2", self.conv3_block1,
                                           128)
        self.conv3_block3 = residual_block("conv3_block3", self.conv3_block2,
                                           128)
        self.conv3_block4 = residual_block("conv3_block4", self.conv3_block3,
                                           128)  #1/8
        print("conv3_block4: ", np.shape(self.conv3_block4))
        #conv4_x   6 blocks
        self.conv4_block1 = residual_block("conv4_block1", self.conv3_block4,
                                           256)
        self.conv4_block2 = residual_block("conv4_block2", self.conv4_block1,
                                           256)
        self.conv4_block3 = residual_block("conv4_block3", self.conv4_block2,
                                           256)
        self.conv4_block4 = residual_block("conv4_block4", self.conv4_block3,
                                           256)
        self.conv4_block5 = residual_block("conv4_block5", self.conv4_block4,
                                           256)
        self.conv4_block6 = residual_block("conv4_block6", self.conv4_block5,
                                           256)  #1/16
        print(np.shape(self.conv4_block6))
        #conv5_x   3 blocks
        self.conv5_block1 = residual_block("conv5_block1", self.conv4_block6,
                                           512)
        self.conv5_block2 = residual_block("conv5_block2", self.conv5_block1,
                                           512)
        self.conv5_block3 = residual_block("conv5_block3", self.conv5_block2,
                                           512)  #1/32
        print(np.shape(self.conv5_block3))
        #1/32
        self.score_32 = _conv_layer_without_relu(self.conv5_block3,
                                                 [1, 1, 512, class_num],
                                                 "1x1conv_1",
                                                 wd=wd)
        #1/16
        self.score_16 = _conv_layer_without_relu(self.conv4_block6,
                                                 [1, 1, 256, class_num],
                                                 "1x1conv_2",
                                                 wd=wd)
        #1/8
        self.score_8 = _conv_layer_without_relu(self.conv3_block4,
                                                [1, 1, 128, class_num],
                                                "1x1conv_3",
                                                wd=wd)

        self.upscore1 = _upscore_layer(self.score_32,
                                       shape=tf.shape(self.score_16),
                                       ksize=4,
                                       stride=2,
                                       num_class=class_num,
                                       name="upscore1")
        self.fuse1 = tf.add(self.score_16, self.upscore1, name="fuse1")
        self.upscore2 = _upscore_layer(self.fuse1,
                                       shape=tf.shape(self.score_8),
                                       ksize=4,
                                       stride=2,
                                       num_class=class_num,
                                       name="upscore2")
        self.fuse2 = tf.add(self.score_8, self.upscore2, name="fuse2")
        self.upscore = _upscore_layer(self.fuse2,
                                      shape=tf.shape(x),
                                      ksize=16,
                                      stride=8,
                                      num_class=class_num,
                                      name="final_upscore")

        return self.upscore