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

我是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)

参考方案

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

 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')

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

如何用'-'解析字符串到节点js本地脚本? - python

我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…

Python:传递记录器是个好主意吗? - python

我的Web服务器的API日志如下:started started succeeded failed 那是同时收到的两个请求。很难说哪一个成功或失败。为了彼此分离请求,我为每个请求创建了一个随机数,并将其用作记录器的名称logger = logging.getLogger(random_number) 日志变成[111] started [222] start…

Python-Excel导出 - python

我有以下代码:import pandas as pd import requests from bs4 import BeautifulSoup res = requests.get("https://www.bankier.pl/gielda/notowania/akcje") soup = BeautifulSoup(res.cont…

Matplotlib'粗体'字体 - python

跟随this example:import numpy as np import matplotlib.pyplot as plt fig = plt.figure() for i, label in enumerate(('A', 'B', 'C', 'D')): ax = f…