我不想使用路径信息,因为在我的Python 3代码中已经将图像作为数组。保存此图像,重新读取没有意义。
因此,我正在尝试将基于路径的方法转换为基于矩阵的方法。
# this needs to be altered here
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
label_lines = [line.rstrip() for line
in tf.gfile.GFile(home + '/retrained_labels.txt')]
with tf.gfile.FastGFile(home + '/retrained_graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
with tf.Session() as sess:
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
# run the prediction
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})
但是,函数tf.gfile.FastGFile
显然不接受任何图像作为矩阵。
TypeError: Expected binary or unicode string, got array([[[134, 129, 126],
此功能是否有其他选择,可以将图像读取为矩阵并且仍然能够如上所述生成image_data
?