コード例 #1
0
ファイル: cntk_layers.py プロジェクト: gil2abir/ELL
    def process(self, ellLayers):
        """Helper to convert a binary convolutional layer to the ELL equivalent."""

        # A CNTK Binary Convolutional layer is a single function.
        # Bias and Activation are separate layers (processed outside of this class).
        weightsTensor = converters.get_float_tensor_from_cntk_convolutional_weight_parameter(
            self.weights_parameter)

        layerParameters = ELL.LayerParameters(
            self.layer.ell_inputShape, self.layer.ell_inputPaddingParameters,
            self.layer.ell_outputShape, self.layer.ell_outputPaddingParameters)

        # Fill in the convolutional parameters
        weightsShape = self.weights_parameter.shape
        receptiveField = weightsShape[2]
        stride = self.attributes['strides'][2]

        convolutionalParameters = ELL.BinaryConvolutionalParameters(
            receptiveField, stride, self.convolution_method,
            self.weights_scale)

        ellLayers.append(
            ELL.FloatBinaryConvolutionalLayer(layerParameters,
                                              convolutionalParameters,
                                              weightsTensor))
コード例 #2
0
    def process(self, ellLayers):
        """Appends the ELL representation of the current layer to ellLayers."""

        preluTensor = converters.get_float_tensor_from_cntk_convolutional_weight_parameter(
            self.prelu_parameter)

        # Create the ell.LayerParameters for the ELL layer
        layerParameters = ell.LayerParameters(
            self.layer.ell_inputShape, self.layer.ell_inputPaddingParameters, self.layer.ell_outputShape, self.layer.ell_outputPaddingParameters)

        # Create the ELL PReLU activation layer
        ellLayers.append(ell.FloatPReLUActivationLayer(
            layerParameters, preluTensor))
コード例 #3
0
ファイル: cntk_layers.py プロジェクト: gil2abir/ELL
    def process(self, ellLayers):
        """Helper to convert a convolutional layer to the ELL equivalent."""

        # Note that a single CNTK Convolutional function block is equivalent to the following 3 ELL layers:
        # - ConvolutionalLayer
        # - BiasLayer
        # - ActivationLayer. This layer is sometimes missing, depending on activation type.
        #
        # Therefore, make sure the output padding characteristics of the last layer reflect the next layer's
        # padding requirements.

        weightsTensor = converters.get_float_tensor_from_cntk_convolutional_weight_parameter(
            self.weights_parameter)
        biasVector = converters.get_float_vector_from_cntk_trainable_parameter(
            self.bias_parameter)

        # Create the ELL.LayerParameters for the various ELL layers
        firstLayerParameters = ELL.LayerParameters(
            self.layer.ell_inputShape, self.layer.ell_inputPaddingParameters,
            self.layer.ell_outputShapeMinusPadding, ELL.NoPadding())
        middleLayerParameters = ELL.LayerParameters(
            self.layer.ell_outputShapeMinusPadding, ELL.NoPadding(),
            self.layer.ell_outputShapeMinusPadding, ELL.NoPadding())
        lastLayerParameters = ELL.LayerParameters(
            self.layer.ell_outputShapeMinusPadding, ELL.NoPadding(),
            self.layer.ell_outputShape, self.layer.ell_outputPaddingParameters)

        layerParameters = firstLayerParameters

        # Fill in the convolutional parameters
        weightsShape = self.weights_parameter.shape
        receptiveField = weightsShape[2]
        stride = self.attributes['strides'][2]

        filterBatchSize = layerParameters.outputShape.channels

        internalNodes = utilities.get_model_layers(self.layer.block_root)
        activationType = utilities.get_ell_activation_type(internalNodes)

        convolutionalParameters = ELL.ConvolutionalParameters(
            receptiveField, stride, self.convolution_method, filterBatchSize)

        # Create the ELL convolutional layer
        ellLayers.append(
            ELL.FloatConvolutionalLayer(layerParameters,
                                        convolutionalParameters,
                                        weightsTensor))

        # Create the ELL bias layer
        isSoftmaxActivation = utilities.is_softmax_activation(internalNodes)
        hasActivation = isSoftmaxActivation or activationType != None
        if (hasActivation):
            layerParameters = middleLayerParameters
        else:
            layerParameters = lastLayerParameters
        ellLayers.append(ELL.FloatBiasLayer(layerParameters, biasVector))

        # Create the ELL activation layer
        if (hasActivation):
            layerParameters = lastLayerParameters

            # Special case: if this is softmax activation, create an ELL Softmax layer.
            # Else, insert an ELL ActivationLayer
            if (isSoftmaxActivation):
                ellLayers.append(ELL.FloatSoftmaxLayer(layerParameters))
            else:
                ellLayers.append(
                    ELL.FloatActivationLayer(layerParameters, activationType))