In general, there are two functions for printing tensorflow variables:
tf.trainable_variables () and Tf.all_variables ()
The difference is:
Tf.trainable_variables () refers to the variables that need to be trained
Tf.all_variables () refers to all variables
In general, we are more concerned with training variables that need to be trained:
It is important to note that the entire graph is initialized when the variable name is output
First, print the name of the variable you need to train
Sess.run (Tf.global_varibales_initializer ())
variable_name = [v.name for C in Tf.trainable_variables ()]
print (Variable_names)
Second, print the variable name and variable value to be trained
Variable_names = [V.name for V ' tf.trainable_variables ()]
values = Sess.run (variable_names) for
k,v in Zip (vari Able_names, values): Print ("
Variable:", k) print (
"Shape:", V.shape)
print (v)
here is a function to print the variable name, shape and the number of its variables
def print_num_of_total_parameters (Output_detail=false, output_to_logging=false): total_parameters = 0 parameters_s Tring = "" For variable in Tf.trainable_variables (): Shape = Variable.get_shape () variable_parameter s = 1 for Dim in Shape:variable_parameters *= dim.value total_parameters + = Variable_paramete
RS If Len (shape) = = 1:parameters_string + = ("%s%d,"% (Variable.name, variable_parameters)) Else:parameters_string + = ("%s%s=%d,"% (Variable.name, str (SHAPE), variable_parameters)) if output_t O_logging:if output_detail:logging.info (parameters_string) logging.info ("Total%d variables,
%s params "% (Len (Tf.trainable_variables ())," {:,} ". Format (total_parameters))) Else:if Output_detail: Print (parameters_string) print ("Total%d variables,%s params"% (Len (Tf.trainable_variables ()), "{:,}". Form at (total_parameters)))