Skip to content

DNN, readNetFromTensorflow, assertion fails on addConstNodes, #14218

Closed

Description

@ndvbd

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?

Activity

  1. dkurt commented on Apr 1, 2019

    @dkurt
    Member

    Please provide a minimal working example or at least attach the mentioned model (.pb file).

  2. added
    needs reproducer
    on Apr 1, 2019
  3. ndvbd commented on Apr 2, 2019

    @ndvbd
    Author

    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 773

    Let me know if you need more info, like the code that created the layers (it's a very simple network).

    Appreciate the help.

  4. dkurt commented on Apr 2, 2019

    @dkurt
    Member

    @nadavb, you need to disable training phase before model serialization:

    image

  5. ndvbd commented on Apr 2, 2019

    @ndvbd
    Author

    @dkurt, it worked.

    1. 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.

    2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category: dnnneeds reproducer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions