Ask Your Question
0

DNN - own tensorflow model and issues with dropout

asked 2018-04-09 04:27:01 -0600

Flipajs gravatar image

Hey guys, does anyone have an experience with training own TF model (nothing fancy, just Conv, Dropout, FC layers...). I am struggling with converting model so I can load it using OpenCV.DNN module. I've followed this approach. The problem is, that in the end there are still dropout layers.

dropout/random_uniform/max
dropout/random_uniform/min
dropout/random_uniform/sub
dropout/div
dropout/Shape
dropout/random_uniform/RandomUniform
dropout/random_uniform/mul
dropout/random_uniform
dropout/add
dropout/Floor
dropout/mul

And when I load the model (cv2.dnn.readNetFromTensorflow('deploy.pb')) I get an error (which make sense):

OpenCV(3.4.1) Error: Unspecified error (Unknown layer type Shape in op dropout/Shape) in populateNet, file /tmp/opencv-20180307-60086-ryy1b3/opencv-3.4.1/modules/dnn/src/tensorflow/tf_importer.cpp, line 1582 Traceback (most recent call last):
  File "run_tensorflow.py", line 24, in <module>
    net = cv2.dnn.readNetFromTensorflow('optimized_model.pb')
cv2.error: OpenCV(3.4.1) /tmp/opencv-20180307-60086-ryy1b3/opencv-3.4.1/modules/dnn/src/tensorflow/tf_importer.cpp:1582: error: (-2) Unknown layer type Shape in op dropout/Shape in function populateNet

Am I missing something?

Thanks in advance!

edit retag flag offensive close merge delete

Comments

1

@Flipajs, May I ask you to point what dropout operation from TensorFlow is actually used? In example, tf.nn.dropout or tf.layers.dropout or something else? Nowadays OpenCV has some mechanic to fuse TensorFlow subgraphs during import so we can fix it in a future PR. Actually, there is one more way is to define a graph without dropout layer, save it using tf.train.write_graph and then freeze with existing checkpoint.

dkurt gravatar imagedkurt ( 2018-04-09 04:43:57 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-04-09 06:09:21 -0600

Flipajs gravatar image

updated 2018-04-09 06:10:30 -0600

@dkurt, Thanks for fast response. I was using tf.nn.dropout and now I see... tf.nn.dropout is not adding information about is_training thus freezing is not removing it and it slips through to deployed model. So when I've changed it to tf.layers.dropout and then I do graph_freeze -> optimize_for_inference -> (if necessary graph_transform) it is working now. Thanks! You are doing a great job.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-04-09 04:27:01 -0600

Seen: 727 times

Last updated: Apr 09 '18