Loading weights into a keras model from a .pb filed generated by tf.simple_save() in TensorFlow 1.15.2

Viewed 314

I am struggling with restoring a keras model from a .pb file. I have seen a couple of posts explaining how to do inference using a model saved in .pb format, but what I need is to load the weights into a keras.Model class.

I have a function that returns an instance of the said original model, but untrained. I want to restore the weights of that model from the .pb file. My goal is to then truncate the model and use the truncated model for other purposes.

So far the furthest I've gotten is using the tf.saved_model.load(session, ['serving'], export_dir) function to get a tensorflow.core.protobuf.meta_graph_pb2.MetaGraphDef object. From here I can access the graph_def attribute, and from there the nodes.

How can I go from that to getting the weights and then loading those into the instance of the untrained keras Model?

Maybe if that's not doable there is a way to "truncate" the graph_def somehow and then make inference using that?

0 Answers
Related