gpt4 book ai didi

python-2.7 - 如何使用pycharm编辑器加载预训练的graph.pb和重新训练的label.text

转载 作者:行者123 更新时间:2023-11-30 08:49:32 26 4
gpt4 key购买 nike

使用pete warden我训练了初始网络和训练的教程,我得到了两个文件

1.retrained_graph.pb
2.retrained_label.txt

使用这个我想对花朵图像进行分类。我已经安装了 pycharm 并链接了所有 tensorflow 库,我还测试了示例 tensorflow 代码,它工作正常。

现在,当我运行 label_image.py 程序时

import tensorflow as tf, sys

image_path = sys.argv[1]

# Read in the image_data
image_data = tf.gfile.FastGFile(image_path, 'rb').read()

# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile("/tf_files/retrained_labels.txt")]

# Unpersists graph from file
with tf.gfile.FastGFile("/tf_files/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:
# Feed the image_data as input to the graph and get first prediction
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')

predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})

# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]

for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
print('%s (score = %.5f)' % (human_string, score))

我收到此错误消息

/home/chandan/Tensorflow/bin/python /home/chandan/PycharmProjects/tf/tf_folder/tf_files/label_image.py
Traceback (most recent call last):
File "/home/chandan/PycharmProjects/tf/tf_folder/tf_files/label_image.py", line 7, in <module>
image_path = sys.argv[1]
IndexError: list index out of range

有人可以帮我解决这个问题吗?

最佳答案

您收到此错误是因为它需要图像名称(带有路径)作为参数。

在 pycharm 中,转到“ View ”->“工具窗口”->“终端”。

与打开单独的终端相同。并运行

python label_image.py /image_path/image_name.jpg

关于python-2.7 - 如何使用pycharm编辑器加载预训练的graph.pb和重新训练的label.text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42640757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com