您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在张量流中馈送图像数据以进行转移学习

在张量流中馈送图像数据以进行转移学习

中使用的出厂的InceptionV3图形classify_image.py支持开箱即用的JPEG图像。您可以通过两种方式将此图用于PNG图像:

例如使用PIL将PNG图像转换为heightx widthx 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: …})

其他 2022/1/1 18:35:59 有487人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