Page 469 - 2020학년도 MDP과제발표회 자료집 (통신과) (3)
P. 469
data = img.reshape([1, 65536])
‘’‘
placeholder 들을 지정해 줍니다 모델에서 정확도와 라벨 값도 받아옵니다. .
‘’‘
# Input placeholder 를 지정해줍니다.
X = tf.placeholder(tf.float32, [None, 65536])
X_img = tf.reshape(X, [-1, 256, 256, 1]) # 128x128x1 (black/white)
Y = tf.placeholder(tf.float32, [None, 5]) # Labels
keep_prob = tf.placeholder(tf.float32)
logits, y_pred = model.model(X, keep_prob)
‘’‘
tf.train.Saver 를 이용하여 train.py 에서 학습한 모델을 받아옵니다.
‘’‘
# tf.train.Saver 를 이용해서 모델과 파라미터를 불러옵니다.
SAVER_DIR = "model"
saver = tf.train.Saver()
ckpt = tf.train.get_checkpoint_state(SAVER_DIR)
init_op = tf.global_variables_initializer()
‘’‘
확률과 라벨을 저장할 변수를 초기화 해줍니다 이후에 불러온 모델을 이용하여 하나의 사진에 대한 . 5
개의 라벨의 확률을 뽑아낸 후 각각의 확률을 비교해서 하나의 변수에 넣어줍니다.
‘’‘
max = 0
result = [0, 0, 0, 0, 0]
with tf.Session() as sess:
sess.run(init_op)
saver.restore(sess, ckpt.model_checkpoint_path)
predictions = sess.run(y_pred, feed_dict={X: data, keep_prob: 1.0})
print(predictions[0]);
for i in range(5):
result[i] = predictions[0][i]
if predictions[0][i] > max:
max = predictions[0][i]
print("Data_Path : ", img_path)
print("Persent : ", max)
print("Data : ", result.index(max))
결과
인천전자마이스터고등학교
- 489 - 정보통신기기과 489