コード例 #1
0
    def __call__(self, input):
        with tf.variable_scope(self.name, reuse=self.reuse):
            input = ly.fc(input, 7 * 7 * 128, name='fc_0')
            input = ly.bn_layer(input, name='bn_0')
            input = tf.nn.leaky_relu(input)

            input = tf.reshape(input, (-1, 7, 7, 128))

            input = ly.deconv2d(input,
                                output_channel=64,
                                output_size=14,
                                strides=2,
                                name='deconv_0')
            input = ly.bn_layer(input, name='bn_1')
            input = tf.nn.leaky_relu(input)

            input = ly.deconv2d(input,
                                output_channel=1,
                                output_size=28,
                                strides=2,
                                name='deconv_1')
            input = ly.bn_layer(input, name='bn_2')
            input = tf.nn.sigmoid(input)

        return input  ## (-1,28,28,1)
コード例 #2
0
    def __call__(self, input):
        ### input_shape [-1,128,128,3]
        input_shape = input.get_shape().as_list()

        with tf.variable_scope(self.name, reuse=self.reuse):
            input = ly.conv2d(input,
                              64,
                              kernel_size=4,
                              strides=2,
                              name='d_conv_0')  # [-1,64,64,64]
            input = ly.bn_layer(input, name='d_bn_0')
            input = tf.nn.relu(input)

            input = ly.conv2d(input,
                              128,
                              kernel_size=4,
                              strides=2,
                              name='d_conv_1')  # [-1,32,32,128]
            input = ly.bn_layer(input, name='d_bn_1')
            input = tf.nn.relu(input)

            input = ly.conv2d(input,
                              256,
                              kernel_size=4,
                              strides=2,
                              name='d_conv_2')  # [-1,16,16,256]
            input = ly.bn_layer(input, name='d_bn_2')
            input = tf.nn.relu(input)

            input = ly.conv2d(input,
                              512,
                              kernel_size=4,
                              strides=2,
                              name='d_conv_3')  # [-1,8,8,512]
            input = ly.bn_layer(input, name='d_bn_3')
            input = tf.nn.relu(input)

            input = ly.conv2d(input,
                              1,
                              kernel_size=4,
                              strides=1,
                              name='d_conv_4',
                              bias=True)
            input = tf.nn.sigmoid(input)

        self.reuse = True
        return input
コード例 #3
0
    def __call__(self, input):
        with tf.variable_scope(self.name, reuse=self.reuse):

            input = ly.conv2d(input, 64, strides=2,
                              name='conv2d_0')  # 14 14 64
            input = ly.bn_layer(input, name='bn_0')
            input = tf.nn.relu(input)

            input = ly.conv2d(input, 128, strides=2,
                              name='conv2d_1')  # 7 7 128
            input = ly.bn_layer(input, name='bn_1')
            input = tf.nn.relu(input)

            input = ly.fc(input, 1024, name='fc_0')
            input = tf.nn.relu(input)

            input = ly.fc(input, 10, name='fc_1')

        return input
コード例 #4
0
    def __call__(self, input):
        with tf.variable_scope(self.name, reuse=self.reuse):
            input = ly.conv2d(input, 64, strides=2, name='d_conv2d_0')
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 128, strides=2, name='d_conv2d_1')
            input = ly.bn_layer(input, name='d_bn_1')
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 256, strides=2, name='d_conv2d_2')
            input = ly.bn_layer(input, name='d_bn_2')
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 512, strides=2, name='d_conv2d_3')
            input = ly.bn_layer(input, name='d_bn_3')
            input = tf.nn.leaky_relu(input)

            input = ly.fc(input, 1, bias=True, name='d_fc_0')

            return tf.nn.sigmoid(input)
コード例 #5
0
    def __call__(self, input):
        height = input.get_shape().as_list()[1]

        with tf.variable_scope(self.name, reuse=self.reuse):
            input = ly.conv2d(input, 64, name='g_conv2d_0')
            input = ly.bn_layer(input, name='g_bn_0')
            input = tf.nn.relu(input)

            ### resnet
            for i in range(16):
                cell = ly.conv2d(input, 64, name='g_res_conv2d_%s' % i)
                cell = ly.bn_layer(cell, name='g_res_bn_%s' % i)
                cell = input + cell
                input = cell

            ### deconv2d
            input = ly.conv2d(input, 256, name='g_conv2d_1')
            input = ly.deconv2d(input, 128, height * 2, strides=2, name='g_deconv2d_0')
            input = tf.nn.relu(input)

            input = ly.conv2d(input, 128, name='g_conv2d_2')
            input = ly.deconv2d(input, 64, height * 4, strides=2, name='g_deconv2d_1')
            input = tf.nn.relu(input)

            # ### Upsampling
            # input = ly.conv2d(input,256,name = 'g_conv2d_1')
            #
            # input = ly.Upsampling(input,height * 2)
            # input = ly.conv2d(input, 128,name = 'g_conv2d_2')
            # input = ly.bn_layer(input,name = 'g_bn_2')
            #
            # input = ly.Upsampling(input,height * 4)
            # input = ly.conv2d(input, 64,name = 'g_conv2d_3')
            # input = ly.bn_layer(input,name = 'g_bn_3')

            input = ly.conv2d(input, 3, name='g_conv2d_last')
            input = tf.nn.tanh(input)

            return input
