models/dense_net.py
def _define_end_graph_operations(self, preserve_transition=False,
                                     kernels_to_prune=None):
        """
        Adds the last layer on top of the (editable portion of the) graph.
        Then defines the operations for cross-entropy, the training step,
        and the accuracy.

        Args:
            preserve_transition: `bool`, whether or not to preserve the
                transition to classes (if yes, adapts the previous transition,
                otherwise creates a new one);
            kernels_to_prune: `list` of `int` or None, identifiers of recently
                pruned kernels (used after kernel-level pruning, otherwise its
                value is None).
        """
        # obtain the predicted logits, set the calculation for the losses
        # (cross_entropy and l2_loss)
        prediction, cross_entropy = self.cross_entropy_loss(
            self.output, self.labels, self.total_blocks-1,
            self.layer_num_list[-1]-1, preserve_transition, kernels_to_prune)
        self.cross_entropy.append(cross_entropy)
        var_list = self.get_variables_in_use()
        l2_loss = tf.add_n(
            [tf.nn.l2_loss(var) for var in var_list])

        # set the optimizer and define the training step
        optimizer = tf.train.MomentumOptimizer(
            self.learning_rate, self.nesterov_momentum, use_nesterov=True)
        self.train_step = optimizer.minimize(
            cross_entropy + l2_loss * self.weight_decay, var_list=var_list)

        # set the calculation for the accuracy
        correct_prediction = tf.equal(
            tf.argmax(prediction, 1),
            tf.argmax(self.labels, 1))
        self.accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

        Adds the last layer on top of the (editable portion of the) graph.
        Then defines the operations for cross-entropy, the training step,
        and the accuracy.

        Args:
            preserve_transition: `bool`, whether or not to preserve the
                transition to classes (if yes, adapts the previous transition,
                otherwise creates a new one);
            kernels_to_prune: `list` of `int` or None, identifiers of recently
                pruned kernels (used after kernel-level pruning, otherwise its
                value is None).
        
Adds the last layer on top of the (editable portion of the) graph.
Then defines the operations for cross-entropy, the training step,
and the accuracy.
Adds the last layer on top of the ( editable portion of the ) graph . Then defines the operations for cross - entropy the training step and the accuracy .
def _define_end_graph_operations(self, preserve_transition=False,
                                     kernels_to_prune=None):
        prediction, cross_entropy = self.cross_entropy_loss(
            self.output, self.labels, self.total_blocks-1,
            self.layer_num_list[-1]-1, preserve_transition, kernels_to_prune)
        self.cross_entropy.append(cross_entropy)
        var_list = self.get_variables_in_use()
        l2_loss = tf.add_n(
            [tf.nn.l2_loss(var) for var in var_list])
        optimizer = tf.train.MomentumOptimizer(
            self.learning_rate, self.nesterov_momentum, use_nesterov=True)
        self.train_step = optimizer.minimize(
            cross_entropy + l2_loss * self.weight_decay, var_list=var_list)
        correct_prediction = tf.equal(
            tf.argmax(prediction, 1),
            tf.argmax(self.labels, 1))
        self.accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
def _define_end_graph_operations ( self , preserve_transition = False , kernels_to_prune = None ) : prediction , cross_entropy = self . cross_entropy_loss ( self . output , self . labels , self . total_blocks - 1 , self . layer_num_list [ - 1 ] - 1 , preserve_transition , kernels_to_prune ) self . cross_entropy . append ( cross_entropy ) var_list = self . get_variables_in_use ( ) l2_loss = tf . add_n ( [ tf . nn . l2_loss ( var ) for var in var_list ] ) optimizer = tf . train . MomentumOptimizer ( self . learning_rate , self . nesterov_momentum , use_nesterov = True ) self . train_step = optimizer . minimize ( cross_entropy + l2_loss * self . weight_decay , var_list = var_list ) correct_prediction = tf . equal ( tf . argmax ( prediction , 1 ) , tf . argmax ( self . labels , 1 ) ) self . accuracy = tf . reduce_mean ( tf . cast ( correct_prediction , tf . float32 ) )
Adds the last layer on top of the (editable portion of the) graph.
Adds the last layer on top of the ( editable portion of the ) graph .
"""
        Adds the last layer on top of the (editable portion of the) graph.
        Then defines the operations for cross-entropy, the training step,
        and the accuracy.

        Args:
            preserve_transition: `bool`, whether or not to preserve the
                transition to classes (if yes, adapts the previous transition,
                otherwise creates a new one);
            kernels_to_prune: `list` of `int` or None, identifiers of recently
                pruned kernels (used after kernel-level pruning, otherwise its
                value is None).
        """ # obtain the predicted logits, set the calculation for the losses # (cross_entropy and l2_loss) # set the optimizer and define the training step # set the calculation for the accuracy
self
preserve_transition
`bool`, whether or not to preserve the
transition to classes (if yes, adapts the previous transition,
otherwise creates a new one).
` bool ` whether or not to preserve the transition to classes ( if yes adapts the previous transition otherwise creates a new one ) .
kernels_to_prune
`list` of `int` or None, identifiers of recently
pruned kernels (used after kernel-level pruning, otherwise its
value is None).
` list ` of ` int ` or None identifiers of recently pruned kernels ( used after kernel - level pruning otherwise its value is None ) .