Closed zjbaby closed 5 years ago
Have you exported the graph?
@netanel-s I export the graph, and the problem is solved, Thank you very much~~~
@zjbaby , happy to help :) You can close the issue.
OK~
Do I need to add additional code in the train.py or trainer.py of the object detection API files? i do not understand "export the graph" could you show me how to do it ? thank you very much!
@Gavinic after you fine-tune the model, you can get the .ckpt files. Then you need to export the graph as follows: python object_detection/export_inference_graph.py \ --input_type image_tensor \ --pipeline_config_path object_detection/samples/configs/ssdlite_mobilenet_v2.config \ --trained_checkpoint_prefix model.ckpt-${CHECKPOINT_NUMBER} \ --output_directory exported_graphs Afterwards, you should see a directory named exported_graphs containing the SavedModel and frozen graph.
After exporting the graph , how do i import the frozen graph model created in the output directory in tensorflowjs . Looking at the standard documentation , the tensorflowjs_converter is to be used , but after it it always gives me an error that "KeyError: 'The name "\'detection_boxes" refers to an Operation not in the graph.'"
Here is the conversion command below :
(tensorflowjs) c:>tensorflowjs_converter --input_format=tf_frozen_model --output_node_names='detection_boxes,detection_scores,detection_classes,num_detections' --saved_model_tags=serve C:/model_conv/inference_graph/frozen_inference_graph.pb C:/model_conv/inference_graph/web_model
and the Traceback call error below:
Traceback (most recent call last):
File "c:\programdata\anaconda3\envs\tensorflowjs\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\programdata\anaconda3\envs\tensorflowjs\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\ProgramData\Anaconda3\envs\tensorflowjs\Scripts\tensorflowjs_converter.exe__main__.py", line 7, in
My conda environment is: (tensorflowjs) c:>pip list Package Version
absl-py 0.9.0 astunparse 1.6.3 cachetools 4.1.0 certifi 2020.4.5.1 chardet 3.0.4 gast 0.3.3 google-auth 1.15.0 google-auth-oauthlib 0.4.1 google-pasta 0.2.0 grpcio 1.29.0 h5py 2.10.0 idna 2.9 Keras-Preprocessing 1.1.2 Markdown 3.2.2 numpy 1.18.4 oauthlib 3.1.0 opt-einsum 3.2.1 pip 20.0.2 prompt-toolkit 1.0.14 protobuf 3.11.3 pyasn1 0.4.8 pyasn1-modules 0.2.8 Pygments 2.6.1 PyInquirer 1.0.3 regex 2020.5.14 requests 2.23.0 requests-oauthlib 1.3.0 rsa 4.0 scipy 1.4.1 setuptools 46.4.0.post20200518 six 1.14.0 tensorboard 2.2.1 tensorboard-plugin-wit 1.6.0.post3 tensorflow-cpu 2.2.0 tensorflow-estimator 2.2.0 tensorflow-hub 0.7.0 tensorflowjs 1.7.4.post1 termcolor 1.1.0 urllib3 1.25.9 wcwidth 0.1.9 Werkzeug 1.0.1 wheel 0.34.2 wincertstore 0.2 wrapt 1.12.1
The environment in which object_detection_api was used is python=3.5 and tensorflow=1.5
Kindly Help , as I want to consume the trained model in tensorflowjs.
System information What is the top-level directory of the model you are using: research/object_detection Have I written custom code: no OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04 TensorFlow installed from (source or binary): source TensorFlow version (use command below): 1.11 Bazel version (if compiling from source):1.18 CUDA/cuDNN version: 9.0/7.1 GPU model and memory:[GeForce 1080Ti] Exact command to reproduce: using the object_detection/model_main.py as described in tutorials
Describe the problem I try to fine-tune the ssdlite_mobilenet_v2_coco_2018_05_09 model, and I use the checkpoint files (model.ckpt) to predict objects after training, but I got an error: KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."
Source code / logs the pipeline.config I used is: (models/research/object_detection/samples/configs/ssdlite_mobilenet_v2_coco.config) the pretrain_weight is from: (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md) I follow the training steps discribed in (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_locally.md)
the test script I use is as follows: `
` and it got an error: Traceback (most recent call last): File "test_tf.py", line 54, in
image_tensor = sess.graph.get_tensor_by_name('image_tensor:0')
File "/home/cyj/anaconda3/envs/tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3664, in get_tensor_by_name
return self.as_graph_element(name, allow_tensor=True, allow_operation=False)
File "/home/cyj/anaconda3/envs/tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3488, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "/home/cyj/anaconda3/envs/tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3530, in _as_graph_element_locked
"graph." % (repr(name), repr(op_name)))
KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."
my training process went smoothly, but why the model.ckpt files after training seemed wrong?
I print all the Tensor names in my trained model.ckpt files, Its really haven't the "image_tensor:0" Tensor. its different from the model.ckpt files that provided by (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md)