/FYP_project

Collaborative Federated Learning Platform for Privacy-preserved Decentralized Machine Learning in Industrial Internet of Things

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Collaborative Federated Learning Platform for Privacy-preserved Decentralized Machine Learning in Industrial Internet of Things

To establish a better TCP connection, we tryed different mechanisms. However, in practical internet usage, we can use TCP punching, for which we can use a middle communication bridge device. In this case, we can use WebSockets to establish a connection, which is helpful for real-time communication over NAT routing networks. However, we cannot send large data over WebSockets, so we use byte data streams to break the data into small chunks and send them as separate packets over the internet. Below is an overview of the communication method as peer-to-peer.

P2P Communication Protocole

Blank-board-Page-1-3.png

Novel Distributed Fedarated learning Protocol

protocol

Deployment

Requried library install

pip install -r requirements.txt

Required tensorflow package donload and add to child_cart Directory

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow_cpu-2.11.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

run web app

yarn tauri dev

setup tauri environment windows : https://tauri.app/v1/guides/building/windows/ MacOS : https://tauri.app/v1/guides/building/macos/ Linux : https://tauri.app/v1/guides/building/linux/

for production

Requried :(tensorflow 12 or latest == keras , Requried library for python , and tauri with Requried yarn packages)

Linux (binary file)

