import tensorflow as tf
saver = tf.train.import_meta_graph('xxx.meta')
variables = tf.trainable_variables()
total_parameters = 0
for variable in variables:
shape = variable.get_shape()
variable_parameters = 1
for dim in shape:
variable_parameters *= dim.value
print(variable)
print(variable_parameters)
total_parameters += variable_parameters
print(total_parameters)
当tensorflow版本过高降版本的方法
import tensorflow.compat.v1 as tf
tf.disable_v2_benhavior()