728x90
728x170
■ 신경망 모델을 로드하는 방법을 보여준다.
▶ 예제 코드 (PY)
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]))
728x90
그리드형(광고전용)
'Python > tensorflow' 카테고리의 다른 글
[PYTHON/TENSORFLOW] 컨볼루션 신경망 만들기 (MNIST) (0) | 2018.08.04 |
---|---|
[PYTHON/TENSORFLOW] 컨볼루션 신경망 만들기 (MNIST) (0) | 2018.08.03 |
[PYTHON/TENSORFLOW] 다층 퍼셉트론 신경망 만들기 (MNIST) : 4계층 ReLU Dropout 1계층 Softmax (0) | 2018.08.01 |
[PYTHON/TENSORFLOW] 다층 퍼셉트론 신경망 만들기 (MNIST) : 4계층 ReLU 1계층 Softmax (0) | 2018.08.01 |
[PYTHON/TENSORFLOW] 다층 퍼셉트론 신경망 만들기 (MNIST) : 4계층 Sigmoid 1계층 Softmax (0) | 2018.08.01 |
[PYTHON/TENSORFLOW] 다층 퍼셉트론 신경망 만들기 (MNIST) : 1계층 Softmax (0) | 2018.07.31 |
[PYTHON/TENSORFLOW] 단일 입력 뉴런 만들기 (0) | 2018.07.30 |
[PYTHON/TENSORFLOW] Session 클래스 : run 메소드를 사용해 피드 연산하기 (0) | 2018.07.29 |
[PYTHON/TENSORFLOW] Session 클래스 : run 메소드를 사용해 1개 이상의 텐서 값 구하기 (0) | 2018.07.29 |
[PYTHON/TENSORFLOW] Variable 클래스 : 변수 사용하기 (0) | 2018.07.29 |