How to import a tensorflow model with dropout in opencv
Hi, I tried using the advice here -> https://github.com/opencv/opencv/issu.... Saving the checkpoint with dropout and saving the graph without dropout. Here is the issue that I face, along with the name of all the layers read by OpenCV 3.4.1:
Conv1/convolution1/Conv2D
Conv1/convolution1/Relu
Conv1/pooling_1
Conv2/convolution2/Conv2D
Conv2/convolution2/Relu
Conv2/pooling_2
Conv3/convolution3/Conv2D
Conv3/convolution3/Relu
Conv3/Reshape/nchw Conv3/Reshape
Dense1/fully_connected5/MatMul
Dense1/fully_connected5/Relu
Dense2/fully_connected6/MatMul
Dense2/fully_connected6/Relu
Dense2/output_node [ INFO:0]
Initialize OpenCL runtime...
OpenCV(3.4.1) Error: Backtrace (Can't infer a dim denoted by -1) in computeShapeByReshapeMask, file /home/ayushpandey/opencv/modules/dnn/src/layers/reshape_layer.cpp, line 136 terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /home/ayushpandey/opencv/modules/dnn/src/layers/reshape_layer.cpp:136: error: (-1) Can't infer a dim denoted by -1 in function computeShapeByReshapeMask
Aborted (core dumped)
Here is my tensorflow code ->https://pastebin.com/mMgRbHV0 ( Commented lines are uncommented and the lines corresponding to uncommented pool1, pool2 and saver.save is commented for saving graph without dropout ).
Then I run the following commands to freeze the graph.
python freeze_graph.py --input_graph=./input_graph.pb --input_checkpoint=./with_dropout.ckpt --output_graph=./output_graph.pb --output_node=Dense2/output_node
followed by
python optimize_for_inference.py --input output_graph.pb --output without_dropout.pb --frozen_graph True --input_names input_node --output_names Dense2/output_node
and then I try to load the "without_dropout.pb" with OpenCV where I face the issue.
@AyushP123,
without_dropout.pb
attached can save some time to reproduce the problem. Please put a reference if it's possible.https://drive.google.com/file/d/1fIpp...
@AyushP123, please specify input dimensions.
[NONE, 125, 125, 1]
@AyushP123, please check it again because the model doesn't work even in TensorFlow with 125x125 inputs.
Sorry for the mistake .... the input size is [NONE, 250, 250, 1]