【发布时间】:2020-01-05 20:46:21
【问题描述】:
我从张量流检测模型动物园下载了一个ssd_mobilenet_v2_coco。我使用import_pb_to_tensorboard.py 在 Tensorboard 上显示结构。
我找到了一个名为“image_tensor”的节点this is the picture discribed in Tensorboard。
我想使用函数 'get_tensor_by_name()' 输入新图像并获取输出。但是,它失败了。
我试过 'get_operation_by_name()' ,也没有用。
代码如下:
import tensorflow as tf
def one_image(im_path, model_path):
sess= tf.Session()
with sess.as_default():
image_tensor = tf.image.decode_jpeg(tf.read_file(im_path), channels=3)
saver = tf.train.import_meta_graph(model_path + "/model.ckpt.meta")
saver.restore(sess, tf.train.latest_checkpoint(model_path))
graph = tf.get_default_graph()
# x = graph.get_tensor_by_name("import/image_tensor:0")
# out_put = graph.get_tensor_by_name("import/detection_classes:0")
x = graph.get_operation_by_name("import/image_tensor").outputs[0]
outputs = graph.get_operation_by_name("import/detection_classes").outputs[0]
out_put = sess.run(outputs, feed_dict={x: image_tensor.eval()})
print(out_put)
sess.close()
if __name__ == "__main__":
one_image("testimg-4-resize.jpg", "ssd_mobilenet_v2_coco_2018_03_29")
这是 KeyError:
KeyError: "The name 'import/image_tensor' refers to an Operation not in the graph."
我想知道如何从 Tensorboard 获取张量名称,以及是否有另一种方法可以从“only-ckpts”加载模型。
'only-ckpts' 表示文件仅包含 'model.ckpt.data-00000-of-00001' , 'model.ckpt.index' 和 'model.ckpt.meta'。
任何建议将不胜感激。提前谢谢你。
【问题讨论】:
标签: python-3.x tensorflow