def test_discriminator_invalid_input(self):
    wrong_dim_img = tf.zeros([5, 32, 32])
    with self.assertRaises(ValueError):
      dcgan.discriminator(wrong_dim_img)

    spatially_undefined_shape = tf.placeholder(tf.float32, [5, 32, None, 3])
    with self.assertRaises(ValueError):
      dcgan.discriminator(spatially_undefined_shape)

    not_square = tf.zeros([5, 32, 16, 3])
    with self.assertRaisesRegexp(ValueError, 'not have equal width and height'):
      dcgan.discriminator(not_square)

    not_power_2 = tf.zeros([5, 30, 30, 3])
    with self.assertRaisesRegexp(ValueError, 'not a power of 2'):
      dcgan.discriminator(not_power_2)
Beispiel #2
0
  def test_discriminator_invalid_input(self):
    wrong_dim_img = tf.zeros([5, 32, 32])
    with self.assertRaises(ValueError):
      dcgan.discriminator(wrong_dim_img)

    spatially_undefined_shape = tf.placeholder(tf.float32, [5, 32, None, 3])
    with self.assertRaises(ValueError):
      dcgan.discriminator(spatially_undefined_shape)

    not_square = tf.zeros([5, 32, 16, 3])
    with self.assertRaisesRegexp(ValueError, 'not have equal width and height'):
      dcgan.discriminator(not_square)

    not_power_2 = tf.zeros([5, 30, 30, 3])
    with self.assertRaisesRegexp(ValueError, 'not a power of 2'):
      dcgan.discriminator(not_power_2)
  def test_discriminator_graph(self):
    # Check graph construction for a number of image size/depths and batch
    # sizes.
    for i, batch_size in zip(xrange(1, 6), xrange(3, 8)):
      tf.reset_default_graph()
      img_w = 2 ** i
      image = tf.random_uniform([batch_size, img_w, img_w, 3], -1, 1)
      output, end_points = dcgan.discriminator(
          image,
          depth=32)

      self.assertAllEqual([batch_size, 1], output.get_shape().as_list())

      expected_names = ['conv%i' % j for j in xrange(1, i+1)] + ['logits']
      self.assertSetEqual(set(expected_names), set(end_points.keys()))

      # Check layer depths.
      for j in range(1, i+1):
        layer = end_points['conv%i' % j]
        self.assertEqual(32 * 2**(j-1), layer.get_shape().as_list()[-1])
Beispiel #4
0
  def test_discriminator_graph(self):
    # Check graph construction for a number of image size/depths and batch
    # sizes.
    for i, batch_size in zip(xrange(1, 6), xrange(3, 8)):
      tf.reset_default_graph()
      img_w = 2 ** i
      image = tf.random_uniform([batch_size, img_w, img_w, 3], -1, 1)
      output, end_points = dcgan.discriminator(
          image,
          depth=32)

      self.assertAllEqual([batch_size, 1], output.get_shape().as_list())

      expected_names = ['conv%i' % j for j in xrange(1, i+1)] + ['logits']
      self.assertSetEqual(set(expected_names), set(end_points.keys()))

      # Check layer depths.
      for j in range(1, i+1):
        layer = end_points['conv%i' % j]
        self.assertEqual(32 * 2**(j-1), layer.get_shape().as_list()[-1])
 def test_discriminator_run(self):
   image = tf.random_uniform([5, 32, 32, 3], -1, 1)
   output, _ = dcgan.discriminator(image)
   with self.test_session() as sess:
     sess.run(tf.global_variables_initializer())
     output.eval()
Beispiel #6
0
        D_model.save_weights('logs/D_Epoch%d-GLoss%.4f-DLoss%.4f.h5' %
                             ((epoch + 1), G_total_loss /
                              (epoch_size + 1), D_total_loss /
                              (epoch_size + 1)))
        print('Saving state, iter:', str(epoch + 1))


if __name__ == "__main__":
    image_shape = [64, 64, 3]

    # 数据集存放路径
    annotation_path = "train_lines.txt"

    # 生成网络和评价网络
    G_model = generator(64, image_shape)
    D_model = discriminator(64, image_shape)

    # G_model_path = "model_data/Generator_Flower.h5"
    # D_model_path = "model_data/Discriminator_Flower.h5"
    # G_model.load_weights(G_model_path, by_name=True, skip_mismatch=True)
    # D_model.load_weights(D_model_path, by_name=True, skip_mismatch=True)

    with open(annotation_path) as f:
        lines = f.readlines()
    num_train = len(lines)

    #------------------------------------------------------#
    #   Init_Epoch为起始世代
    #   Epoch总训练世代
    #------------------------------------------------------#
    if True:
Beispiel #7
0
    batch_size      = 64
    lr              = 0.002
    #------------------------------#
    #   每隔50个step保存一次图片
    #------------------------------#
    save_interval   = 50
    #------------------------------------------#
    #   获得图片路径
    #------------------------------------------#
    annotation_path = "train_lines.txt"

    #----------------------------#
    #   生成网络和评价网络
    #----------------------------#
    G_model = generator(channel, input_shape)
    D_model = discriminator(channel, input_shape)
    
    #------------------------------------------#
    #   将训练好的模型重新载入
    #------------------------------------------#
    if G_model_path != '':
        G_model.load_weights(G_model_path, by_name=True, skip_mismatch=True)
    if D_model_path != '':
        D_model.load_weights(D_model_path, by_name=True, skip_mismatch=True)
    
    with open(annotation_path) as f:
        lines = f.readlines()
    num_train = len(lines)

    #------------------------------------------------------#
    #   Init_Epoch为起始世代
Beispiel #8
0
 def test_discriminator_run(self):
   image = tf.random_uniform([5, 32, 32, 3], -1, 1)
   output, _ = dcgan.discriminator(image)
   with self.test_session() as sess:
     sess.run(tf.global_variables_initializer())
     output.eval()