A federated learning package for IoT devices and aggregation server communication.
Project description
kehe-fl
A federated learning package for IoT devices and aggregation server communication using MQTT.
Features
- Distributed, federated learning orchestration using MQTT
- Device-side and server-side reference implementations
- Asyncio-based for efficient concurrency
- Modular design for custom ML or IoT projects
Quick Start
Installation
pip install kehe-fl
Example Usage
Device Side
import asyncio
from kehe_fl.comms.mqtt_device import MQTTDevice
mqttConnection: MQTTDevice | None = None
async def main():
global mqttConnection
mqttConnection = MQTTDevice(broker="192.168.1.193", deviceId="device123")
mqtt_task = asyncio.create_task(mqttConnection.connect_and_listen())
await asyncio.gather(mqtt_task)
asyncio.run(main())
Aggregation Server Side
import asyncio
from kehe_fl.comms.mqtt_agg_server import MQTTAggServer
mqttConnection: MQTTAggServer | None = None
async def handleMessaging():
global mqttConnection
loop = asyncio.get_running_loop()
while True:
if mqttConnection.is_connected and not mqttConnection.working:
message = await loop.run_in_executor(None, input, "Enter a command to send to the clients: ")
await mqttConnection.send_command(message)
else:
await asyncio.sleep(2)
async def main():
global mqttConnection
mqttConnection = MQTTAggServer(broker="localhost")
mqtt_task = asyncio.create_task(mqttConnection.connect_and_listen())
input_task = asyncio.create_task(handleMessaging())
await asyncio.gather(mqtt_task, input_task)
asyncio.run(main())
Adapt
Communication
You can adapt the device and server code to your specific ML or IoT project needs by modifying the MQTTDevice and MQTTAggServer or even MQTTProvider classes. These classes provide a foundation for communication and can be extended with custom logic for model training, data handling, and more.
Machine Learning
You can integrate your preferred machine learning libraries (like TensorFlow, PyTorch, etc.) into the device and server implementations with modifying ModelService. The provided classes can be used to send model updates, receive commands, and manage the training process across devices.
Data Collection
You can implement custom sensor classes in common/<your sensor>.pyand also modify the DataCollectionService for your needs. This allows you to collect and process data from various IoT sensors and devices, which can then be used for training machine learning models.
Project Constants
You can modify the project_constants.py file to change the MQTT topic structure, message formats, and other constants used throughout the package. This allows you to tailor the communication protocol to your specific requirements.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kehe_fl-0.1.10.tar.gz.
File metadata
- Download URL: kehe_fl-0.1.10.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
431429f4f217ef91ac91f81cedd4a78c2edaf4fe79364e05d0190a79441f7df2
|
|
| MD5 |
9a5b045c9f41846287091e012f01319f
|
|
| BLAKE2b-256 |
aad80821218453dc28939f5353008d181cc958fe4919d93827ea29069f872000
|
File details
Details for the file kehe_fl-0.1.10-py3-none-any.whl.
File metadata
- Download URL: kehe_fl-0.1.10-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
413378cbb2ac0ce8914b7984e5b3064d81f692fd4a766f9226e422ef8df7ad41
|
|
| MD5 |
a99af56cc6dc1d374a482519a6b0ba16
|
|
| BLAKE2b-256 |
af405388e124157c7fca7bbd94a246bfe32e5d185061abf19a8532b179360cc2
|