-
Notifications
You must be signed in to change notification settings - Fork 74.6k
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
optimize_for_inference.py should remove Dropout operations #5867
Comments
Yes, it would be nice if the |
related / dupe: #6124 |
There is also this SO (attempt at a) solution: http://stackoverflow.com/questions/40358892/wipe-out-dropout-operations-from-tensorflow-graph for node in temp_graph_def.node:
for idx, i in enumerate(node.input):
input_clean = node_name_from_input(i)
if input_clean.endswith('/cond/Merge') and input_clean.split('/')[-3].startswith('dropout'):
identity = node_from_map(input_node_map, i).input[0]
assert identity.split('/')[-1] == 'Identity'
parent = node_from_map(input_node_map, node_from_map(input_node_map, identity).input[0])
pred_id = parent.input[1]
assert pred_id.split('/')[-1] == 'pred_id'
good = parent.input[0]
node.input[idx] = good |
i'am getting the following error in android |
Is there anyway this can be accomplished using the transform_graph tool and remove_nodes? |
Is there a way to get rid of the dropout in a model? I am currently trying to remove it but I haven't found a way yet :
Any updates on this ? |
Is using a tensor for keep_prob which is set to 1 during inference not enough? |
Any updates on this? Just tried optimize_for_inference.py but dropout still there confusing NVIDIA TensorRT and Jetson TX2 inference. |
There is a way to create a new graph and copy all the nodes you want (except dropout) from the old graph to the new one, fixing the input/output names of the nodes before and after the dropout layer. This way you can create a new graph without the dropout layer. |
Please let optimize_for_inference remove dropout layers from the graph. To allow the conversion to TFLite, I need to remove the dropout layer in my MNIST model frozen graph. If I get it right, the only way to do that (without writing a python script for that) is to use the Graph Transform Tool. The funny thing is that in prediction mode the dropout would not even be used. If I am missing something please tell me - I would be overjoyed to know I got it wrong. |
Run training script -> export_inference_graph -> freeze_graph . This removes all the extra nodes added during training. I was trying to convert finetuned inception model to uff format required by Jetson, and got issues due to the same RandomUniform node and a few others dropout related nodes. Running export_inference_graph on finetuned model before freezing fixed the issue. |
Hi @shrutim90 , can you please provide more information on the export_inference_graph script? |
@AndRossi : In this link: https://github.com/tensorflow/models/tree/master/research/slim#Pretrained , they have used export_inference_graph script to export default inception graph. If you'll check the code for that script, you'll see there is an option to specify dataset_name as well. python export_inference_graph.py So you can specify any dataset predefined in slim library or add you own data in the slim dataset and then use above script, with required dataset_name. It will create graph with all the extra layers removed and correct number of output nodes. |
@shrutim90 It didn't work for me. When I use a tf.slim model with my own dataset and is_training=True I obtain a checkpoint with 97% accuracy. If I then import this checkpoint into the same tf.slim model but with is_training=False I get only around 40% accuracy. |
You should freeze the training checkpoint into a separate eval/inference graph. You should have separate python code to constructor this eval_graph. Take a look at tf_estimator model_fn to see how it encourages constructing a different graph for training/eval/inference. That graph should be compatible with TF Lite. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py In general, it's difficult to convert a training graph into an inference graph because batch norm and dropout create different graphs for training or eval. |
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks! |
@tofulawrence I bet you had a look on this #19264, can you comment why it can't be upstreamed ? Does it fail some internal test cases ? |
I got dropout ops convert fail in tensorrt 4.0
|
I've just approved the PR related to this one. Sorry for the delay in reviewing. |
which version can solve this problem。hope comming soon |
Any update on the solution yet ? |
I think that the only way to remove dropout for now is to comment out the dropout lines in your python source code and export the model without them ... |
Any update on this issue yet? |
1 similar comment
Any update on this issue yet? |
Hi @cancan101, what is |
One comment to add - it's hard to debug if you don't know what this means:
or
which either indicate the use for a |
Imported from GitHub PR openxla/xla#5867 Fixed a recent build error due to the missing link at rocm gpu executor and some updates on rocm_driver @akuegel @ddunl Thanks in advance! Copybara import of the project: -- 63801cf1b46aee77ccc272e0eb65624367553fe2 by Chao Chen <cchen104@amd.com>: fixed rocm kernel link Merging this change closes #5867 PiperOrigin-RevId: 568485642
When I first tried using an exported MNIST model with TensorFlow on iOS, I got the following error:
Since Dropout operations are no-ops during inference (we pass in a keep probability of 1), it would be nice if they were removed (or turned into no-ops of some kind that can be parsed and ignored by the iOS library).
While I was able to work around this by explicitly exporting a separate graph that does not contain Dropout, it was pretty tedious and it would be nice if the
optimize_for_inference.py
script did this automatically.Environment info
Operating System: macOS 10.12
Installed version of CUDA and cuDNN:
None
Source:
This week's tip-of-tree (around d93d526)
The text was updated successfully, but these errors were encountered: