- TinyFL Model: ML Based IDS for IoT Botnet Detection
Go to the Folder Python_FL_Model and follow the README
Follow this Tutorial Embedded Devices. Instead of cloning their example use mine.
On your development machine, launch the SuperLink. You will connnect Flower SuperNodes to it in the next step.
flower-superlink --insecureWith the 'SuperLink' up and running, we can now launch a SuperNode on each embedded device. To do this, make sure you know the IP address of the machine running the SuperLink and that the necessary data has been copied to the device.
Ensure the Python environment you created earlier when setting up your device has all dependencies installed.
Now, launch your 'SuperNode'
# Repeat for each embedded device (adjust SuperLink IP and partition-id)
flower-supernode --insecure --superlink SuperLink IP:9092 --node-config "partition-id=0 num-partitions=4"Repeat for each embedded device that you want to connect to the SuperLink. Change partition-id if you want the Client to use different Data.
If you want to use SuperLink and SuperNode on PC with multiple Terminals launch 'Supernode' with this
# Repeat for each embedded device (adjust SuperLink IP, Clientappio Port and partition-id)
flower-supernode --insecure --superlink SuperLink IP:9092 --clientappio-api-address 127.0.0.1:9097 --node-config "partition-id=0 num-partitions=4"Change the clientappio-api-address Port for each Client. Change partition-id if you want the Client to use different Data.
With both the long-running server (SuperLink) and two SuperNodes up and running, we can now start run. Let's first update the Flower Configuration file to add a new SuperLink connection.
Locate your Flower configuration file by running:
flwr config list# Example output:
Flower Config file: /path/to/your/.flwr/config.toml
SuperLink connections:
-supergrid
-local (default)Open this configuration file and add a new SuperLink connection at the end:
[superlink.embedded-federation]
address = "127.0.0.1:9093" # ControlAPI of your SUPERLINK
insecure = trueFinally, run your Flower App in your federation:
flwr run . embedded-federationTake the resulting Files final_model.pt,calibration_data.npy,tree_model.h,mcu_test_data.h,mcu_val_data.h from the folder Python_FL_Model.
Copy tree_model.h, mcu_test_data.h and ,mcu_val_data.h into the folder ESP32_Model/main from the folder TINYML.
Copy final_model.pt and calibration_data.npy into the folder Model_converter.
create new venv, look at tinyml_env2
- take final_model.pt
- drag it into TinyML_Conversion
- run converter_onnx.py do it both for normal model and encoder. With an enviroment that has both torch and onnx.
- new terminal with tinyml_env2 as enviroment run:
onnx2tf -i model.onnx -o saved_model
onnx2tf -i model_encoder.onnx -o saved_model_enc- run converter_tf_tflite_fix_hard.py
- run converter_tflite_c.py
- copy the files
model.handmodel_encoder.hinto the folderTINYML/main
