3
我試圖用這個代碼創建自己的夢深算法:深夢代碼不會產生可識別模式
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
import inception
img = np.random.rand(1,500,500,3)
net = inception.get_inception_model()
tf.import_graph_def(net['graph_def'], name='inception')
graph = tf.get_default_graph()
sess = tf.Session()
layer = graph.get_tensor_by_name('inception/mixed5b_pool_reduce_pre_relu:0')
gradient = tf.gradients(tf.reduce_mean(layer), graph.get_tensor_by_name('inception/input:0'))
softmax = sess.graph.get_tensor_by_name('inception/softmax2:0')
iters = 100
init = tf.global_variables_initializer()
sess.run(init)
for i in range(iters):
prediction = sess.run(softmax, \
{'inception/input:0': img})
grad = sess.run(gradient[0], \
{'inception/input:0': img})
grad = (grad-np.mean(grad))/np.std(grad)
img = grad
plt.imshow(img[0])
plt.savefig('output/'+str(i+1)+'.png')
plt.close('all')
但是,即使運行該循環100次迭代後所產生的畫面看起來還是隨機的(我將附上說明圖片到這個問題)。 有人可以幫我優化我的代碼嗎?
BTW,是的,我拿了CADL過程中,並用深夢想製作這個視頻:https://www.youtube.com/watch?v=RD9uc2u557w - 但實際上,這是可能的,而不unpicking谷歌的深層夢代碼到所有單獨的步驟都需要。 –
謝謝,這真的很好。 PS。你非常熟練 –