0

i wanna put this model (https://www.pyimagesearch.com/2020/05/04/covid-19-face-mask-detector-with-opencv-keras-tensorflow-and-deep-learning/) to works in a C++ code,the model is written using keras and H5,so i search and i discovered than i need first to convert my h5 model to a pb model because the opencv dont have h5 support.

following this guide (https://www.youtube.com/watch?v=2UgqCwVfdJY) i could do it and now i have a prototxt file and a pb file

so all that i need is to go in my code and write:

'''cv::dnn::Net mask_net = cv::dnn::readNetFromTensorflow("output_graph.pb","proto_file.prototxt");

right? but is not working... i tried another models like sddmobilinet2 and works well, but with this custom model, it doesn't works

i have this log:

terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.4.0-pre) /home/luiz/Libraries/CPP/opencv/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp:1016: error: (-215:Assertion failed) permIds.size() == net.node_size() in function 'sortByExecutionOrder'

Aborted (core dumped)

can anyone help-me?

1 Answers1

0

I ran into the same issue and managed to fix it by using only the frozen .pb file. OpenCV gives only the model + config function declaration in the documentation:

cv::dnn::readNetFromTensorflow  (const String & model, const String & config = String())    

But the one with only the model can be used as well:

cv::dnn::readNetFromTensorflow  (const String & model)  

For a good example of how to freeze a graph in TensorFlow 2, see: How to save Keras model as frozen graph?.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
dnl_anoj
  • 361
  • 1
  • 10
  • cv::dnn::Net inputNet; inputNet = cv::dnn::readNet("/home/tf/Projects/TF24/as/frozen_graph_210729_42.pb"); and I get the following error: terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.1.0) /home/tf/Downloads/opencv-4.1.0/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp:860: error: (-215:Assertion failed) nodesMapIt != nodesMap.end() in function 'sortByExecutionOrder' Aborted (core dumped) – fisakhan Oct 19 '21 at 10:54