I want to count parameters in a tensorflow model. It is similar to the existing question as follows.
How to count total number of trainable parameters in a tensorflow model?
But if the model is defined with a graph loaded from .pb file, all the proposed answers don't work. Basically I loaded the graph with the following function.
def load_graph(model_file):
graph = tf.Graph()
graph_def = tf.GraphDef()
with open(model_file, "rb") as f:
graph_def.ParseFromString(f.read())
with graph.as_default():
tf.import_graph_def(graph_def)
return graph
One example is to load a frozen_graph.pb file for retraining purpose in tensorflow-for-poets-2.