コード例 #6
0
    def __call__(self, input):
        with tf.variable_scope(self.name, reuse=self.reuse):
            input = ly.conv2d(input, 64, strides=2,
                              name='conv_0')  ## (-1,14,14,64)
            input = ly.bn_layer(input, name='bn_0')
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 128, strides=2,
                              name='conv_1')  ## (-1,7,7,128)
            input = ly.bn_layer(input, name='bn_1')
            input = tf.nn.leaky_relu(input)

            output_d = ly.fc(input, 1, name='fc_0')
            output_d = ly.bn_layer(input, name='bn_2')

            # output_label = ly.fc(input, 128,name = 'label_fc_0')
            # input = ly.bn_layer(input, name='bn_3')
            # input = tf.nn.leaky_relu(input)
            #
            # output_label = ly.fc(input, 1,name = 'label_fc_1')
            # input = ly.bn_layer(input, name='bn_4')
            # input = tf.nn.sigmoid(input)

        return output_d
コード例 #7
0
    def __call__(self, input):
        ### simple
        with tf.variable_scope(self.name, reuse=self.reuse):
            input = ly.conv2d(input, 64, name='d_conv2d_0')

            input = ly.conv2d(input, 64, strides=2, name='d_conv2d_1')
            input = ly.bn_layer(input, name='d_bn_1', gamma_initializer=tf.random_normal_initializer(1., 0.02))
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 128, strides=1, name='d_conv2d_2')
            input = ly.bn_layer(input, name='d_bn_2', gamma_initializer=tf.random_normal_initializer(1., 0.02))
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 128, strides=2, name='d_conv2d_3')
            input = ly.bn_layer(input, name='d_bn_3', gamma_initializer=tf.random_normal_initializer(1., 0.02))
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 256, strides=1, name='d_conv2d_4')
            input = ly.bn_layer(input, name='d_bn_4', gamma_initializer=tf.random_normal_initializer(1., 0.02))
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 256, strides=2, name='d_conv2d_5')
            input = ly.bn_layer(input, name='d_bn_5', gamma_initializer=tf.random_normal_initializer(1., 0.02))
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 512, strides=1, name='d_conv2d_6')
            input = ly.bn_layer(input, name='d_bn_6', gamma_initializer=tf.random_normal_initializer(1., 0.02))
            input = tf.nn.leaky_relu(input)

            input = ly.conv2d(input, 512, strides=2, name='d_conv2d_7')
            input = ly.bn_layer(input, name='d_bn_7', gamma_initializer=tf.random_normal_initializer(1., 0.02))
            input = tf.nn.leaky_relu(input)

            print(input.shape)
            input = ly.fc(input, 1024, name='d_fc_0')
            input = tf.nn.leaky_relu(input)

            input = ly.fc(input, 1, name='d_fc_1')
            input = tf.nn.sigmoid(input)

            return input
