1

我尝试使用 Google 的 Inception Neural Network 用这段代码构建我自己的深度梦想算法:

import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
#I am using the Kadenze CADL helper function ---> https://github.com/pkmital/CADL/tree/master/session-4/libs
import inception

img = np.random.rand(1,1920,1080,3)

net = inception.get_inception_model()
tf.import_graph_def(net['graph_def'], name='inception')
graph = tf.get_default_graph()
layer = graph.get_tensor_by_name('inception/mixed5b_pool_reduce_pre_relu:0')
gradient = tf.gradients(tf.reduce_mean(layer), img)
sess = tf.Session()
init = tf.global_variables_initializer()
iters = 1440

sess.run(init)
for i in range(iters):
    print(i+1)
    grad = sess.run(gradient[0])[0]
    img += grad
    plt.imshow(img[0])
    plt.savefig('output/'+str(i+1)+'.png')
    plt.close('all')

但该行tf.gradients(tf.reduce_mean(layer), img)只返回[None]。这(当然)会导致错误。谁能告诉我如何解决它?

4

0 回答 0