First I have a gzipped file named maia-1900.pb.gz, I unzipped it by double clicking on mac and a file named maia-1900.pb was outputted. I tried loading the model with model = tf.saved_model.load("maia-1900")
but I got an error saying: OSError: SavedModel file does not exist at: maia-1900/{saved_model.pbtxt|saved_model.pb}
.
Then I realized that the file may be a frozen graph file and I tried to convert the frozen graph to a tensorflow model. I first tested out to see the nodes of the graph to find the input and output tensor by using this code:
import tensorflow as tf
def load_frozen_graph(pb_file):
with tf.io.gfile.GFile(pb_file, 'rb') as f:
graph_def = tf.compat.v1.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def, name='')
return graph
def print_all_nodes(graph):
"""Print all nodes in the graph."""
for op in graph.get_operations():
print(op.name)
def main(pb_file):
"""Main function to load the graph and print all nodes."""
graph = load_frozen_graph(pb_file)
print_all_nodes(graph)
# Path to the frozen graph file
pb_file_path = 'maia-1900.pb'
# Run the script
main(pb_file_path)
But I wasn’t able to find it and it kept saying that the graph had 0 nodes. I am very confused because the .pb file is definitely not an empty file. Please help me on how to integrate this .pb file with a tensorflow/keras model.
Thank you very much