【发布时间】:2019-11-08 10:38:27
【问题描述】:
我已经调整了这个retrain.py 脚本以与几个预训练模型一起使用, 训练完成后,这会生成一个“retrained_graph.pb”,然后我读取并尝试使用此代码对图像进行预测:
def get_top_labels(image_data):
'''
Returns a list of labels and their probabilities
image_data: content of image as string
'''
with tf.compat.v1.Session() as sess:
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor, {'DecodeJpeg/contents:0': image_data})
return predictions
这适用于 inception_v3 模型,因为它有一个名为“DecodeJpeg”的张量,而我使用的其他模型,例如 inception_v4、mobilenet 和 inception_resnet_v2 则没有。
我的问题是我可以在图表中添加一个操作,就像在 retrain.py 脚本中的 add_jpeg_decoding 中使用的那样,以便我之后可以将其用于预测?
有没有可能做这样的事情:
predictions = sess.run(softmax_tensor, {image_data_tensor: image_data}) 其中image_data_tensor 是一个变量,取决于我使用的模型?
我查看了 stackoverflow 并找不到可以解决我的问题的问题,非常感谢任何帮助,谢谢。 我至少需要知道这是否可能。 很抱歉重新发布我对我的第一个没有意见。
【问题讨论】:
标签: python-3.x tensorflow pre-trained-model