备注:下载github程序并运行,本人是小白一枚。这也是本人第一次运行GAN程序。在这里仅仅将自己的代码实操过程分享出来。附件的tf.subtract()和tf.multiply()函数相对于github有所改动,不然版本配不上会出错。这里附上:github源代码链接
#运行run.py文件
run run.py
运行结果,耗时约一小时,CPU Windows7
step 0: loss 21.247
step 10: loss 22.076
step 20: loss 19.516
step 30: loss 6.678
step 40: loss 5.416
step 50: loss 8.300
step 60: loss 5.144
step 70: loss 6.920
step 80: loss 5.351
step 90: loss 6.231
step 100: loss 5.182
step 110: loss 4.267
step 120: loss 7.220
step 130: loss 6.011
step 140: loss 6.295
step 150: loss 4.976
·····
step 99870: loss 0.013
step 99880: loss 0.011
step 99890: loss 0.010
step 99900: loss 0.014
step 99910: loss 0.011
step 99920: loss 0.009
step 99930: loss 0.014
step 99940: loss 0.011
step 99950: loss 0.014
step 99960: loss 0.006
step 99970: loss 0.003
step 99980: loss 0.017
step 99990: loss 0.004
<Figure size 640x480 with 1 Axes>
#显示生成的最后一张图片
visualize.visualize(embed, x_test)
附件
#run.py
""" Siamese implementation using Tensorflow with MNIST example.
This siamese network embeds a 28x28 image (a point in 784D)
into a point in 2D.
By Youngwook Paul Kwon (young at berkeley.edu)
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
#import system things
from tensorflow.examples.tutorials.mnist import input_data # for data
import tensorflow as tf
import numpy as np
import os
#import helpers
import inference
import visualize
# prepare data and tf.session
mnist = input_data.read_data_sets('MNIST_data', one_hot=False)
sess = tf.InteractiveSession()
# setup siamese network
siamese = inference.siamese();
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(siamese.loss)
saver = tf.train.Saver()
tf.initialize_all_variables().run()
# if you just want to load a previously trainmodel?
new = True
model_ckpt = 'model.ckpt'
if os.path.isfile(model_ckpt):
input_var = None
while inp