models/dense_net.py
def _count_trainable_params_in_use(self, write_to_ft_logs=False):
        """
        Uses TensorFlow commands to count the total number of trainable
        parameters in the graph, as well as the number of parameters that are
        currently 'in use'. This refers specifically to: the multiplied
        dimensions of each TF variable that is not a discarded transition to
        classes or batch normalization, or a pruned element.
        The method prints not only the number of parameters, but also the
        number of parameters in the convolutional and fully connected parts
        of the TensorFlow graph.

        Args:
            write_to_ft_logs: `bool`, if feature logs are being written,
                whether or not to write the parameter counts to those logs;
        """
        total_parameters = 0
        conv_params_in_use = 0
        fc_params_in_use = 0
        fc_name = 'FC_'
        t2fc_name = 'Transition_to_FC_'
        suffix = 'block_%d' % (self.total_blocks-1)
        if not self.preserve_transition_l:
            suffix += '_layer_%d' % (self.layer_num_list[-1]-1)
        true_fc_name = fc_name + suffix
        true_t2fc_name = t2fc_name + suffix
        true_t2fc_name += '/BatchNorm_%d' % self.batch_norm_counter

        # print("Variable names:")
        for variable in tf.trainable_variables():
            # print(variable.name)
            shape = variable.get_shape()
            variable_parameters = 1
            for dim in shape:
                variable_parameters *= dim.value
            # Add all identified parameters to total_parameters.
            total_parameters += variable_parameters
            # From here onwards only consider non-pruned parameters.
            if not (self.should_self_construct and
                    variable.name in self.pruned_varnames):
                # Add params from the current FC layer to fc_params_in_use.
                if variable.name.startswith(true_fc_name):
                    fc_params_in_use += variable_parameters
                # Add params from the current batchnorm to conv_params_in_use.
                elif variable.name.startswith(true_t2fc_name):
                    conv_params_in_use += variable_parameters
                # Add params not in a rejected batchnorm or FC layer (to conv).
                elif (not variable.name.startswith(fc_name) and
                      not variable.name.startswith(t2fc_name)):
                    conv_params_in_use += variable_parameters
        # Add together the two counts for parameters 'in use'.
        total_parameters_in_use = conv_params_in_use + fc_params_in_use

        print("Total trainable params: %.1fk" % (total_parameters / 1e3))
        print("Total params in use: %.1fk" % (total_parameters_in_use / 1e3))
        print("\tConvolutional: %.1fk" % (conv_params_in_use / 1e3))
        print("\tFully Connected: %.1fk" % (fc_params_in_use / 1e3))

        if self.should_save_ft_logs and write_to_ft_logs:
            self.feature_writer.write("\nTotal trainable params: %.1fk\n" % (
                total_parameters / 1e3))
            self.feature_writer.write("Total params in use: %.1fk\n" % (
                total_parameters_in_use / 1e3))
            self.feature_writer.write("Convolutional: %.1fk\n" % (
                conv_params_in_use / 1e3))
            self.feature_writer.write("Fully Connected: %.1fk\n" % (
                fc_params_in_use / 1e3))

        Uses TensorFlow commands to count the total number of trainable
        parameters in the graph, as well as the number of parameters that are
        currently 'in use'. This refers specifically to: the multiplied
        dimensions of each TF variable that is not a discarded transition to
        classes or batch normalization, or a pruned element.
        The method prints not only the number of parameters, but also the
        number of parameters in the convolutional and fully connected parts
        of the TensorFlow graph.

        Args:
            write_to_ft_logs: `bool`, if feature logs are being written,
                whether or not to write the parameter counts to those logs;
        
