AIfES 2  2.0.0
aifes_express_f32_fnn.h File Reference

AIfES Express functions for weights with F32 (float32) data type. More...

Go to the source code of this file.

Data Structures

struct  AIFES_E_model_parameter_fnn_f32
 Parameters for the FNN model. More...
 
struct  AIFES_E_training_parameter_fnn_f32
 Parameters for Training. More...
 
struct  AIFES_E_init_weights_parameter_fnn_f32
 Parameters for weight initialization. More...
 

Typedefs

typedef struct AIFES_E_model_parameter_fnn_f32 AIFES_E_model_parameter_fnn_f32
 
typedef struct AIFES_E_training_parameter_fnn_f32 AIFES_E_training_parameter_fnn_f32
 
typedef struct AIFES_E_init_weights_parameter_fnn_f32 AIFES_E_init_weights_parameter_fnn_f32
 

Enumerations

enum  AIFES_E_activations {
  AIfES_E_relu , AIfES_E_sigmoid , AIfES_E_softmax , AIfES_E_leaky_relu ,
  AIfES_E_elu , AIfES_E_tanh , AIfES_E_softsign , AIfES_E_linear
}
 Possible activation functions in AIfES-Express. More...
 
enum  AIFES_E_loss { AIfES_E_mse , AIfES_E_crossentropy }
 Possible loss functions in AIfES-Express. More...
 
enum  AIFES_E_optimizer { AIfES_E_adam , AIfES_E_sgd }
 Possible optimizers in AIfES-Express. More...
 
enum  AIFES_E_init_weights_method { AIfES_E_init_uniform , AIfES_E_init_glorot_uniform , AIfES_E_init_no_init }
 Possible weight initialization methods in AIfES-Express. More...
 
enum  AIFES_E_early_stopping { AIfES_E_early_stopping_off , AIfES_E_early_stopping_on }
 Turn early stopping on or off.
 

Functions

uint32_t AIFES_E_flat_weights_number_fnn_f32 (uint32_t *fnn_structure, uint32_t layer_count)
 Calculates the total required float weights for the selected network structure. More...
 
int8_t AIFES_E_inference_fnn_f32 (aitensor_t *input_tensor, AIFES_E_model_parameter_fnn_f32 *AIFES_E_fnn, aitensor_t *output_tensor)
 Executes the inference. More...
 
int8_t AIFES_E_training_fnn_f32 (aitensor_t *input_tensor, aitensor_t *target_tensor, AIFES_E_model_parameter_fnn_f32 *AIFES_E_fnn, AIFES_E_training_parameter_fnn_f32 *AIFES_E_fnn_training, AIFES_E_init_weights_parameter_fnn_f32 *AIFES_E_fnn_init_weights, aitensor_t *output_tensor)
 Executes the training. More...
 

Detailed Description

AIfES Express functions for weights with F32 (float32) data type.

Version
2.2.0

AIfES Express is a beginner friendly high-level API of AIfES. This file contains all necessary functions for neural networks with float32 weights.

Enumeration Type Documentation

◆ AIFES_E_activations

Possible activation functions in AIfES-Express.

Enumerator
AIfES_E_relu 

Relu.

AIfES_E_sigmoid 

Sigmoid.

AIfES_E_softmax 

Softmax.

AIfES_E_leaky_relu 

Leaky_relu.

AIfES_E_elu 

Elu.

AIfES_E_tanh 

Tanh.

AIfES_E_softsign 

Softsign.

AIfES_E_linear 

Linear.

◆ AIFES_E_init_weights_method

Possible weight initialization methods in AIfES-Express.

Enumerator
AIfES_E_init_uniform 

Dices the weights in a range of values you specify.

AIfES_E_init_glorot_uniform 

Random numbers are uniformly diced within a certain range.

AIfES_E_init_no_init 

No weight init.

If starting weights are already available or if you want to continue training

◆ AIFES_E_loss

Possible loss functions in AIfES-Express.

Enumerator
AIfES_E_mse 

Mean squared error (MSE)

AIfES_E_crossentropy 

Crossentropy.

◆ AIFES_E_optimizer

Possible optimizers in AIfES-Express.

Enumerator
AIfES_E_adam 

ADAM.

AIfES_E_sgd 

SGD.

Function Documentation

◆ AIFES_E_flat_weights_number_fnn_f32()

uint32_t AIFES_E_flat_weights_number_fnn_f32 ( uint32_t *  fnn_structure,
uint32_t  layer_count 
)

Calculates the total required float weights for the selected network structure.

Parameters
*fnn_structureThe FNN structure
layer_countNumber of layers
Returns
Number of float weights required

◆ AIFES_E_inference_fnn_f32()

int8_t AIFES_E_inference_fnn_f32 ( aitensor_t input_tensor,
AIFES_E_model_parameter_fnn_f32 AIFES_E_fnn,
aitensor_t output_tensor 
)

Executes the inference.

