Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Unable to convert TF_slim model to IR format #3787

Closed
3 tasks done
varunjain3 opened this issue Jan 8, 2021 · 11 comments
Closed
3 tasks done

[Bug] Unable to convert TF_slim model to IR format #3787

varunjain3 opened this issue Jan 8, 2021 · 11 comments
Assignees

Comments

@varunjain3
Copy link

varunjain3 commented Jan 8, 2021

System information (version)
  • OpenVINO => 2021.2.185
  • Operating System / Platform => Docker Image
  • Problem classification: Model Conversion
  • Framework: TensorFlow 1.15
  • Model name: InceptionV3
Detailed description

I want to use my custom fine-tuned InceptionV3 classification model to work with dlstreamer,

I was following this reference and this reference

I completed all the steps as per the TF_slim repository. After using the freeze_graph.py file I was able to freeze my model, file size being ~85mbs, exactly similar to this post.

Now I'm not really sure how I can I use mo_tf.py to convert my frozen model to the .XML and .bin format.
I tried these commands and all of them failed:

python3 mo_tf.py --input_model final.pb 
Model Optimizer arguments:
Common parameters:
	- Path to the Input Model: 	/opt/intel/openvino_2021.2.185/deployment_tools/model_optimizer/final.pb
	- Path for generated IR: 	/opt/intel/openvino_2021.2.185/deployment_tools/model_optimizer/.
	- IR output name: 	final
	- Log level: 	ERROR
	- Batch: 	Not specified, inherited from the model
	- Input layers: 	Not specified, inherited from the model
	- Output layers: 	Not specified, inherited from the model
	- Input shapes: 	Not specified, inherited from the model
	- Mean values: 	Not specified
	- Scale values: 	Not specified
	- Scale factor: 	Not specified
	- Precision of IR: 	FP32
	- Enable fusing: 	True
	- Enable grouped convolutions fusing: 	True
	- Move mean values to preprocess section: 	None
	- Reverse input channels: 	False
TensorFlow specific parameters:
	- Input model in text protobuf format: 	False
	- Path to model dump for TensorBoard: 	None
	- List of shared libraries with TensorFlow custom layers implementation: 	None
	- Update the configuration file with input/output node names: 	None
	- Use configuration file used to generate the model with Object Detection API: 	None
	- Use the config file: 	None
Model Optimizer version: 	2021.2.0-1877-176bdf51370-releases/2021/2
[ ERROR ]  Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.front.output_cut.OutputCut'>): Graph contains 0 node after executing <class 'extensions.front.output_cut.OutputCut'>. It considered as error because resulting IR will be empty which is not usual
python3 mo_tf.py --input_model final.pb -ms '[127.5,127.5,127.5]' --scale 127.5
Model Optimizer arguments:
Common parameters:
	- Path to the Input Model: 	/opt/intel/openvino_2021.2.185/deployment_tools/model_optimizer/final.pb
	- Path for generated IR: 	/opt/intel/openvino_2021.2.185/deployment_tools/model_optimizer/.
	- IR output name: 	final
	- Log level: 	ERROR
	- Batch: 	Not specified, inherited from the model
	- Input layers: 	Not specified, inherited from the model
	- Output layers: 	Not specified, inherited from the model
	- Input shapes: 	Not specified, inherited from the model
	- Mean values: 	[127.5,127.5,127.5]
	- Scale values: 	Not specified
	- Scale factor: 	127.5
	- Precision of IR: 	FP32
	- Enable fusing: 	True
	- Enable grouped convolutions fusing: 	True
	- Move mean values to preprocess section: 	None
	- Reverse input channels: 	False
TensorFlow specific parameters:
	- Input model in text protobuf format: 	False
	- Path to model dump for TensorBoard: 	None
	- List of shared libraries with TensorFlow custom layers implementation: 	None
	- Update the configuration file with input/output node names: 	None
	- Use configuration file used to generate the model with Object Detection API: 	None
	- Use the config file: 	None
