나는 내가 다음으로 graph.pb 파일로 변환되는 훈련 후이 밖으로 내 graph.pbtxt 파일을 가지고 https://github.com/tensorflow/models/tree/master/slimTensorflow Inception_Resnet_V2 분류 이미지
에서 README 다음 꽃의 이미지에 대한 inception_resnet_v2 모델을 훈련 코드 : 여기
import tensorflow as tf
from google.protobuf import text_format
def convert_pbtxt_to_graphdef(filename):
"""Returns a `tf.GraphDef` proto representing the data in the given pbtxt file.
Args:
filename: The name of a file containing a GraphDef pbtxt (text-formatted
`tf.GraphDef` protocol buffer data).
Returns:
A `tf.GraphDef` protocol buffer.
"""
with tf.gfile.FastGFile(filename, 'r') as f:
graph_def = tf.GraphDef()
file_content = f.read()
# Merges the human-readable string in `file_content` into `graph_def`.
text_format.Merge(file_content, graph_def)
return graph_def
with tf.gfile.FastGFile('/foo/bar/workspace/results/graph.pb', 'wb') as f:
f.write(convert_pbtxt_to_graphdef('/foo/bar/workspace/results/graph.pbtxt'))
tensorflow의 classify_image.py를 사용하여 나는 훈련 모델을 임의의 이미지를 먹이려고이 파일을받은 후 :
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/imagenet/classify_image.py
,532 10 내 .pb 또, .pbtxt를 사용하여, 내 레이블 파일, 그러나, 나는 다음과 같은 오류 얻을 : 슬림과
Traceback (most recent call last):
File "classify_image.py", line 212, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "classify_image.py", line 208, in main
run_inference_on_image(image)
File "classify_image.py", line 170, in run_inference_on_image
softmax_tensor = sess.graph.get_tensor_by_name('softmax:0')
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2615, in get_tensor_by_name
return self.as_graph_element(name, allow_tensor=True, allow_operation=False)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2466, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2508, in _as_graph_element_locked
"graph." % (repr(name), repr(op_name)))
KeyError: "The name 'softmax:0' refers to a Tensor which does not exist. The operation, 'softmax', does not exist in the graph."
TF r0.11을 재결 중이고 convert_checkpoint_to_pb.py를 실행할 때이 오류가 발생합니다. "ImportError : 모듈 이름이 tools.optimize_for_inference_lib"입니다. –
TF r0.11에서도 작동하지 않습니다. 함수는 있지만 모듈로는 액세스 할 수 없습니다. 최신 버전 (TF r0.12, TF r1.0)으로 업그레이드하면 작동합니다. r0.11에 붙어있는 경우 Python에서 [this] (https://github.com/tensorflow/tensorflow/blob/r0.11/tensorflow/python/tools/optimize_for_inference_lib.py) 함수를 사용할 수 있도록 고려하십시오. 통로. – Maximilian