def generate_image_grid(sess, op):
"""
Generates a grid of images by passing a set of numbers to the decoder and getting its output.
:param sess: Tensorflow Session required to get the decoder output
:param op: Operation that needs to be called inorder to get the decoder output
:return: None, displays a matplotlib window with all the merged images.
"""
x_points = np.arange(-10, 10, 1.5).astype(np.float32)
y_points = np.arange(-10, 10, 1.5).astype(np.float32)
nx, ny = len(x_points), len(y_points)
plt.subplot()
gs = gridspec.GridSpec(nx, ny, hspace=0.05, wspace=0.05)
for i, g in enumerate(gs):
z = np.concatenate(([x_points[int(i / ny)]], [y_points[int(i % nx)]]))
z = np.reshape(z, (1, 2))
x = sess.run(op, feed_dict={decoder_input: z})
ax = plt.subplot(g)
img = np.array(x.tolist()).reshape(28, 28)
ax.imshow(img, cmap='gray')
ax.set_xticks([])
ax.set_yticks([])
ax.set_aspect('auto')
plt.show()
adversarial_autoencoder.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录