This project is designed to train a YOLOv5 model in a federated approach using embedded systems for coffee plant detection.
The embedded systems used for the development of this project were three 4GB Jetson Nano Developer Kits.
To perform the complete installation of the necessary libraries on a Jetson Nano, visit the tutorial here
For server library installation instructions, see here
Warning
Ensure OpenSSL is installed on the server.
To allow clients to connect securely, check the server's IP address in gen_certs.sh and then run:
chmod +x gen_certs.sh
./gen_certs.sh
This will generate the OpenSSL certificates; ca.crt must be copied to each node.
This ensures that only the server can connect to the nodes. If UFW is not installed, run this command twice.
chmod +x ufw_setup.sh
sudo ./ufw_setup.sh
If you only have the base dataset, run:
python3 divide_dataset.py `--num_nodes` N `--input_dir` <Directory where the dataset is located> `--output_dir` <Directory where each subset is saved>
This divides your dataset into the number of nodes N you have randomly, so you must send each folder to the nodes.
- First, run the server
python3 server.py
Tip
The server has several options.
--no_defenses: Disables Byzantine defenses.--output: The directory where the models for each round will be stored in.npyformat. (If the output folder already has a.npymodel, its treated as a checkpoint).
- Then run the clients.
python3 client.py
Tip
You can run the clients first and then the server because they wait for the server to become available (no more than 30 seconds).
- If you want to run a malicious client, choose the type of attack to perform in the
.envfile (sign_flip, gaussian_noise, scale_attack, zero_weights) and run:
python3 malicious_client.py
The results are saved in ~/logs within each client. Use the filename plus the file extension to graph the results.
To view the loss during training, run:
python plot_loss.py --csv <path_to_file.csv> --out <output_format>
To view the metrics, run:
python plot_loss.py -csv <path_to_file.csv> --out <output_format> --hw_metrics
Once federated training is complete, simply run:
python3 export_model.py --round N --params_path <path_to_model.npy> --output <model_name>
Nis the round from which you want to extract the model
To explicitly test the trained model, a series of steps must be performed.
First, uninstall grpcio, since yolo uses version 1.70.0.
pip uninstall grpcio
Next, install the default version, which is installed as Python 3.8 (it must be 1.70.0).
pip install grpcio
Next, navigate to the yolo folder.
cd yolov5/
Here we will use the inference script detect.py included in the repository as follows:
python.exe detect.py --weights <model_path.pt> --source <image_path_to_use.jpg>
This script will save the inference in this directory:
~/yolov5/runs/detect/exp*