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))