Requires the input tensor, the FNN model parameters and an output tensor for the results. All data sets of the input tensor are calculated

Possible returns:

  • 0 = success
  • 1 = ERROR! Tensor dtype
  • 2 = ERROR! Tensor shape: Data Number
  • 3 = ERROR! Input tensor shape does not correspond to ANN inputs
  • 4 = ERROR! Output tensor shape does not correspond to ANN outputs
  • 5 = ERROR! Unknown activation function
  • 6 = ERROR! Not enough memory

Example:

uint32_t nn_structure[3] = {2,3,1};
AIFES_E_activations nn_activations[2];
nn_activations[0] = AIfES_E_sigmoid;
nn_activations[1] = AIfES_E_sigmoid;
float weights[] = {-10.1164f, -8.4212f, 5.4396f, 7.297f, -7.6482f, -9.0155f, -2.9653f,
2.3677f, -1.5968f, 12.0305f, -6.5858f, 11.9371f,-5.4247f};
nn.layer_count = 3;
nn.fnn_structure = nn_structure;
nn.fnn_activations = nn_activations;
nn.flat_weights = weights;
float input_data[4][2] = {
{0.0f, 0.0f},
{0.0f, 1.0f},
{1.0f, 0.0f},
{1.0f, 1.0f}
};
uint16_t input_shape[4*2] = {4, 2}; // Definition of the input shape
aitensor_t input_tensor = AITENSOR_2D_F32(input_shape, input_data); // Macro for the simple creation of a float32 tensor. Also usable in the normal AIfES version
float output_data[4*1]; // Output data
uint16_t output_shape[] = {4, 1};
aitensor_t output_tensor = AITENSOR_2D_F32(output_shape, output_data);
int8_t error;
error = AIFES_E_inference_fnn_f32(&input_tensor,
&nn,
&output_tensor);
int8_t AIFES_E_inference_fnn_f32(aitensor_t *input_tensor, AIFES_E_model_parameter_fnn_f32 *AIFES_E_fnn, aitensor_t *output_tensor)
Executes the inference.
AIFES_E_activations
Possible activation functions in AIfES-Express.
Definition: aifes_express_f32_fnn.h:34
@ AIfES_E_sigmoid
Sigmoid.
Definition: aifes_express_f32_fnn.h:36
Parameters for the FNN model.
Definition: aifes_express_f32_fnn.h:107
void * flat_weights
Pointer to the array with the weights.
Definition: aifes_express_f32_fnn.h:111
uint32_t layer_count
Count of all layers, including input and output layers.
Definition: aifes_express_f32_fnn.h:108
uint32_t * fnn_structure
Pointer to the network structure.
Definition: aifes_express_f32_fnn.h:109
AIFES_E_activations * fnn_activations
Pointer to the activation function list (AIFES_E_activations)
Definition: aifes_express_f32_fnn.h:110
A tensor in AIfES.
Definition: aifes_math.h:89
Parameters
*input_tensorTensor with the inputs
*AIFES_E_fnnThe FNN model parameters
*output_tensorTensor for the results
Returns
Error output

◆ AIFES_E_training_fnn_f32()

int8_t AIFES_E_training_fnn_f32 ( aitensor_t input_tensor,
aitensor_t target_tensor,
AIFES_E_model_parameter_fnn_f32 AIFES_E_fnn,
AIFES_E_training_parameter_fnn_f32 AIFES_E_fnn_training,
AIFES_E_init_weights_parameter_fnn_f32 AIFES_E_fnn_init_weights,
aitensor_t output_tensor 
)

Executes the training.

Requires the input tensor, the target tensor, FNN model parameters, training parameters, weight initialization method and an output tensor for the results. All data sets of the input tensor are used for the training

Possible returns:

  • 0 = success
  • 1 = ERROR! Tensor dtype
  • 2 = ERROR! Tensor shape: Data Number
  • 3 = ERROR! Input tensor shape does not correspond to ANN inputs
  • 4 = ERROR! Output tensor shape does not correspond to ANN outputs
  • 5 = ERROR! Use the crossentropy as loss for softmax
  • 6 = ERROR! learn_rate or sgd_momentum negative
  • 7 = ERROR! Init uniform weights min - max wrong
  • 8 = ERROR! batch_size: min = 1 / max = Number of training data
  • 9 = ERROR! Unknown activation function
  • 10 = ERROR! Unknown loss function
  • 11 = ERROR! Unknown init weights method
  • 12 = ERROR! Unknown optimizer
  • 13 = ERROR! Not enough memory

Example:

