-
Notifications
You must be signed in to change notification settings - Fork 22
/
FeedForward_from_internal_EEPROM.ino
39 lines (30 loc) · 1.72 KB
/
FeedForward_from_internal_EEPROM.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// This is a minimal example demonstrating the use of a Neural Network (NN) with EEPROM-based weights and biases,
// aiming to reduce RAM and PROGMEM usage.
/*
CAUTION: Use Save_NN_to_internal_EEPROM.ino TO SAVE AN NN INTO EEPROM FIRST, BEFORE USE OF THIS SKETCH
CAUTION: Use Save_NN_to_internal_EEPROM.ino TO SAVE AN NN INTO EEPROM FIRST, BEFORE USE OF THIS SKETCH
CAUTION: Use Save_NN_to_internal_EEPROM.ino TO SAVE AN NN INTO EEPROM FIRST, BEFORE USE OF THIS SKETCH
*/
// Macro to calculate the number of elements in an array
#define NumberOf(arg) ((unsigned int)(sizeof(arg) / sizeof(arg[0])))
// Macros for optimization flags
#define _1_OPTIMIZE 0B01000110 // https://github.com/GiorgosXou/NeuralNetworks#define-macro-properties
#define _2_OPTIMIZE 0B10000000 // Enable the use of Internal EEPROM
#define FROM_EEPROM_ADDRESS 0 // The position at which the NN will be saved in the internal EEPROM
#include <EEPROM.h>
#include <NeuralNetwork.h>
float *output;
void setup()
{
Serial.begin(9600);
// Initializing a NeuralNetwork that runs (partially) via the Internal EEPROM of the MCU
// (Partially meaning: weights, biases, etc. NOT LOADED INTO RAM.
// Only the computation of outputs of each layer uses RAM, which can be eliminated\reduced by B01000000 and FeedForward_Individual)
NeuralNetwork NN(FROM_EEPROM_ADDRESS);
// "Feeding" the NeuralNetwork with an input array and getting the output
output = NN.FeedForward((const float[]){1, 0, 0});
// Displaying the output of double-xor-NN-from-internal-EEPROM for the input value (1, 0, 0)
Serial.println("Output of double-xor-NN-from-internal-EEPROM for the value (1,0,0) is: " +
String(round(output[0])) + " ≅ " + String(output[0], 7));
}
void loop() {}