from tensorflow.python import pywrap_tensorflow
import os
import numpy as np
import argparse
defmain(args):
model_dir = args["model_dir_path"]
detecotr = TOD()
detecotr.paramstest(model_dir)classTOD(object):def__init__(self):
self.self = self
defparamstest(self,model_dir):
checkpoint_path = os.path.join(model_dir,"model.ckpt")
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()
total_parameters =0for key in var_to_shape_map:#list the keys of the model# print(key)# print(reader.get_tensor(key))
shape = np.shape(reader.get_tensor(key))#get the shape of the tensor in the model
shape =list(shape)# print(shape)# print(len(shape))
variable_parameters =1for dim in shape:# print(dim)
variable_parameters *= dim
# print(variable_parameters)
total_parameters += variable_parameters
total_parameters = total_parameters /1000000print("=========================================================")print("Finish! The parameters of this model!")print(str(total_parameters)+"M parameters.")if __name__ =='__main__':
ap = argparse.ArgumentParser()
ap.add_argument("-model","--model_dir_path",
required=True,help="directory path of model files")
args =vars(ap.parse_args())
main(args)