DNN - own tensorflow model and issues with dropout
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!
@Flipajs, May I ask you to point what
dropout
operation from TensorFlow is actually used? In example,tf.nn.dropout
ortf.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 usingtf.train.write_graph
and then freeze with existing checkpoint.