我想使用tensorflow训练过的初始模型对花卉照片进行分类。
加载tensorflow_inception_graph.pb
后,我从图表中导入了两个张量:pool_3/_reshape:0
和DecodeJpeg/contents:0
bottleneck_tensor_name='pool_3/_reshape:0'
jpeg_data_tensor_name='DecodeJpeg/contents:0'
model_dir='C:/Users/User/PycharmProjects/Neural_Network'
model_file='tensorflow_inception_graph.pb'
with gfile.FastGFile(os.path.join(model_dir,model_file),'rb') as f:
graph_def=tf.GraphDef()
graph_def.ParseFromString(f.read())
bottleneck_tensor,jpeg_data_tensor=tf.import_graph_def(graph_def,return_elements=[bottleneck_tensor_name,jpeg_data_tensor_name])
加载我自己的image_data
后,我执行了:
bottleneck_values=sess.run(bottleneck_tensor,{image_data_tensor:image_data})
bottleneck_values=np.squeeze(bottleneck_values)
但是,我有两种类型的错误:(1)BatchNormalization不推荐使用(2)形状不兼容。
是因为图表中jpeg_data_tensor_name
的形状与我照片的形状不同吗?我在哪里可以获取源代码来检查指定pool_3/_reshape:0
和DecodeJpeg/contents:0
的方式?
如果不推荐使用BatchNormalization,需要从头开始重新训练吗?
2018-02-25 20:42:07.519912: W C:\tf_jenkins\workspace\rel-win\M\windows\PY\36\tensorflow\core\framework\op_def_util.cc:343] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1350, in _do_call
return fn(*args)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1329, in _run_fn
status, run_metadata)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 473, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [5] vs. [700]
[[Node: evaluation_1/Equal = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"](evaluation_1/ArgMax, evaluation_1/ArgMax_1)]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 36, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 895, in run
run_metadata_ptr)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1128, in _run
feed_dict_tensor, options, run_metadata)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1344, in _do_run
options, run_metadata)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1363, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [5] vs. [700]
[[Node: evaluation_1/Equal = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"](evaluation_1/ArgMax, evaluation_1/ArgMax_1)]]
Caused by op 'evaluation_1/Equal', defined at:
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.4\helpers\pydev\pydevconsole.py", line 542, in <module>
pydevconsole.start_server(host, int(port), int(client_port), client_host)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.4\helpers\pydev\pydevconsole.py", line 366, in start_server
process_exec_queue(interpreter)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.4\helpers\pydev\pydevconsole.py", line 221, in process_exec_queue
more = interpreter.add_exec(code_fragment)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.4\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 251, in add_exec
more = self.do_add_exec(code_fragment)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.4\helpers\pydev\pydevconsole.py", line 123, in do_add_exec
command.run()
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.2.4\helpers\pydev\pydevconsole.py", line 82, in run
self.more = self.interpreter.runsource(text, '<input>', symbol)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\code.py", line 75, in runsource
self.runcode(code)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 20, in <module>
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line 1700, in equal
"Equal", x=x, y=y, name=name)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3160, in create_op
op_def=op_def)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1625, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): Incompatible shapes: [5] vs. [700]
[[Node: evaluation_1/Equal = Equal[T=DT_INT64, _device="/job:localhost/replica:0/task:0/device:CPU:0"](evaluation_1/ArgMax, evaluation_1/ArgMax_1)]]