コード例 #8
0
    def __call__(self, input):  # 256 * 256 * 3
        with tf.variable_scope(self.name, reuse=self.reuse):

            e0 = ly.conv2d(input, 64, strides=2,
                           name='g_conv2d_0')  # 128 * 128 * 64
            e0 = ly.bn_layer(e0, name='g_bn_0')
            e0 = tf.nn.leaky_relu(e0)

            e1 = ly.conv2d(e0, 128, strides=2,
                           name='g_conv2d_1')  # 64 * 64 * 128
            e1 = ly.bn_layer(e1, name='g_bn_1')
            e1 = tf.nn.leaky_relu(e1)

            e2 = ly.conv2d(e1, 256, strides=2,
                           name='g_conv2d_2')  # 32 * 32 * 256
            e2 = ly.bn_layer(e2, name='g_bn_2')
            e2 = tf.nn.leaky_relu(e2)

            e3 = ly.conv2d(e2, 512, strides=2,
                           name='g_conv2d_3')  # 16 * 16 * 512
            e3 = ly.bn_layer(e3, name='g_bn_3')
            e3 = tf.nn.leaky_relu(e3)

            e4 = ly.conv2d(e3, 512, strides=2,
                           name='g_conv2d_4')  # 8 * 8 * 512
            e4 = ly.bn_layer(e4, name='g_bn_4')
            e4 = tf.nn.leaky_relu(e4)

            e5 = ly.conv2d(e4, 512, strides=2,
                           name='g_conv2d_5')  # 4 * 4 * 512
            e5 = ly.bn_layer(e5, name='g_bn_5')
            e5 = tf.nn.leaky_relu(e5)

            e6 = ly.conv2d(e5, 512, strides=2,
                           name='g_conv2d_6')  # 2 * 2 * 512
            e6 = ly.bn_layer(e6, name='g_bn_6')
            e6 = tf.nn.leaky_relu(e6)

            e7 = ly.conv2d(e6, 512, strides=2,
                           name='g_conv2d_7')  # 1 * 1 * 512
            e7 = ly.bn_layer(e7, name='g_bn_7')
            e7 = tf.nn.leaky_relu(e7)

            d1 = ly.deconv2d(e7, 512, 2, strides=2,
                             name='g_deconv2d_1')  # 2 * 2 * 512
            d1 = ly.bn_layer(d1, name='g_bn_8')
            d1 = tf.nn.dropout(tf.nn.leaky_relu(d1), 0.5)
            d1 = tf.concat([d1, e6], 3)

            d2 = ly.deconv2d(d1, 512, 4, strides=2,
                             name='g_deconv2d_2')  # 4 * 4 * 512
            d2 = ly.bn_layer(d2, name='g_bn_9')
            d2 = tf.nn.dropout(tf.nn.leaky_relu(d2), 0.5)
            d2 = tf.concat([d2, e5], 3)

            d3 = ly.deconv2d(d2, 512, 8, strides=2,
                             name='g_deconv2d_3')  # 8 * 8 * 512
            d3 = ly.bn_layer(d3, name='g_bn_10')
            d3 = tf.nn.dropout(tf.nn.leaky_relu(d3), 0.5)
            d3 = tf.concat([d3, e4], 3)

            d4 = ly.deconv2d(d3, 512, 16, strides=2,
                             name='g_deconv2d_4')  # 16 * 16 * 512
            d4 = ly.bn_layer(d4, name='g_bn_11')
            d4 = tf.nn.leaky_relu(d4)
            d4 = tf.concat([d4, e3], 3)

            d5 = ly.deconv2d(d4, 256, 32, strides=2,
                             name='g_deconv2d_5')  # 32 * 32 * 256
            d5 = ly.bn_layer(d5, name='g_bn_12')
            d5 = tf.nn.leaky_relu(d5)
            d5 = tf.concat([d5, e2], 3)

            d6 = ly.deconv2d(d5, 128, 64, strides=2,
                             name='g_deconv2d_6')  # 64 * 64 * 128
            d6 = ly.bn_layer(d6, name='g_bn_13')
            d6 = tf.nn.leaky_relu(d6)
            d6 = tf.concat([d6, e1], 3)

            d7 = ly.deconv2d(d6, 64, 128, strides=2,
                             name='g_deconv2d_7')  # 128 * 128 * 64
            d7 = ly.bn_layer(d7, name='g_bn_14')
            d7 = tf.nn.leaky_relu(d7)
            d7 = tf.concat([d7, e0], 3)

            d7 = ly.deconv2d(d7, 3, 256, strides=2,
                             name='g_deconv2d_8')  # 256 * 256 * 3
            d7 = tf.nn.tanh(d7)

        return d7
コード例 #9
0
    def __call__(self, input):
        ### input --> image
        ### input_shape : [ -1, 128,128,3 ]
        input_shape = input.get_shape().as_list()
        input_channel = input_shape[-1]
        with tf.variable_scope(self.name, reuse=self.reuse):
            height = input.get_shape().as_list()[1]

            ### 提取特征 防止图片边缘奇异
            input = tf.pad(input,
                           paddings=[[0, 0], [3, 3], [3, 3], [0, 0]],
                           mode='REFLECT')
            input = ly.conv2d(input,
                              64,
                              kernel_size=7,
                              strides=1,
                              name='g_conv2d_0')
            input = ly.bn_layer(input, name='g_bn_0')
            input = tf.nn.relu(input)

            input = ly.conv2d(input,
                              128,
                              kernel_size=3,
                              strides=2,
                              name='g_conv2d_1')
            input = ly.bn_layer(input, name='g_bn_1')
            input = tf.nn.relu(input)

            input = ly.conv2d(input,
                              256,
                              kernel_size=3,
                              strides=2,
                              name='g_conv2d_2')
            input = ly.bn_layer(input, name='g_bn_2')
            input = tf.nn.relu(input)

            ### resnet
            for i in range(8):
                cell = ly.conv2d(input,
                                 256,
                                 kernel_size=3,
                                 strides=1,
                                 name='g_conv2d_res_%s' % i)
                cell = ly.bn_layer(cell, name='g_res_%s' % i)
                cell = tf.nn.relu(cell)
                input = cell

            low_height = math.ceil((height + 6.) / 4)

            input = ly.deconv2d(input,
                                128,
                                low_height * 2,
                                kernel_size=3,
                                strides=2,
                                name='g_deconv2d_0')
            input = ly.bn_layer(input, name='g_bn_3')
            input = tf.nn.relu(input)

            input = ly.deconv2d(input,
                                64,
                                low_height * 4,
                                kernel_size=3,
                                strides=2,
                                name='g_deconv2d_1')
            input = ly.bn_layer(input, name='g_bn_4')
            input = tf.nn.relu(input)

            input = ly.conv2d(input,
                              3,
                              kernel_size=7,
                              strides=1,
                              name='g_conv2d_3')
            input = ly.bn_layer(input, name='g_bn_5')
            input = tf.nn.tanh(input)

            input = tf.image.resize_images(input, [height, height])

        self.reuse = True

        return input