■ 신경망 모델을 로드하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import random import tensorflow as tf import tensorflow.examples.tutorials.mnist as mnist mnistDatasets = mnist.input_data.read_data_sets("data", one_hot = True) session = tf.InteractiveSession() saver = tf.train.import_meta_graph("data/mnist_1_layer_softmax.ckpt.meta") saver.restore(session, "data/mnist_1_layer_softmax.ckpt") tf.get_default_graph().as_graph_def() inputTensor = session.graph.get_tensor_by_name("input:0" ) outputTensor = session.graph.get_tensor_by_name("output:0") testImageIndex = random.randint(0, mnistDatasets.test.images.shape[0]) testImageNDArray = mnistDatasets.test.images[testImageIndex] result = session.run(["input:0", outputTensor], feed_dict = {inputTensor : [testImageNDArray]}) print("정답 : ", session.run(tf.argmax(mnistDatasets.test.labels[testImageIndex]))) print("판단 : ", session.run(tf.argmax(result[1], 1)[0])) |