0
私のTensorFlowモデルは、モデルを訓練しなくなり、チェックポイント付きモデルファイルが変更されていなくても、これは、同じハードコード化された入力でランダムかつ信頼性の低い予測を得るため、問題があります。リストアされたTensorFlowモデルは、リストアされるたびに予期せずにウェイトを変更します。
以下は、単純にすべての重みの合計を返す単純化されたコードです。スクリプトを実行するたびに合計が変化し、重みが変化していることが示されます。
import tensorflow as tf
import numpy as np
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
x = tf.placeholder(tf.float32, shape=[None, 240, 320, 3])
y_ = tf.placeholder(tf.float32, shape=[None, 3])
x_shaped = tf.reshape(x, [-1, 240 * 320 * 3])
W1 = weight_variable([240 * 320 * 3, 32])
b1 = bias_variable([32])
h1 = tf.sigmoid(tf.matmul(x_shaped, W1) + b1)
W2 = weight_variable([32, 3])
b2 = bias_variable([3])
y=tf.nn.softmax(tf.matmul(h1, W2) + b2)
saver = tf.train.Saver()
sess = tf.InteractiveSession(config=tf.ConfigProto())
saver.restore(sess, "/some/path/model.ckpt")
sess.run(tf.initialize_all_variables())
weights = W1.eval(session=sess)
print(np.sum(weights))