Skip to content

pbtxt file from frozen tf trained graph cant work  #15817

Closed

Description

@toborobot

Situation:
I have trained own model with google colab (tensorflow 1.15). it works good.
Trying to prepare pbtxt file for opencv with this tutorial https://github.com/opencv/opencv/wiki/TensorFlow-Object-Detection-API
Recieve file which is only 24Kb (last worked file prepared at June was 124Kb).
This pbtxt file with frozen model raise mistake (core dumped).
I have test saved previous own frozen graph model prepared before and generate good worked pbtxt file.
That means problem is in new tf 1.15 or with colab environments probably... somebody have this mistakes?

name of nodes is different in last and new pbtxt files.

Activity

  1. added
    needs reproducer
    on Oct 31, 2019
  2. dkurt commented on Oct 31, 2019

    @dkurt
    Member

    We cannot help you without reproducer.

  3. toborobot commented on Oct 31, 2019

    @toborobot
    Author

    how better prepare You reproducer? Colab notebook will be ok?

  4. dkurt commented on Oct 31, 2019

    @dkurt
    Member

    @toborobot, .pb model with pipeline.config would be enough. Thanks.

  5. toborobot commented on Oct 31, 2019

    @toborobot
    Author

    fine_tuned_model.zip
    this model prerared with colab standart tensorflow environment (tf1.15) (base model ssd_mobilenet_v2 (2019_03_29)

    • plus 2 hours
      I have found that locally trained model with Tensorflow 1.13 reproduce good pbtxt file (~123Kb) and works good with Opencv dnn
    • plus 6 hours
    1. train graph with tensorflow 1.15
    2. make fine_tuned_model with tensorflow 1.14.1(from train_dir) (could be other version I have checked 1.14)
      pbtxt prepared correct - inference with cv2.dnn.readNetFromTensorflow(frozen_graph, pbtxt) is ok.

    problem is in between tensorflow 1.15 and tf_text_graph_ssd.py with high possibility... :)

    addons:
    tensorflow backward and forward compatibility policy - https://www.tensorflow.org/guide/versions

  6. dkurt commented on Dec 30, 2019

    @dkurt
    Member

    @toborobot, thanks for bug report!

    Please try to run this script first to get opt_graph.pb:

    import tensorflow as tf
    from tensorflow.python.tools import optimize_for_inference_lib
    
    with tf.gfile.FastGFile('frozen_inference_graph.pb', 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
    
    with tf.Session() as sess:
        # Restore session
        sess.graph.as_default()
        tf.import_graph_def(graph_def, name='')
    
    
    inp_nodes = ['image_tensor']
    out_nodes = ['num_detections', 'detection_scores', 'detection_boxes', 'detection_classes']
    
    graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, inp_nodes, out_nodes, tf.float32.as_datatype_enum)
    
    with tf.gfile.FastGFile("opt_graph.pb", 'wb') as f:
        f.write(graph_def.SerializeToString())

    Then using the changes from #16263 generate a .pbtxt file:

    python tf_text_graph_ssd.py --input opt_graph.pb --config pipeline.config --output graph.pbtxt

    Please let us know if the accuracy won't match or add a sample image so we can check.

  7. added and removed
    needs reproducer
    on Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions