1
Udacityの深い学習基礎コースからのものです。それは彼らのために働くようです。しかし、それは私のコンピュータでは機能しません。見てください。あなたの助けをよろしく!Tensorflowの保存と復元の変数が同じではありません
講義と私のコンピュータのテンソルフローバージョンは両方とも1.0.0です。
import tensorflow as tf
# The file path to save the data
save_file = './model.ckpt'
# Two Tensor Variables: weights and bias
weights = tf.Variable(tf.truncated_normal([2, 3]))
bias = tf.Variable(tf.truncated_normal([3]))
# Class used to save and/or restore Tensor Variables
saver = tf.train.Saver()
with tf.Session() as sess:
# Initialize all the Variables
sess.run(tf.global_variables_initializer())
# Show the values of weights and bias
print('Weights:')
print(sess.run(weights))
print('Bias:')
print(sess.run(bias))
# Save the model
saver.save(sess, save_file)
# Remove the previous weights and bias
tf.reset_default_graph()
# Two Variables: weights and bias
weights = tf.Variable(tf.truncated_normal([2, 3]))
bias = tf.Variable(tf.truncated_normal([3]))
# Class used to save and/or restore Tensor Variables
saver = tf.train.Saver()
with tf.Session() as sess:
# Load the weights and bias
saver.restore(sess, save_file)
# Show the values of weights and bias
print('Weight:')
print(sess.run(weights))
print('Bias:')
print(sess.run(bias))
あなたのコードは最新のTensorFlowで動作します。最新のTensorFlowリリースに更新してやり直すことはできますか?それでも動作しない場合、何がうまくいかないのですか?エラーや出力が間違っていますか? –