## 3 TinyML Implemenatation
### Implementation Methodology
The training steps are executed on the computer. The obtained result is a file that contains the trained model. Training (x_train, y_train) and testing data (x_test, y_test) are obtained using the code shown in Figure 8. As a good practice adopted from various reports in the state of the art [48, 88], the \"one-hot\" labeling technique is used. Figure 9 illustrates an example of the corresponding features (input data) and label matrix (output) for the DNN model obtained as a result of the code given in Figure 8. It should be noted that the input matrix in Figure 6 is used for demonstration purposes in the explanation. Likewise, this matrix is presented in Figure 9; however, for better understanding, it is presented again with the output tags in one-hot format. Figure 10 depicts the code fragment for executing the training step considering the architecture described in the code snippet shown in Figure 8. The hyperparameters are given with the statement \(model\_compile\). The numbers of epochs are set within the statement \(model\_fit\). Finally, the training parameterization is as follows:  
1. Loss function: Categorical cross-entropy. 2. Optimizer: [PERSON]. 3. Metrics to evaluate: Accuracy. 4. Epochs: 100. 5. Batch size: 1. Before the launch of the training processes, the Iris dataset is divided into two groups. Figure 8 shows how the dataset is divided into 80% for the training (x_train, y_train) and 20% for the validation (x_test, y_test). The graphical behavior of the DNN model during the training stage is shown in Figure 11, taking into account 100 training epochs. Figure 12 shows the training process on the computer using Python and TensorFlow. An important issue when training ANN with TensorFlow and Keras in Python is the numerical format of the dataset. In some cases, this format is \(uint64\) (64 bits), which turns out to be a data type that would generate trained models with a large size. In the case of this implementation, for the Iris dataset, the data type was changed to \(float32\) with the statements x_train = x_train.astype(\"float32') and y_train = y_train.astype(\"float32'), which is a 32-bit float type; thus, the trained model results in a smaller size without disregarding precision in the data and hoping that the accuracy of the model when making predictions does not decrease. However, converting the Iris dataset data from \(uint64\) to \(float32\) allows the compression process to obtain better results by reducing the size of the model file. However, performing the data type conversion directly in the Iris dataset before  
Figure 10: Code Snippet with the statement for training and hyperparameters of the DNN. Figure 8.0 Matrix with input features and matrix with output labels for the DNN. the training process does not mean that a quantization process is still involved. However, the possibility of doing so remains available. **Testing and compressing the model on a computer**. As a first performance test, the classification processes through the DNN are tested on a computer using Python and Keras. However, the most important step is when the DNN is tested by performing the flower-type classification process within the embedded system. Figure 13 depicts the portion of code on which the \(model\_evaluate\) statement is executed to obtain the trained model's accuracy and loss function value at the last epoch executed in the training process. The result in the Python IDLE output terminal is _loss_0.6000, _Accuracy_: 0.96666638. Figure 8.1 Training results. “Loss”: loss function of the training dataset; “val-loss”: validation dataset loss function; “accuracy”: degree of accuracy of the training dataset; “val-accuracy”: degree of accuracy of the validation dataset. Figure 8.2 Training process on the computer. The final result of the training process is a file, with \(H5\) extension, that contains the trained model. Subsequently, the \(H5\) file is compressed to a file with a _tflite_ extension and then converted to a \(cc\) extension file.