5
votes

I currently code my models with tensorflow 2.0 and I want to run them with opencv 4 (I want to compare performance). But I can't find a way to convert my tensorflow model for opencv.

For running in opencv I want to use:

cv2.dnn.readNetFromTensorflow('saved_model.pb', 'saved_model.pbtxt')

but when I save my model with:

model.save('./')

I obtain this files:

saved_model.pb | variables/variables.index | variables/variables.data-00000-of-00002 |variables/variables.data-00001-of-00002

I have a my .pb but not my .pbtxt. How it is possible to write this file ? According to opencv documentation this file is the text graph definition. I already try to write a .pbtxt with model.to_json() but it didn't work :/

Do you have any ideas ?

Thanks in advance !

Tanguy

1

1 Answers

0
votes

Additionally, OpenCV requires an extra configuration file based on the .pb, the .pbtxt. It is possible to import your own models and generate your own .pbtxt files by using one of the following files from the OpenCV Github repository...

Here is a link to tutorial: https://jeanvitor.com/tensorflow-object-detecion-opencv/ Haven't tried it myself, but seems legit. For example tf_text_graph_ssd.py does job done.