中使用的出厂的InceptionV3图形classify_image.py
仅支持开箱即用的JPEG图像。您可以通过两种方式将此图用于PNG图像:
例如使用PIL将PNG图像转换为height
x width
x 3(通道)的Numpy数组,然后馈入张量:'DecodeJpeg:0'
import numpy as np
from PIL import Image
image = Image.open(“example.png”) image_array = np.array(image)[:, :, 0:3] # Select RGB channels only.
prediction = sess.run(softmax_tensor, {‘DecodeJpeg:0’: image_array})
或许令人混淆,'DecodeJpeg:0'
是 输出 的的DecodeJpeg
运算,所以通过将该料张量,你能养活原始图像数据。
将tf.image.decode_png()
op添加到导入的图形。从简单的开关美联储张的名字'DecodeJpeg/contents:0'
,以'DecodePng/contents:0'
不起作用,因为没有'DecodePng'
在运图运算。您可以通过使用input_map
参数将这样的节点添加到图中tf.import_graph_def()
:
png_data = tf.placeholder(tf.string, shape=[])
decoded_png = tf.image.decode_png(png_data, channels=3)
graph_def = … softmax_tensor = tf.import_graph_def( graph_def, input_map={‘DecodeJpeg:0’: decoded_png}, return_elements=[‘softmax:0’])
sess.run(softmax_tensor, {png_data: …})