Issue with .pb file after creating it from checkpoint files using Tensorflow

18 Views Asked by At

I have converted a saved model with checkpoints to a .pb file. But after generating .pb file it is not able to open with netron app.

I have used below logic to convert it.

trained_checkpoint_prefix = f'{ckpt_dir_path}/model.ckpt'
export_dir = os.path.join(key, 'saved_model')

graph = tf.Graph()
with tf.compat.v1.Session(graph=graph) as sess:
    # Restore from checkpoint
    loader = tf.compat.v1.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
    loader.restore(sess, trained_checkpoint_prefix)

    # Export checkpoint to SavedModel
    builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_dir)
    builder.add_meta_graph_and_variables(sess, [tf.saved_model.TRAINING, tf.saved_model.SERVING], strip_default_attrs=True)
    builder.save()

My TF version is v2.13.

I tried with using import_meta_graph and restore and then save.

Is there any other way with which I can load checkpoint files directly and save model as TF saved model file without loading actual model?

0

There are 0 best solutions below