models/dense_net.py
def remove_kernels_from_layer(self, _input, in_cv, layer,
                                  kernels_to_prune):
        """
        Removes specific convolution kernels in a layer within a block:
        removes the kernels from the list, reconstructs the composite function,
        and concatenates outputs to ensure the DenseNet paradigm.
        Returns the layer's new output tensor.
        N.B.: This function is meant to be used ONLY in self-constructing mode
            (i.e. when should_self_construct is true).

        Args:
            _input: tensor, the layer's input;
            in_cv: tensor, the input for the layer's convolution;
            layer: `int`, identifier number for this layer (within a block);
            kernels_to_prune: `list` of `int`, the specific kernels to remove.
        """
        with tf.variable_scope("layer_%d" % layer):
            with tf.variable_scope("composite_function"):
                # remove the kernels specified in kernels_to_prune
                in_features = int(in_cv.get_shape()[-1])
                print("\nPre-pruning kernels_ref_list length: %d" % len(
                    self.kernels_ref_list[-1][-1]))
                for i in reversed(kernels_to_prune):
                    # iterate backwards so that kernel ids remain meaningful
                    self.pruned_varnames.append(
                        self.kernels_ref_list[-1][-1][i].name)
                    del self.kernels_ref_list[-1][-1][i]
                for elem in self.pruned_varnames:
                    print(elem)
                print("Post-pruning kernels_ref_list length: %d\n" % len(
                    self.kernels_ref_list[-1][-1]))
                # reconstruct the composite function from the current kernels
                comp_out, filter_ref = self.reconstruct_composite_function(
                    in_cv, self.kernels_ref_list[-1][-1])
                # save a reference to the composite function's filter
                self.filter_ref_list[-1][-1] = filter_ref
            # concatenate output with layer input to ensure DenseNet paradigm
            if TF_VERSION[0] >= 1 and TF_VERSION[1] >= 0:
                output = tf.concat(axis=3, values=(_input, comp_out))
            else:
                output = tf.concat(3, (_input, comp_out))

        # Keep track of kernel CS.
        for i in reversed(kernels_to_prune):
            del self.kCS_FIFO[i], self.dkCS_FIFO[i]

        return output

        Removes specific convolution kernels in a layer within a block:
        removes the kernels from the list, reconstructs the composite function,
        and concatenates outputs to ensure the DenseNet paradigm.
        Returns the layer's new output tensor.
        N.B.: This function is meant to be used ONLY in self-constructing mode
            (i.e. when should_self_construct is true).

        Args:
            _input: tensor, the layer's input;
            in_cv: tensor, the input for the layer's convolution;
            layer: `int`, identifier number for this layer (within a block);
            kernels_to_prune: `list` of `int`, the specific kernels to remove.
        
Removes specific convolution kernels in a layer within a block:
removes the kernels from the list, reconstructs the composite function,
and concatenates outputs to ensure the DenseNet paradigm.
Returns the layer's new output tensor.
N.B.: This function is meant to be used ONLY in self-constructing mode
.
Removes specific convolution kernels in a layer within a block : removes the kernels from the list reconstructs the composite function and concatenates outputs to ensure the DenseNet paradigm . Returns the layer ' s new output tensor . N . B . : This function is meant to be used ONLY in self - constructing mode .
def remove_kernels_from_layer(self, _input, in_cv, layer,
                                  kernels_to_prune):
        with tf.variable_scope("layer_%d" % layer):
            with tf.variable_scope("composite_function"):
                in_features = int(in_cv.get_shape()[-1])
                print("\nPre-pruning kernels_ref_list length: %d" % len(
                    self.kernels_ref_list[-1][-1]))
                for i in reversed(kernels_to_prune):
                    self.pruned_varnames.append(
                        self.kernels_ref_list[-1][-1][i].name)
                    del self.kernels_ref_list[-1][-1][i]
                for elem in self.pruned_varnames:
                    print(elem)
                print("Post-pruning kernels_ref_list length: %d\n" % len(
                    self.kernels_ref_list[-1][-1]))
                comp_out, filter_ref = self.reconstruct_composite_function(
                    in_cv, self.kernels_ref_list[-1][-1])
                self.filter_ref_list[-1][-1] = filter_ref
            if TF_VERSION[0] >= 1 and TF_VERSION[1] >= 0:
                output = tf.concat(axis=3, values=(_input, comp_out))
            else:
                output = tf.concat(3, (_input, comp_out))
        for i in reversed(kernels_to_prune):
            del self.kCS_FIFO[i], self.dkCS_FIFO[i]
        return output
def remove_kernels_from_layer ( self , _input , in_cv , layer , kernels_to_prune ) : with tf . variable_scope ( "layer_%d" % layer ) : with tf . variable_scope ( "composite_function" ) : in_features = int ( in_cv . get_shape ( ) [ - 1 ] ) print ( "\nPre-pruning kernels_ref_list length: %d" % len ( self . kernels_ref_list [ - 1 ] [ - 1 ] ) ) for i in reversed ( kernels_to_prune ) : self . pruned_varnames . append ( self . kernels_ref_list [ - 1 ] [ - 1 ] [ i ] . name ) del self . kernels_ref_list [ - 1 ] [ - 1 ] [ i ] for elem in self . pruned_varnames : print ( elem ) print ( "Post-pruning kernels_ref_list length: %d\n" % len ( self . kernels_ref_list [ - 1 ] [ - 1 ] ) ) comp_out , filter_ref = self . reconstruct_composite_function ( in_cv , self . kernels_ref_list [ - 1 ] [ - 1 ] ) self . filter_ref_list [ - 1 ] [ - 1 ] = filter_ref if TF_VERSION [ 0 ] >= 1 and TF_VERSION [ 1 ] >= 0 : output = tf . concat ( axis = 3 , values = ( _input , comp_out ) ) else : output = tf . concat ( 3 , ( _input , comp_out ) ) for i in reversed ( kernels_to_prune ) : del self . kCS_FIFO [ i ] , self . dkCS_FIFO [ i ] return output
Removes specific convolution kernels in a layer within a block:
removes the kernels from the list, reconstructs the composite function,
and concatenates outputs to ensure the DenseNet paradigm.
Removes specific convolution kernels in a layer within a block : removes the kernels from the list reconstructs the composite function and concatenates outputs to ensure the DenseNet paradigm .
"""
        Removes specific convolution kernels in a layer within a block:
        removes the kernels from the list, reconstructs the composite function,
        and concatenates outputs to ensure the DenseNet paradigm.
        Returns the layer's new output tensor.
        N.B.: This function is meant to be used ONLY in self-constructing mode
            (i.e. when should_self_construct is true).

        Args:
            _input: tensor, the layer's input;
            in_cv: tensor, the input for the layer's convolution;
            layer: `int`, identifier number for this layer (within a block);
            kernels_to_prune: `list` of `int`, the specific kernels to remove.
        """ # remove the kernels specified in kernels_to_prune # iterate backwards so that kernel ids remain meaningful # reconstruct the composite function from the current kernels # save a reference to the composite function's filter # concatenate output with layer input to ensure DenseNet paradigm # Keep track of kernel CS.
self
_input
tensor, the layer's input.
tensor the layer ' s input .
in_cv
tensor, the input for the layer's convolution.
tensor the input for the layer ' s convolution .
layer
`int`, identifier number for this layer (within a block).
` int ` identifier number for this layer ( within a block ) .
kernels_to_prune
`list` of `int`, the specific kernels to remove.
` list ` of ` int ` the specific kernels to remove .