how Convert my tensorflow 2 using tflearn model to graph.pb file

113 Views Asked by At

I am trying to convert my model to CoreML so I save my model using this code

model2.save("modelcnn2.tfl")

then giving three model files as follow:

  • checkpoint
  • modelcnn2.tfl.data-00000-of-00001
  • modelcnn2.tfl.index
  • modelcnn2.tfl.meta

so how can convert to one graph.pb then convert to CoreMl

I use this code

 import tensorflow as tf
meta_path = '/content/drive/MyDrive/check/modelcnn2.tfl.meta' # Your .meta file
output_node_names = ['0',
                 '1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18',
                 '19''20','21','22','23','24','25','26','27','28']    # Output nodes
with tf.compat.v1.Session() as sess:
    # Restore the graph
    saver = tf.compat.v1.train.import_meta_graph(meta_path)
    # Load weights
    saver.restore(sess,tf.train.latest_checkpoint('path/of/your/.meta/file'))
    # Freeze the graph
    frozen_graph_def = tf.graph_util.convert_variables_to_constants(
        sess,
        sess.graph_def,
        output_node_names)
    # Save the frozen graph
    with open('output_graph.pb', 'wb') as f:
      f.write(frozen_graph_def.SerializeToString())

but this error appeared

KeyError: "The name 'Adam' refers to an Operation not in the graph."

so if any suggestion helps me, it is appreciated

1

There are 1 best solutions below

0
Jeshua Lacock On

The error is telling you exactly what the issue is.

Adam is not a supported operation. You have two options:

(1) Create a new model without an Adam layer.

(2) Implement a Custom Operators.