You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DNN, readNetFromTensorflow, assertion fails on addConstNodes, #14218
I created a simple convolutional net with Python + Tensorflow/keras, and can't load it in Opencv 4.0.1.
The readNetFromTensorflow throws assertion error.
Any ideas, best practices or examples how to export a classic conv networks from tensorflow+keras to .pb and .pbtxt files so they can be loaded with Opencv 4?
cv::dnn::readNetFromTensorflow("my_model.pb");
In debug mode, I get this error:
OpenCV(4.0.1) Error: Unspecified error (Tensor's data type is not supported) in cv::dnn::dnn4_v20181221::getTensorContent, file \4.0.1\src\modules\dnn\src\tensorflow\tf_graph_simplifier.cpp, line 773
Let me know if you need more info, like the code that created the layers (it's a very simple network).
I recommend, if it's possible, to add a more meaningful errors messages in these cases. In addition to writing "Tensor's data type is not supported", you can add the name of the Tensor that is not supported, and this way the "keras_learning_phase" name would have been popped out more easily so it would be feasible to debug it.
For the record, the way I removed this is by saving the keras model to hdf5 file, then set: tf.keras.backend.set_learning_phase(0)
Then create the model again, and load the weights from the filesystem (model.load_weights), and only then serialize it to a .pb file.
Activity
dkurt commentedon Apr 1, 2019
Please provide a minimal working example or at least attach the mentioned model (
.pbfile).ndvbd commentedon Apr 2, 2019
Thanks @dkurt, here is the .pb file,
my_model.zip
When I do:
cv::dnn::readNetFromTensorflow("my_model.pb");In debug mode, I get this error:
OpenCV(4.0.1) Error: Unspecified error (Tensor's data type is not supported) in cv::dnn::dnn4_v20181221::getTensorContent, file \4.0.1\src\modules\dnn\src\tensorflow\tf_graph_simplifier.cpp, line 773Let me know if you need more info, like the code that created the layers (it's a very simple network).
Appreciate the help.
dkurt commentedon Apr 2, 2019
@nadavb, you need to disable training phase before model serialization:
ndvbd commentedon Apr 2, 2019
@dkurt, it worked.
I recommend, if it's possible, to add a more meaningful errors messages in these cases. In addition to writing "Tensor's data type is not supported", you can add the name of the Tensor that is not supported, and this way the "keras_learning_phase" name would have been popped out more easily so it would be feasible to debug it.
For the record, the way I removed this is by saving the keras model to hdf5 file, then set:
tf.keras.backend.set_learning_phase(0)
Then create the model again, and load the weights from the filesystem (model.load_weights), and only then serialize it to a .pb file.