Skip to content

NN_Model of the GCC Backend

Philipp edited this page Feb 29, 2020 · 7 revisions

This page covers the idea of the nn_model in the gcc_backend. The nn_model consists of a .h-template and .c-template which represent templates for regular .h- and .c-files.

The .h-template holds two different types of code:

  • Static Code: Code for variable definitions and function signatures.
  • Code with Marker Elements: While translating a neural network model, these marker elements are replaced with the proper values extracted from the neural network model.

The .c-template only contains the implementation of the different functions of a neural network as static code. This code is not changed during the translation process.

The following marker elements are used in the .h-template:

Maker Name Description
###activationFunctions### An array which contains the activation function identifiers as integer values for each layer. The length of the array is ###dimNumberLayers###. The possible integer values are specified below in the "Activation Function"-enumeration.
###bias### Holds all the bias values for all the layers as a flattened array. The length of the array is ###dimBias###.
###dimNumberLayers### Defines the total number of layers including the (input, output, and hidden layers) - 1.
###horizontalStride### Defines the horizontal step sizes for the filter of each layer. The length of the array is ###dimNumberLayers###.
###indicesBias### Represents an array filled with integer values for each layer representing the start index of the bias values in the BIASES array for each layer. The length of the array is ###dimNumberLayers###. The possible integer values are in the range [0,...,###dimBias###-1].
###indicesWeights### Represents an array filled with integer values for each layer representing the start index of the weights values in the WEIGHTS array for each layer. The length of the array is ###dimNumberLayers###. The possible integer values are in the range [0,...,###dimWeights###-1].
###layerOutputDepth### Defines the output depth for each layer in an array of the length ###numberLayers###. The depth of the input shape in neural network frameworks is equivalent to the output-depth for the 0th element of the array.
###layerOutputHeight### Defines the output height for each layer in an array of the length ###numberLayers###. The height of the input shape in neural network frameworks is equivalent to the output-depth for the 0th element of the array.
###layerOutputWidth### Defines the output width for each layer in an array of the length ###numberLayers###. The width of the input shape in neural network frameworks is equivalent to the output-depth for the 0th element of the array.
###layerTypes### Represents an array filled with integer values for each layer depending on the layer type. The length of the array is ###dimNumberLayers###. The possible integer values are specified below in the "Layer Types"-Enumeration.
###numberLayers### Defines the total number of layers including the input, output, and hidden layers
###padding### Represents an array filled with either a 0 or a 1 for each layer depending on whether padding should be applied in each layer. The length of the array is ###dimNumberLayers###.
###poolHeight### Defines the height of the filter for each layer. The length of the array is ###dimNumberLayers###.
###poolWidth### Defines the width of the filter for each layer. The length of the array is ###dimNumberLayers###.
###useBias### Represents an array filled with either a 0 or a 1 for each layer depending on whether bias values should be applied in each layer. The length of the array is ###dimNumberLayers###.
###vertialStride### Defines the vertical step sizes of the filter for each layer. The length of the array is ###dimNumberLayers###.
###weights### Holds all the weight values for all the layers as a flattened array. The length of the array is ###dimWeights###.

Supported Neural Network Structures for the GCC-Backend

All functionality of a neural network must be implemented in the .c-template file. Currently, the following features are supported:

Neural Network Structure:

Neural Network Structure Status
Feed Forward Neural Network ✔️
Recurrent Neural Network
Convolutional Neural Network

Activation Function:

Enum-Value Int-Value Activation Function (af) Status
af_linear 0 Linear ✔️
af_sigmoid 1 Sigmoid ✔️
af_relu 2 ReLu ✔️
af_tanh 3 TanH ✔️
af_softmax 4 Softmax ✔️

Layer Types:

Enum-Value Int-Value Layer Type (lt) Status
lt_dropout 0 DropOut ✔️
lt_dense 1 Dense ✔️
lt_flatten 2 Flatten ✔️
lt_max_pooling 3 MaxPooling1D ✔️
lt_max_pooling 3 MaxPooling2D ✔️
lt_max_pooling 3 MaxPooling3D
lt_avg_pooling 4 AvgPooling1D ✔️
lt_avg_pooling 4 AvgPooling2D ✔️
lt_avg_pooling 4 AvgPooling3D
lt_convolution 5 Conv1D
lt_convolution 5 Conv2D
lt_convolution 5 Conv3D
lt_activation 6 Activation ✔️
lt_batch_normalization 7 Batch Normalization
lt_bias 8 Bias ✔️

Padding

Enum-Value Int-Value Padding Type Status
padding_valid 0 Disables padding ✔️
padding_same 1 Enables padding ✔️