这是我在MNIST数据集上测量量化的例子.我正在使用以下代码测试我的模型:
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.python.framework import graph_util
from tensorflow.core.framework import graph_pb2
import numpy as np
def test_model(model_file,x_in):
with tf.Session() as sess:
with open(model_file, "rb") as f:
output_graph_def = graph_pb2.GraphDef()
output_graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(output_graph_def, name="")
x = sess.graph.get_tensor_by_name('Placeholder_1:0')
y = sess.graph.get_tensor_by_name('softmax_cross_entropy_with_logits:0')
new_scores = sess.run(y, feed_dict={x:x_in.test.images})
print((orig_scores - new_scores) < 1e-6)
find_top_pred(orig_scores)
find_top_pred(new_scores)
#print(epoch_x.shape)
mnist = input_data.read_data_sets("/tmp/data/", one_hot = True)
test_model('mnist_cnn1.pb',mnist)
Run Code Online (Sandbox Code Playgroud)
我没有得到我提供错误值的地方.在这里,我添加了错误代码的完整跟踪.以下是错误:
Extracting /tmp/data/train-images-idx3-ubyte.gz
Extracting /tmp/data/train-labels-idx1-ubyte.gz
Extracting /tmp/data/t10k-images-idx3-ubyte.gz
Extracting /tmp/data/t10k-labels-idx1-ubyte.gz
Traceback (most recent call last):
File …Run Code Online (Sandbox Code Playgroud) placeholder quantization mnist conv-neural-network tensorflow