Unable to load the frozen model (.pb) in GraphDef in tensorflow version 2.x

1.6k views Asked by At
  1. Created a simple dummy sequential model in tf.keras as shown below:

    model = tf.keras.Sequential()
    model.add(layers.Dense(10, input_shape=(100, 100)))
    model.add(layers.Conv1D(3, 2))
    model.add(layers.Flatten())
    model.add(layers.Dense(10, activation='softmax', name='predict_10'))
    
  2. Trained the model and saved it using tf.keras.models.saved_model.

  3. To get the input input and output node names used saved_model_cli.

    saved_model_cli show --dir "path/to/SavedModel" --all
    

    enter image description here

  4. Froze the saved model with freeze_graph.py utility.

    python freeze_graph.py --input_saved_model_dir=<path/to/SavedModel> --output_graph=<path/freeze.pb> --input_binary=True --output_node_names=StatefulPartitionedCall
    

    Model is frozen.

Now Here's the main issue:

  1. To load the frozen graph I've used this guide Migrate tf1.x to tf2.x (wrap_frozen_graph)
  2. Used
    with tf.io.gfile.GFile("patf/to/freeze.pb", 'rb') as f:
       graph_def = tf.compat.v1.GraphDef()
       graph_def.ParseFromString(f.read())
    load_frozen = wrap_frozen_graph(graph_def, inputs='dense_3_input:0', outputs='predict_10:0')
    
  3. Output error ValueError: Input 1 of node StatefulPartitionedCall was passed float from dense_3/kernel:0 incompatible with expected resource.

I'm getting same error when converting .pb to .dlc (Qualcomm). Actually I want to run original model on Qualcomm's Hexagon DSP or GPU.

0

There are 0 answers