Model Optimizer version: 	2021.2.0-1877-176bdf51370-releases/2021/2
[ ERROR ]  Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.front.output_cut.OutputCut'>): Graph contains 0 node after executing <class 'extensions.front.output_cut.OutputCut'>. It considered as error because resulting IR will be empty which is not usual
python3 mo_tf.py --input_model final.pb --input input --input_shape=[1,299,299,3]
Model Optimizer arguments:
Common parameters:
	- Path to the Input Model: 	/opt/intel/openvino_2021.2.185/deployment_tools/model_optimizer/final.pb
	- Path for generated IR: 	/opt/intel/openvino_2021.2.185/deployment_tools/model_optimizer/.
	- IR output name: 	final
	- Log level: 	ERROR
	- Batch: 	Not specified, inherited from the model
	- Input layers: 	input
	- Output layers: 	Not specified, inherited from the model
	- Input shapes: 	[1,299,299,3]
	- Mean values: 	Not specified
	- Scale values: 	Not specified
	- Scale factor: 	Not specified
	- Precision of IR: 	FP32
	- Enable fusing: 	True
	- Enable grouped convolutions fusing: 	True
	- Move mean values to preprocess section: 	None
	- Reverse input channels: 	False
TensorFlow specific parameters:
	- Input model in text protobuf format: 	False
	- Path to model dump for TensorBoard: 	None
	- List of shared libraries with TensorFlow custom layers implementation: 	None
	- Update the configuration file with input/output node names: 	None
	- Use configuration file used to generate the model with Object Detection API: 	None
	- Use the config file: 	None
Model Optimizer version: 	2021.2.0-1877-176bdf51370-releases/2021/2
[ ERROR ]  Exception occurred during running replacer "REPLACEMENT_ID" (<class 'extensions.front.user_data_repack.UserDataRepack'>): No node with name input

Extra Details:

I used the master branch of tensorflow/models repo commit = 7786b741e3ee5692819264568341dfc84f6b07b7 to fine-tune the pre-trained model with TF1.15
Used tf2.1 to convert the frozen model using freeze_graph.py
Using the current development docker image of the dl_streamer for OpenVINO environment
Here are my model files and the frozen model - https://drive.google.com/drive/folders/1lWHnrEos6fy0hE7qr8o832sg1v0cA2zF?usp=sharing

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, Stack Overflow, etc and have not found solution
  • There is reproducer code and related data files: images, videos, models, etc.
@varunjain3 varunjain3 added bug Something isn't working support_request labels Jan 8, 2021
@avitial
Copy link
Contributor

avitial commented Jan 11, 2021

Hi @varunjain3, thanks for reaching out. I am trying to access your model files but unable to, I just requested access. Allow me to investigate once I can see your model files.

Regards,
Luis

@avitial avitial self-assigned this Jan 11, 2021
@varunjain3
Copy link
Author

Hi @avitial , https://drive.google.com/folderview?id=1plG4GE3qLLtB35om4gcKTx8YQgM6LqUT

This link might help, let me know. I haven't set any restrictions on the sharing settings as such

@avitial
Copy link
Contributor

avitial commented Jan 11, 2021

@varunjain3 I can access your model files now, may I ask how did you freeze the model? Glancing at final.pb I can't find an input layer.

@varunjain3
Copy link
Author

varunjain3 commented Jan 12, 2021

@avitial I tried several approaches, all of them had the same issue.

  • changing meta data index files to directly .pb file
  • getting the freeze_graph.py script and running it directly (with the appropriate flags)
  • manually freezing the graph as per the steps from the freeze_graph.py

I did this, as I wasn't able to build the bazel tensorflow :/

@avitial
Copy link
Contributor

avitial commented Jan 13, 2021

