为什么此测试功能不输出图像? pokeGAN教程

时间:2019-01-10 19:24:43

标签: python tensorflow dcgan

我是python编码和使用tensorflow的新手,据说这可能是一个愚蠢的问题。我一直在跟踪Siraj所做的pokeGAN tutorial,而他实际上并未对测试功能发表评论。我已经训练过模型,但是当我取消对测试函数的注释时,它只是以代码0退出,并且没有给出可能生成的图像。我知道退出代码0表示没有错误,但是我很好奇为什么它不生成图像。函数只是不告诉它生成图像吗?是否还有其他需要取消注释(或注释)的内容才能使其正常工作?任何帮助都会很棒。

以下是整个代码的github链接:pokeGAN

这是实际的测试功能:

def test():
random_dim = 100
with tf.variable_scope('input'):
    real_image = tf.placeholder(tf.float32, shape=[None, HEIGHT, WIDTH, CHANNEL], name='real_image')
    random_input = tf.placeholder(tf.float32, shape=[None, random_dim], name='rand_input')
    is_train = tf.placeholder(tf.bool, name='is_train')

# wgan
fake_image = generator(random_input, random_dim, is_train)
real_result = discriminator(real_image, is_train)
fake_result = discriminator(fake_image, is_train, reuse=True)
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
variables_to_restore = slim.get_variables_to_restore(include=['gen'])
print(variables_to_restore)
saver = tf.train.Saver(variables_to_restore)
ckpt = tf.train.latest_checkpoint('./model/' + version)
saver.restore(sess, ckpt)

1 个答案:

答案 0 :(得分:0)

您输入的代码缺少一些信息来创建图像并保存图像。

 def test():
     random_dim = 100
     with tf.variable_scope('input'):
         real_image = tf.placeholder(tf.float32, shape = [None, HEIGHT, WIDTH, CHANNEL], name='real_image')
         random_input = tf.placeholder(tf.float32, shape=[None, random_dim], name='rand_input')
         is_train = tf.placeholder(tf.bool, name='is_train')

 # wgan
    fake_image = generator(random_input, random_dim, is_train)
    real_result = discriminator(real_image, is_train)
    fake_result = discriminator(fake_image, is_train, reuse=True)
    sess = tf.InteractiveSession()
    sess.run(tf.global_variables_initializer())
    variables_to_restore = slim.get_variables_to_restore(include=['gen'])
    print(variables_to_restore)
    saver = tf.train.Saver(variables_to_restore)
    ckpt = tf.train.latest_checkpoint('./model/' + version)
    saver.restore(sess, ckpt)

 #image creation
    sample_noise = np.random.uniform(-1.0, 1.0, size=[64, random_dim]).astype(np.float32)
    imgtest = sess.run(fake_image, feed_dict={random_input: sample_noise, is_train: False})

    save_images(imgtest, [8,8] ,newPoke_path + '/epoch'  + 'image.jpg')