models/dense_net.py
def cross_entropy_loss(self, _input, labels, block, layer,
                           preserve_transition=False, kernels_to_prune=None):
        """
        Takes an input and adds a transition layer to obtain predictions for
        classes. Then calculates the cross-entropy loss for that input with
        respect to expected labels. Returns the prediction tensor and the
        calculated cross-entropy.

        Args:
            _input: tensor, the operation's input;
            labels: tensor, the expected labels (classes) for the data;
            block: `int`, identifier number for the last block;
            layer: `int`, identifier number for the last layer in that block;
            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).
        """
        # add the FC transition layer to the classes (+ softmax)
        if preserve_transition:
            # the reconstruction depends on the las self-constructing action
            if kernels_to_prune is None:
                logits = self.reconstruct_transition_to_classes(
                    _input, block, layer)
            else:
                logits = self.reconstruct_transition_to_classes_post_pruning(
                    _input, block, layer, kernels_to_prune)
        else:
            logits = self.transition_layer_to_classes(_input, block, layer)
        prediction = tf.nn.softmax(logits)

        # set the calculation for the losses (cross_entropy and l2_loss)
        if TF_VERSION[0] >= 1 and TF_VERSION[1] >= 5:
            cross_entropy = tf.reduce_mean(
                tf.nn.softmax_cross_entropy_with_logits_v2(logits=logits,
                                                           labels=labels))
        else:
            cross_entropy = tf.reduce_mean(
                tf.nn.softmax_cross_entropy_with_logits(logits=logits,
                                                        labels=labels))

        return prediction, cross_entropy

        Takes an input and adds a transition layer to obtain predictions for
        classes. Then calculates the cross-entropy loss for that input with
        respect to expected labels. Returns the prediction tensor and the
        calculated cross-entropy.

        Args:
            _input: tensor, the operation's input;
            labels: tensor, the expected labels (classes) for the data;
            block: `int`, identifier number for the last block;
            layer: `int`, identifier number for the last layer in that block;
            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).
        
Takes an input and adds a transition layer to obtain predictions for
classes. Then calculates the cross-entropy loss for that input with
respect to expected labels. Returns the prediction tensor and the
calculated cross-entropy.
Takes an input and adds a transition layer to obtain predictions for classes . Then calculates the cross - entropy loss for that input with respect to expected labels . Returns the prediction tensor and the calculated cross - entropy .
def cross_entropy_loss(self, _input, labels, block, layer,
                           preserve_transition=False, kernels_to_prune=None):
        if preserve_transition:
            if kernels_to_prune is None:
                logits = self.reconstruct_transition_to_classes(
                    _input, block, layer)
            else:
                logits = self.reconstruct_transition_to_classes_post_pruning(
                    _input, block, layer, kernels_to_prune)
        else:
            logits = self.transition_layer_to_classes(_input, block, layer)
        prediction = tf.nn.softmax(logits)
        if TF_VERSION[0] >= 1 and TF_VERSION[1] >= 5:
            cross_entropy = tf.reduce_mean(
                tf.nn.softmax_cross_entropy_with_logits_v2(logits=logits,
                                                           labels=labels))
        else:
            cross_entropy = tf.reduce_mean(
                tf.nn.softmax_cross_entropy_with_logits(logits=logits,
                                                        labels=labels))
        return prediction, cross_entropy
def cross_entropy_loss ( self , _input , labels , block , layer , preserve_transition = False , kernels_to_prune = None ) : if preserve_transition : if kernels_to_prune is None : logits = self . reconstruct_transition_to_classes ( _input , block , layer ) else : logits = self . reconstruct_transition_to_classes_post_pruning ( _input , block , layer , kernels_to_prune ) else : logits = self . transition_layer_to_classes ( _input , block , layer ) prediction = tf . nn . softmax ( logits ) if TF_VERSION [ 0 ] >= 1 and TF_VERSION [ 1 ] >= 5 : cross_entropy = tf . reduce_mean ( tf . nn . softmax_cross_entropy_with_logits_v2 ( logits = logits , labels = labels ) ) else : cross_entropy = tf . reduce_mean ( tf . nn . softmax_cross_entropy_with_logits ( logits = logits , labels = labels ) ) return prediction , cross_entropy
Takes an input and adds a transition layer to obtain predictions for
classes.
Takes an input and adds a transition layer to obtain predictions for classes .
"""
        Takes an input and adds a transition layer to obtain predictions for
        classes. Then calculates the cross-entropy loss for that input with
        respect to expected labels. Returns the prediction tensor and the
        calculated cross-entropy.

        Args:
            _input: tensor, the operation's input;
            labels: tensor, the expected labels (classes) for the data;
            block: `int`, identifier number for the last block;
            layer: `int`, identifier number for the last layer in that block;
            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).
        """ # add the FC transition layer to the classes (+ softmax) # the reconstruction depends on the las self-constructing action # set the calculation for the losses (cross_entropy and l2_loss)
self
_input
tensor, the operation's input.
tensor the operation ' s input .
labels
tensor, the expected labels (classes) for the data.
tensor the expected labels ( classes ) for the data .
block
`int`, identifier number for the last block.
` int ` identifier number for the last block .
layer
`int`, identifier number for the last layer in that block.
` int ` identifier number for the last layer in that block .
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 ) .