@varunjain3 thanks for clarification, unfortunately I am unable to convert this specific model. Let me check with my peers and see if they have any insights on this. If you don't mind please include the freeze_graph.py script used as well as the flags. Also a link to the base InceptionV3 model used for fine tuning, I assume you got it from tf_slim.

Regards,
Luis

@avitial avitial added category: MO Model Optimizer TCE labels Jan 13, 2021
@varunjain3
Copy link
Author

varunjain3 commented Jan 13, 2021

@avitial I have added the freeze_graph.py in the same drive folder for your reference, the file works with Tensorflow > 2.0 as per my observation.

Here are the flags I used with freeze_graph.py -

python freeze_graph.py --input_graph=$(TRAIN_DIR)/all/graph.pbtxt \
	--input_checkpoint=$(TRAIN_DIR)/all/model.ckpt-3000 \
	--input_binary=false \
	--output_graph=$(TRAIN_DIR)/all/frozen_graph.pb \
	--output_node_names="InceptionV3/Predictions/Reshape_1"

Yes, I have closely followed all the steps from the tf_slim official repository, just changed the dataset with mine.

@asirvaiy asirvaiy assigned asirvaiy and unassigned asirvaiy Jan 15, 2021
@sevhabert sevhabert self-assigned this Jan 15, 2021
@sevhabert
Copy link

@varunjain3 The issue is coming from the first layers in the frozen graph: prefetch_queue/fifo_queue and fifo_queue_Dequeue. They should not be there, so I think something went wrong in freezing. Our documentation shows how to freeze and convert TF-Slim models: https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_tf_specific_Convert_Slim_Library_Models.html . First, make sure that your steps are similar to those. Second, in this link and the one you had from our forum, there is a step to show the topology (summarize_graph.py). Could you output the result? The current graph does not have "input" as actual input but prefetch_queue/fifo_queue.

@varunjain3
Copy link
Author

Our documentation shows how to freeze and convert TF-Slim models: https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_tf_specific_Convert_Slim_Library_Models.html .

@sevhabert, I was using the same documentation initially, but the document only contains a reference to convert the pre-trained checkpoint of the inceptionV1. As per the issues raised by others on the same problem, I found the forum insights useful and thus stuck to them closely.

step to show the topology (summarize_graph.py). Could you output the result? The current graph does not have "input" as actual input but prefetch_queue/fifo_queue.

When I tried running the summarize_graph.py, I got the same results as you, which says that the input layer is prefetch_queue/fifo_queue.

As the documentation is quite old on the OpenVINO site, it would really help, if there was a step by step guide to convert the custom-trained model for the new Inception models.

@varunjain3
Copy link
Author

If possible, could you share a guide to make tf records from a custom dataset of images? I m not sure if that should be the cause of this problem though

@sevhabert
Copy link

I tested the summarize_graph on your model frozen.pb using TF 1.15 and actually I get an error due to TF mismatch.
ValueError: NodeDef mentions attr 'exponential_avg_factor' not in Op<name=FusedBatchNorm; signature=x:T, scale:T, offset:T, mean:T, variance:T -> y:T, batch_mean:T, batch_variance:T, reserve_space_1:T, reserve_space_2:T; attr=T:type,allowed=[DT_FLOAT]; attr=epsilon:float,default=0.0001; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]; attr=is_training:bool,default=true>; NodeDef: {{node InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/FusedBatchNorm}}. (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).

The graph has some attributes only present in TF 2.0: onnx/tensorflow-onnx#862 . Mixing the TF version for the training (TF 1.15) and the freezing (tf 2.0) should be avoided and can only be source for error. Can you freeze your model with TF 1.15 ?

@avitial
Copy link
Contributor

avitial commented Jan 26, 2021

Closing this, I hope previous responses were sufficient to help you proceed. Feel free to reopen and ask additional questions related to this topic.

~Luis

@avitial avitial closed this as completed Jan 26, 2021
@avitial avitial removed the bug Something isn't working label Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants