ERIS CORE

◆ AppAIfES()

AppAIfES::AppAIfES ( )
inline

Definition at line 21 of file AppAIfES.h.

21  :AppBaseClass(){
22  strcpy(name,"AI");
23  x_test = NULL;
24  y_test = NULL;
25  // The layer structures for F32 data type and their configurations
26  input_layer_shape[0] = 1;
27  input_layer_shape[1] = 3;
28  input_layer = AILAYER_INPUT_F32_A(2, input_layer_shape);
29  dense_layer_1 = AILAYER_DENSE_F32_A(3);
30  leaky_relu_layer = AILAYER_LEAKY_RELU_F32_A(0.01f);
31  dense_layer_2 = AILAYER_DENSE_F32_A(2);
32  sigmoid_layer = AILAYER_SIGMOID_F32_A();
33 
34  model.input_layer = ailayer_input_f32_default(&input_layer);
35  x_layer = ailayer_dense_f32_default(&dense_layer_1, model.input_layer);
36  x_layer = ailayer_leaky_relu_f32_default(&leaky_relu_layer, x_layer);
37  x_layer = ailayer_dense_f32_default(&dense_layer_2, x_layer);
38  x_layer = ailayer_sigmoid_f32_default(&sigmoid_layer, x_layer);
39  model.output_layer = x_layer;
40 
41  // Finish the model creation by checking the connections and setting some parameters for further processing
42  aialgo_compile_model(&model);
43 
44  uint32_t parameter_memory_size = aialgo_sizeof_parameter_memory(&model);
45  parameter_memory = extmem_malloc(parameter_memory_size);
46 
47  // Distribute the memory to the trainable parameters of the model
48  aialgo_distribute_parameter_memory(&model, parameter_memory, parameter_memory_size);
49  //aialgo_print_model_structure(&model);
50 
51  model.loss = ailoss_crossentropy_f32_default(&crossentropy_loss, model.output_layer);
52  //aialgo_print_loss_specs(model.loss);
53 
54  //config the optimizer
55  adam_opti = AIOPTI_ADAM_F32(0.01f, 0.9f, 0.999f, 1e-7f);
56  optimizer = aiopti_adam_f32_default(&adam_opti);
57  //aialgo_print_optimizer_specs(optimizer);
58 
59  // Set the seed for your configured random function for example with
60  srand(time(0));
61 
62  aimath_f32_default_init_he_uniform(&dense_layer_1.weights);
63  aimath_f32_default_init_zeros(&dense_layer_1.bias);
64 
65  aimath_f32_default_init_glorot_uniform(&dense_layer_2.weights);
66  aimath_f32_default_init_zeros(&dense_layer_2.bias);
67 
68  uint32_t training_memory_size = aialgo_sizeof_training_memory(&model, optimizer);
69  void *training_memory = extmem_malloc(training_memory_size);
70 
71  // Schedule the memory to the model
72  aialgo_schedule_training_memory(&model, optimizer, training_memory, training_memory_size);
73 
74 
75  // One epoch of training. Iterates through the whole data once
76  //float loss;
77  //int batch_size = 3;
78  //aialgo_train_model(&model, &x_train, &y_train, optimizer, batch_size);
79  //aialgo_calc_loss_model_f32(&model, x_test, y_test, &loss);
80 
81  // Print the loss to the console
82  //aiprint("M VM Epoch "); aiprint_int("%5d", 0);
83  //aiprint(": test loss: "); aiprint_float("%f", loss);
84  //aiprint("\n");
85 
86 
87  //extmem_free(parameter_memory);
88  //extmem_free(training_memory);
89  };
uint16_t input_layer_shape[2]
Definition: AppAIfES.h:99
aiopti_t * optimizer
Definition: AppAIfES.h:111
aimodel_t model
Definition: AppAIfES.h:101
aiopti_adam_f32_t adam_opti
Definition: AppAIfES.h:110
ailayer_sigmoid_f32_t sigmoid_layer
Definition: AppAIfES.h:106
void * parameter_memory
Definition: AppAIfES.h:98
ailayer_dense_f32_t dense_layer_2
Definition: AppAIfES.h:105
ailayer_leaky_relu_f32_t leaky_relu_layer
Definition: AppAIfES.h:104
ailoss_crossentropy_f32_t crossentropy_loss
Definition: AppAIfES.h:109
aitensor_t * x_test
Definition: AppAIfES.h:115
ailayer_input_f32_t input_layer
Definition: AppAIfES.h:102
aitensor_t * y_test
Definition: AppAIfES.h:116
ailayer_t * x_layer
Definition: AppAIfES.h:108
ailayer_dense_f32_t dense_layer_1
Definition: AppAIfES.h:103
char name[MAX_NAME_LENGTH]
Definition: AppBaseClass.h:74

References adam_opti, crossentropy_loss, dense_layer_1, dense_layer_2, input_layer, input_layer_shape, leaky_relu_layer, model, AppBaseClass::name, optimizer, parameter_memory, sigmoid_layer, x_layer, x_test, and y_test.