void my_print_function(float loss)
{
//E.g. a normal print output
printf("Loss: %f\n", loss);
}
uint32_t nn_structure[3] = {2,3,1};
AIFES_E_activations nn_activations[2];
nn_activations[0] = AIfES_E_sigmoid;
nn_activations[1] = AIfES_E_sigmoid;
float weights[] = {-10.1164f, -8.4212f, 5.4396f, 7.297f, -7.6482f, -9.0155f, -2.9653f,
2.3677f, -1.5968f, 12.0305f, -6.5858f, 11.9371f,-5.4247f};
nn.layer_count = 3;
nn.fnn_structure = nn_structure;
nn.fnn_activations = nn_activations;
nn.flat_weights = weights;
nn_train_config.optimizer = AIfES_E_adam;
nn_train_config.sgd_momentum = 0.0f; // Only for SGD optimizer
nn_train_config.loss = AIfES_E_mse;
nn_train_config.learn_rate = 0.05f;
nn_train_config.batch_size = 4;
nn_train_config.epochs = 100;
nn_train_config.epochs_loss_print_interval = 10;
// Your individual print function
nn_train_config.loss_print_function = my_print_function;
//You can enable early stopping, so that learning is automatically stopped when a learning target is reached
nn_train_config.early_stopping = AIfES_E_early_stopping_on;
//Define your target loss
nn_train_config.early_stopping_target_loss = 0.004;
float input_data[4][2] = {
{0.0f, 0.0f},
{0.0f, 1.0f},
{1.0f, 0.0f},
{1.0f, 1.0f}
};
uint16_t input_shape[4*2] = {4, 2}; // Definition of the input shape
aitensor_t input_tensor = AITENSOR_2D_F32(input_shape, input_data); // Macro for the simple creation of a float32 tensor. Also usable in the normal AIfES version
float target_data[4*1] = {0.0f, 1.0f, 1.0f, 0.0f}; // Target Data
uint16_t target_shape[] = {4, 1};
aitensor_t target_tensor = AITENSOR_2D_F32(target_shape, target_data); // Macro for the simple creation of a float32 tensor. Also usable in the normal AIfES version
float output_data[4*1]; // Output data
uint16_t output_shape[] = {4, 1};
aitensor_t output_tensor = AITENSOR_2D_F32(output_shape, output_data);
int8_t error;
error = AIFES_E_training_fnn_f32(&input_tensor,
&target_tensor,
&nn,
&nn_train_config,
&nn_weights_init,
&output_tensor);
@ AIfES_E_init_glorot_uniform
Random numbers are uniformly diced within a certain range.
Definition: aifes_express_f32_fnn.h:69
int8_t AIFES_E_training_fnn_f32(aitensor_t *input_tensor, aitensor_t *target_tensor, AIFES_E_model_parameter_fnn_f32 *AIFES_E_fnn, AIFES_E_training_parameter_fnn_f32 *AIFES_E_fnn_training, AIFES_E_init_weights_parameter_fnn_f32 *AIFES_E_fnn_init_weights, aitensor_t *output_tensor)
Executes the training.
@ AIfES_E_mse
Mean squared error (MSE)
Definition: aifes_express_f32_fnn.h:50
@ AIfES_E_adam
ADAM.
Definition: aifes_express_f32_fnn.h:59
Parameters for weight initialization.
Definition: aifes_express_f32_fnn.h:184
AIFES_E_init_weights_method init_weights_method
Weight initialization method (AIFES_E_init_weights_method)
Definition: aifes_express_f32_fnn.h:185
Parameters for Training.
Definition: aifes_express_f32_fnn.h:138
float learn_rate
Learning rate for training (For all optimizers)
Definition: aifes_express_f32_fnn.h:141
AIFES_E_early_stopping early_stopping
Switch early stopping on or off.
Definition: aifes_express_f32_fnn.h:162
float sgd_momentum
Optional momentum for SGD (Value 0.0f means Momentum off)
Definition: aifes_express_f32_fnn.h:142
void(* loss_print_function)(float)
Individual print function for the loss.
Definition: aifes_express_f32_fnn.h:161
uint32_t batch_size
Batch size (min: 1 -> max: Entire data set)
Definition: aifes_express_f32_fnn.h:143
float early_stopping_target_loss
If early stopping is switched on, the target loss can be specified here.
Definition: aifes_express_f32_fnn.h:163
AIFES_E_optimizer optimizer
Optimizer selection (AIFES_E_optimizer)
Definition: aifes_express_f32_fnn.h:140
uint32_t epochs_loss_print_interval
Selection of the interval in which the loss is to be calculated and output via the print function.
Definition: aifes_express_f32_fnn.h:145
AIFES_E_loss loss
Loss selection (AIFES_E_loss)
Definition: aifes_express_f32_fnn.h:139
uint32_t epochs
Number of desired epochs (If early stopping is on, can be stopped before)
Definition: aifes_express_f32_fnn.h:144
Parameters
*input_tensorTensor with the input training data
*target_tensorTensor with the training target data / labels
*AIFES_E_fnnThe FNN model parameters
*AIFES_E_fnn_trainingThe training parameters
*AIFES_E_fnn_init_weightsThe weight init parameters
*output_tensorTensor for the results
Returns
Error output