## 5 Application of Multilayer Architecture
### Implementation
Finally, the updated weights are centralized and checked over a part of the dataset called \"test data\". This part is to check the validity of the method and the performance of the federated learning procedure. These data are processed as a reference using the code presented in Listing 3. ```
avg_model=create_model(input_shape,num_classes) avg_model.set_weights(new_weights) loss,acc=avg_model.evaluate(test_data[0],test_data[1]) precision,recall,f1=\ evaluate_with_metrics(avg_model,test_data[0],test_data[1])
```  
Listing 3: Validation of the provided model analyzing performance indicators such as precision and recall. This code recreates a model as another node of the federated learning platform. Then, it proceeds to update the weights with the one retrieved from the distributed computation. After this step, the module is evaluated as a single-node computation. To ensure the flexibility of the system, we automatized the registration to the flower platform. That is, when a Kubernetes container is powered up in a pod, it will participate automatically in the next round of distributed federated learning evaluation independently from its architecture. This was strongly automatized by the Kubernetes scale and replica features, enabling the possibility to increase the number of virtualized nodes with a single command kubectl scale -replicas=50 fl/client. Also, it is possible to perform automatic scaling, based on the performance of the system. For instance, we created a new metric using precision as the reference value. When the precision is too low (less than 50%),we create a new node, automatically trying to increase the precision due to having more workers. This could lead to cost-effective machine learning, where performances dictate the strict requirements. Setting a threshold to the minimum precision, the system will auto-adapt to reach the required value for the metric. To maintain privacy and avoid privacy leaks, we implemented Differential Privacy algorithms. Using pydp, a Python library implementing differential privacy, we performed two actions: (1) First we redacted the private data of the users, such as photos tagged as personal and data such as email addresses, phone numbers, home addresses and so on; if an application wants to avoid privacy leaks, the blocklist provided with the code should be implemented; (2) then, the dataset is augmented with noise, to avoid the recognition of private values in terms of numbers, for instance that can be used in Electronic Medical Records or Account Statement. Results  
We tested our implementation with varying numbers of clients from two to fifty and over five different datasets, which are well-known and open to the public. The datasets we considered are as follows:  
* CIFAR-10: An image dataset with 10 classes, available at [[https://www.cs.toronto.edu/~kriz/cifar.html](https://www.cs.toronto.edu/~kriz/cifar.html)]([https://www.cs.toronto.edu/~kriz/cifar.html](https://www.cs.toronto.edu/~kriz/cifar.html)) (accessed on 14 September 2024). * We selected this dataset as the main reference, due to the fact the development has been made with it in mind. We expected this dataset to be the best behaving among other well-known datasets. * CIFAR-100: Same as the CIFAR-10 dataset but with 100 classes. This is harder to train due to the augmented details of the classes, due to this fact, we expected the system to have lower performance. * MNIST: A dataset of hand-written digits, therefore, composing 10 classes, similar to CIFAR-10. Available at [[http://yann.lecun.com/exdb/mnist/](http://yann.lecun.com/exdb/mnist/)]([http://yann.lecun.com/exdb/mnist/](http://yann.lecun.com/exdb/mnist/)) (accessed on 14 September 2024) we expect it to have performances similar to the CIFAR-10 ones. * Fashion-MNIST: A dataset interchangeable with MNIST, taken as a reference, it is composed of 10 classes of photos of dresses. We expect it to have comparable performance to MNIST. * SVHN: A dataset composed of House Street Numbers, obtained with Google Street View.