TensorFlow训练模式如何保存,网上很多列子,拿来一试竟然没有作用! 后面自己摸索了下,搞定了,下面列子每次启动训练都会读取上次训练结果,每次训练也会自动存储。做一个记录吧,方便日后查询:
W_fc2 = weight_variable('W_fc2',[1024,64])
b_fc2 = bias_variable([64])
W_fc3 = weight_variable('W_fc3',[64, 6])
b_fc3 = bias_variable([6])
F1=tf.matmul(h_fc1_drop, W_fc2) + b_fc2
F2=tf.matmul(F1, W_fc3) + b_fc3
y_conv=tf.nn.softmax(tt)
#下面代码检查创建保存文件路径
chk_dir="D:\\PokerChkPointCNN"
if(not os.path.exists(chk_dir)):
os.makedirs(chk_dir)
saver=tf.train.Saver()
tf.global_variables_initializer().run()
#主意一定要在前面代码执行后才执行下面代码,否则是无意义的,也就是无法恢复上次的训练结果
ckpt=tf.train.latest_checkpoint(chk_dir)
if(ckpt):
saver.restore(sess,ckpt)
while true:
#训练过程中的保存
saver.save(sess, chk_dir+"\\model.ckpt",global_step=i+1)