tensorflow-gpu训练图像

tensorflow-gpu训练图像_第1张图片

从github(数据集)下载的数据集解压如下,分为五种:

tensorflow-gpu训练图像_第2张图片

下载repository,cd 项目文件路径tensorflow-for-poets-2

运行tensorflow-gpu(需要anaconda环境)

conda activate tensorflow-gpu

 开始训练:

python -m scripts.retrain --bottleneck_dir=tf_files/bottlenecks --how_many_training_steps=500 --model_dir=tf_files/models/ --summaries_dir=tf_files/training_summaries/basic --output_graph=tf_files/retrained_graph.pb  --output_labels=tf_files/retrained_labels.txt --image_dir=tf_files/flower_photos

 训练结束后生成以下两个文件:

 

接下来对训练的结果进行测试,输入以下命令行:

python -m scripts.label_image --graph=tf_files/retrained_graph.pb --image=tf_files/flower_photos/daisy/21652746_cc379e0eea_m.jpg

正常情况下结果就出来了,但是我的结果报错情况如下:

Traceback (most recent call last):
  File "D:\Users\Zjj\Anaconda3\envs\tensorflow-gpu\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "D:\Users\Zjj\Anaconda3\envs\tensorflow-gpu\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Zjj\Desktop\Graduation-project\TensorFlow\tensorflow-for-poets-2\scripts\label_image.py", line 121, in 
    input_operation = graph.get_operation_by_name(input_name);
  File "D:\Users\Zjj\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\framework\ops.py", line 3163, in get_operation_by_name
    return self.as_graph_element(name, allow_tensor=False, allow_operation=True)
  File "D:\Users\Zjj\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\framework\ops.py", line 3035, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "D:\Users\Zjj\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\framework\ops.py", line 3095, in _as_graph_element_locked
    "graph." % repr(name))
KeyError: "The name 'import/Input' refers to an Operation not in the graph."

查阅国外社区资料后发现这是因为label_image.py里面第76-78行的的设置有问题(可能是使用了除MobileNet之外的任何其他架构产生的问题),修改如下:

#第74-78行
input_height = 224
input_width = 224
input_mean = 128
input_std = 128
input_layer ="input"


#改为此
input_height = 299
input_width = 299
input_mean = 128
input_std = 128
input_layer ="Mul"

重新运行,发现结果如下

tensorflow-gpu训练图像_第3张图片

你可能感兴趣的:(tensorflow)