Uses TensorFlow commands to count the total number of trainable
parameters in the graph, as well as the number of parameters that are
currently 'in use'. This refers specifically to: the multiplied
dimensions of each TF variable that is not a discarded transition to
classes or batch normalization, or a pruned element.
The method prints not only the number of parameters, but also the
number of parameters in the convolutional and fully connected parts
of the TensorFlow graph.
Uses TensorFlow commands to count the total number of trainable parameters in the graph as well as the number of parameters that are currently ' in use ' . This refers specifically to : the multiplied dimensions of each TF variable that is not a discarded transition to classes or batch normalization or a pruned element . The method prints not only the number of parameters but also the number of parameters in the convolutional and fully connected parts of the TensorFlow graph .
def _count_trainable_params_in_use(self, write_to_ft_logs=False):
        total_parameters = 0
        conv_params_in_use = 0
        fc_params_in_use = 0
        fc_name = 'FC_'
        t2fc_name = 'Transition_to_FC_'
        suffix = 'block_%d' % (self.total_blocks-1)
        if not self.preserve_transition_l:
            suffix += '_layer_%d' % (self.layer_num_list[-1]-1)
        true_fc_name = fc_name + suffix
        true_t2fc_name = t2fc_name + suffix
        true_t2fc_name += '/BatchNorm_%d' % self.batch_norm_counter
        for variable in tf.trainable_variables():
            shape = variable.get_shape()
            variable_parameters = 1
            for dim in shape:
                variable_parameters *= dim.value
            total_parameters += variable_parameters
            if not (self.should_self_construct and
                    variable.name in self.pruned_varnames):
                if variable.name.startswith(true_fc_name):
                    fc_params_in_use += variable_parameters
                elif variable.name.startswith(true_t2fc_name):
                    conv_params_in_use += variable_parameters
                elif (not variable.name.startswith(fc_name) and
                      not variable.name.startswith(t2fc_name)):
                    conv_params_in_use += variable_parameters
        total_parameters_in_use = conv_params_in_use + fc_params_in_use
        print("Total trainable params: %.1fk" % (total_parameters / 1e3))
        print("Total params in use: %.1fk" % (total_parameters_in_use / 1e3))
        print("\tConvolutional: %.1fk" % (conv_params_in_use / 1e3))
        print("\tFully Connected: %.1fk" % (fc_params_in_use / 1e3))
        if self.should_save_ft_logs and write_to_ft_logs:
            self.feature_writer.write("\nTotal trainable params: %.1fk\n" % (
                total_parameters / 1e3))
            self.feature_writer.write("Total params in use: %.1fk\n" % (
                total_parameters_in_use / 1e3))
            self.feature_writer.write("Convolutional: %.1fk\n" % (
                conv_params_in_use / 1e3))
            self.feature_writer.write("Fully Connected: %.1fk\n" % (
                fc_params_in_use / 1e3))
def _count_trainable_params_in_use ( self , write_to_ft_logs = False ) : total_parameters = 0 conv_params_in_use = 0 fc_params_in_use = 0 fc_name = 'FC_' t2fc_name = 'Transition_to_FC_' suffix = 'block_%d' % ( self . total_blocks - 1 ) if not self . preserve_transition_l : suffix += '_layer_%d' % ( self . layer_num_list [ - 1 ] - 1 ) true_fc_name = fc_name + suffix true_t2fc_name = t2fc_name + suffix true_t2fc_name += '/BatchNorm_%d' % self . batch_norm_counter for variable in tf . trainable_variables ( ) : shape = variable . get_shape ( ) variable_parameters = 1 for dim in shape : variable_parameters *= dim . value total_parameters += variable_parameters if not ( self . should_self_construct and variable . name in self . pruned_varnames ) : if variable . name . startswith ( true_fc_name ) : fc_params_in_use += variable_parameters elif variable . name . startswith ( true_t2fc_name ) : conv_params_in_use += variable_parameters elif ( not variable . name . startswith ( fc_name ) and not variable . name . startswith ( t2fc_name ) ) : conv_params_in_use += variable_parameters total_parameters_in_use = conv_params_in_use + fc_params_in_use print ( "Total trainable params: %.1fk" % ( total_parameters / 1e3 ) ) print ( "Total params in use: %.1fk" % ( total_parameters_in_use / 1e3 ) ) print ( "\tConvolutional: %.1fk" % ( conv_params_in_use / 1e3 ) ) print ( "\tFully Connected: %.1fk" % ( fc_params_in_use / 1e3 ) ) if self . should_save_ft_logs and write_to_ft_logs : self . feature_writer . write ( "\nTotal trainable params: %.1fk\n" % ( total_parameters / 1e3 ) ) self . feature_writer . write ( "Total params in use: %.1fk\n" % ( total_parameters_in_use / 1e3 ) ) self . feature_writer . write ( "Convolutional: %.1fk\n" % ( conv_params_in_use / 1e3 ) ) self . feature_writer . write ( "Fully Connected: %.1fk\n" % ( fc_params_in_use / 1e3 ) )
Uses TensorFlow commands to count the total number of trainable
parameters in the graph, as well as the number of parameters that are
currently 'in use'.
Uses TensorFlow commands to count the total number of trainable parameters in the graph as well as the number of parameters that are currently ' in use ' .
"""
        Uses TensorFlow commands to count the total number of trainable
        parameters in the graph, as well as the number of parameters that are
        currently 'in use'. This refers specifically to: the multiplied
        dimensions of each TF variable that is not a discarded transition to
        classes or batch normalization, or a pruned element.
        The method prints not only the number of parameters, but also the
        number of parameters in the convolutional and fully connected parts
        of the TensorFlow graph.

        Args:
            write_to_ft_logs: `bool`, if feature logs are being written,
                whether or not to write the parameter counts to those logs;
        """ # print("Variable names:") # print(variable.name) # Add all identified parameters to total_parameters. # From here onwards only consider non-pruned parameters. # Add params from the current FC layer to fc_params_in_use. # Add params from the current batchnorm to conv_params_in_use. # Add params not in a rejected batchnorm or FC layer (to conv). # Add together the two counts for parameters 'in use'.
self
write_to_ft_logs
`bool`, if feature logs are being written,
whether or not to write the parameter counts to those logs.
` bool ` if feature logs are being written whether or not to write the parameter counts to those logs .