deploy vite application : yarn build coppy build file : cp -r web_app/dist/* child_cart/api/templates Parent Cart : pyinstaller --onefile --add-data "child_cart/api/templates:child_cart/api/templates" --name P_main.bin C_main.py Child Cart : pyinstaller --onefile --add-data "child_cart/api/templates:child_cart/api/templates" --name C_main.bin C_main.py or make upl

Windos (executable file)

deploy vite application : yarn build coppy build file : cp -r web_app/dist/* child_cart/api/templates Parent Cart : pyinstaller --onefile --add-data "child_cart/api/templates;child_cart/api/templates" --name P_main.bin C_main.py Child Cart : pyinstaller --onefile --add-data "child_cart/api/templates;child_cart/api/templates" --name C_main.bin C_main.py or make upw

Create dev test objects

When creating multiple objects in the same PC environment, it is important to be mindful of the available I/O resources and processing speed.

At the network layer, it is recommended to have at least 500KB/s of bandwidth available for each peer to ensure proper communication. If the available bandwidth is lower than this, it may cause problems with communication between peers.

To test the functionality of the project, you can use the "test" directory located in the root project folder. This directory contains test images that can be used to verify that the project is working correctly

Parent cart image

use ./main.py

import sys
import os

# Get the path to the root directory (two levels up from the current file)
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "."))

# Add the root directory to the Python path
sys.path.insert(0, root_path)

# Import the parent_cart module from the main package
from parent_cart.main import *

if __name__ == '__main__':
    try:
        # Call the parent_cart function from the main module
        parent_cart()
    except KeyboardInterrupt:
        # If a keyboard interrupt is received, print a message and kill all Python processes
        print("Keyboard interrupt received. Closing all programs...")
        os.system("pkill -f python")

Child cart image

use ./main.py

import sys
import os

# Get the path to the root directory (two levels up from the current file)
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "."))

# Add the root directory to the Python path
sys.path.insert(0, root_path)

# Import the mainFunc function from the child_cart module
from child_cart.main import *

if __name__ == '__main__':
    # Call the mainFunc function from the child_cart module
    mainFunc()

Tech Stack

Bridge Module:

(Http - Protocole) aiohttp : https://pypi.org/project/aiohttp/

(TCP - Protocole) Socket : https://docs.python.org/3/library/socket.html

(kademlia - Protocole - distributed network) kademlia: https://pypi.org/project/kademlia/

Cart network module:

(serialize data packet) pickle: https://docs.python.org/3/library/pickle.html

Python Application:

dependencies

pip==20.2.3
aiohttp==3.8.4
kademlia==2.2.2
pymongo==4.3.3
scikit-learn==1.2.1
numpy==1.24.1
cv2==4.7.0
pyzbar==0.1.9
tensorflow==2.11.0
Flask==2.2.2 
Flask-Cors==3.0.10
h5py==3.8.0
keras==2.11.0
pandas==1.5.2

Mobile Application:

dependencies

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation 'org.tensorflow:tensorflow-lite:+'
    implementation 'org.tensorflow:tensorflow-lite-support:0.1.0-rc1'
    implementation 'com.github.denzcoskun:ImageSlideshow:0.1.0'

Bugs Solve

    https://github.com/hiway/rpcudp/commit/92bfff36740ca2fcfa77f47ceb87d3ba480083ea

Docker setup in ubuntu 18.04

//admin privilage
sudo su

//proxi configure
sudo nano /etc/resolv.conf
//apply following 
nameserver 8.8.8.8
nameserver 8.8.4.4

//docker cli
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
sudo systemctl status docker

//docker composer
sudo apt update -y
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
docker --version; docker compose version;ctr version


sudo systemctl daemon-reload
sudo systemctl restart docker

//errorfix dpkg
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*

Project run in docker commands

 //runnning containers
docker ps
//stop
docker stop <container_id>

//down contrainer see
docker ps -a
//down contrainers delete
docker rm <container_id>

//see docker images
docker images
//delete images
docker rmi <image_name_or_id>


//build
docker build -t fyp .
//start
docker run -it --network=host fyp

//current log
docker logs <container_name_or_id>

//log continues
docker logs -f <container_name_or_id>
docker exec -it <container_name_or_id> /bin/bash

File Organization

📦 
├─ .dockerignore
├─ .env
├─ .gitignore
├─ Makefile
├─ README.md
├─ SECURITY.md
├─ child_cart
│  â”œâ”€ Dockerfile
│  â”œâ”€ db
│  â”‚  â””─ dbConnect.py
│  â”œâ”€ main.py
│  â”œâ”€ model
│  â”‚  â”œâ”€ Main.py
│  â”‚  â”œâ”€ QRScanner.py
│  â”‚  â”œâ”€ csvFileGenerator.py
│  â”‚  â”œâ”€ dataSetGenerator.py
│  â”‚  â”œâ”€ dataSetSplit.py
│  â”‚  â”œâ”€ encodeParameter.py
│  â”‚  â”œâ”€ fileHandle.py
│  â”‚  â”œâ”€ modelAccuracy.py
│  â”‚  â”œâ”€ modelAggregation.py
│  â”‚  â”œâ”€ modelGenerator.py
│  â”‚  â”œâ”€ modelTraining.py
│  â”‚  â”œâ”€ saveModelData.py
│  â”‚  â””─ writeFile.py
│  â”œâ”€ network
│  â”‚  â”œâ”€ cartConfiguration.py
│  â”‚  â”œâ”€ client.py
│  â”‚  â”œâ”€ com.py
│  â”‚  â”œâ”€ enumList.py
│  â”‚  â”œâ”€ errorList.py
│  â”‚  â”œâ”€ file.py
│  â”‚  â”œâ”€ filesender.py
│  â”‚  â”œâ”€ seed.py
│  â”‚  â”œâ”€ soc9k.py
│  â”‚  â””─ util.py
│  â”œâ”€ requirements.txt
│  â”œâ”€ startup.sh
│  â”œâ”€ templates
│  â”‚  â”œâ”€ admin.html
│  â”‚  â””─ home.html
│  â””─ api
│     â””─ Flask.py
├─ docker-compose.yml
├─ docker-composer.dev.yml
├─ mobile_app
│  â”œâ”€ .gitignore
│  â”œâ”€ .idea
│  â”‚  â”œâ”€ .gitignore
│  â”‚  â”œâ”€ .name
│  â”‚  â”œâ”€ compiler.xml
│  â”‚  â”œâ”€ gradle.xml
│  â”‚  â”œâ”€ jarRepositories.xml
│  â”‚  â”œâ”€ misc.xml
│  â”‚  â””─ vcs.xml
│  â”œâ”€ app
│  â”‚  â”œâ”€ .gitignore
│  â”‚  â”œâ”€ build.gradle
│  â”‚  â”œâ”€ proguard-rules.pro
│  â”‚  â””─ src
│  â”‚     â”œâ”€ androidTest
│  â”‚     â”‚  â””─ java
│  â”‚     â”‚     â””─ com
│  â”‚     â”‚        â””─ example
│  â”‚     â”‚           â””─ cachemobile
│  â”‚     â”‚              â””─ ExampleInstrumentedTest.java
│  â”‚     â”œâ”€ main
│  â”‚     â”‚  â”œâ”€ AndroidManifest.xml
│  â”‚     â”‚  â”œâ”€ assets
│  â”‚     â”‚  â”‚  â”œâ”€ dataset.csv
│  â”‚     â”‚  â”‚  â””─ model.tflite
│  â”‚     â”‚  â”œâ”€ java
│  â”‚     â”‚  â”‚  â””─ com
│  â”‚     â”‚  â”‚     â””─ example
│  â”‚     â”‚  â”‚        â””─ cachemobile
│  â”‚     â”‚  â”‚           â””─ MainActivity.java
│  â”‚     â”‚  â””─ res
│  â”‚     â”‚     â”œâ”€ drawable-v24
│  â”‚     â”‚     â”‚  â””─ ic_launcher_foreground.xml
│  â”‚     â”‚     â”œâ”€ drawable
│  â”‚     â”‚     â”‚  â””─ ic_launcher_background.xml
│  â”‚     â”‚     â”œâ”€ layout
│  â”‚     â”‚     â”‚  â””─ activity_main.xml
│  â”‚     â”‚     â”œâ”€ mipmap-anydpi-v26
│  â”‚     â”‚     â”‚  â”œâ”€ ic_launcher.xml
│  â”‚     â”‚     â”‚  â””─ ic_launcher_round.xml
│  â”‚     â”‚     â”œâ”€ mipmap-hdpi
│  â”‚     â”‚     â”‚  â”œâ”€ ic_launcher.png
│  â”‚     â”‚     â”‚  â””─ ic_launcher_round.png
│  â”‚     â”‚     â”œâ”€ mipmap-mdpi
│  â”‚     â”‚     â”‚  â”œâ”€ ic_launcher.png
│  â”‚     â”‚     â”‚  â””─ ic_launcher_round.png
│  â”‚     â”‚     â”œâ”€ mipmap-xhdpi
│  â”‚     â”‚     â”‚  â”œâ”€ ic_launcher.png
│  â”‚     â”‚     â”‚  â””─ ic_launcher_round.png
│  â”‚     â”‚     â”œâ”€ mipmap-xxhdpi
│  â”‚     â”‚     â”‚  â”œâ”€ ic_launcher.png
│  â”‚     â”‚     â”‚  â””─ ic_launcher_round.png
│  â”‚     â”‚     â”œâ”€ mipmap-xxxhdpi
│  â”‚     â”‚     â”‚  â”œâ”€ ic_launcher.png
│  â”‚     â”‚     â”‚  â””─ ic_launcher_round.png
│  â”‚     â”‚     â”œâ”€ values-night
│  â”‚     â”‚     â”‚  â””─ themes.xml
│  â”‚     â”‚     â””─ values
│  â”‚     â”‚        â”œâ”€ colors.xml
│  â”‚     â”‚        â”œâ”€ strings.xml
│  â”‚     â”‚        â””─ themes.xml
│  â”‚     â””─ test
│  â”‚        â””─ java
│  â”‚           â””─ com
│  â”‚              â””─ example
│  â”‚                 â””─ cachemobile
│  â”‚                    â””─ ExampleUnitTest.java
│  â”œâ”€ build.gradle
│  â”œâ”€ gradle.properties
│  â”œâ”€ gradle
│  â”‚  â””─ wrapper
│  â”‚     â”œâ”€ gradle-wrapper.jar
│  â”‚     â””─ gradle-wrapper.properties
│  â”œâ”€ gradlew
│  â”œâ”€ gradlew.bat
│  â””─ settings.gradle
└─ parent_cart
   â”œâ”€ Dockerfile
   â”œâ”€ bridge
   â”‚  â”œâ”€ Main.py
   â”‚  â”œâ”€ rndGen.py
   â”‚  â””─ util.py
   â”œâ”€ main.py
   â”œâ”€ requirements.txt
   â””─ startup.sh

Authors