-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update three mode in separate folder
- Loading branch information
1 parent
11e9314
commit 78feaef
Showing
111 changed files
with
349 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 4296_gp | ||
|
||
### prerequisite | ||
|
||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Usage | ||
|
||
Cloud computing | ||
|
||
``` | ||
mv src/ cloud_computing/server | ||
mv image/ cloud_computing/client | ||
python3 mserver.py -ip xx | ||
python3 mclient.py -ip xx | ||
``` | ||
|
||
Edge computing | ||
|
||
``` | ||
mv src/ edge_computing/server | ||
mv image/ edge_computing/client | ||
python3 mserver.py -ip 0.0.0.0 | ||
python3 mclient.py -ip xx | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import socket | ||
import zipfile | ||
import os | ||
import argparse | ||
import time | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-ip', type=str, help='ip address', default="127.0.0.1") | ||
args = parser.parse_args() | ||
|
||
ip_port = (args.ip, 9999) | ||
s = socket.socket() | ||
s.connect(ip_port) | ||
|
||
|
||
def zip_and_transfer(path='images', zip_name='tmp.zip'): | ||
with zipfile.ZipFile(zip_name, 'w') as file: | ||
for fn in os.listdir(path): | ||
file.write(os.path.join(path, fn)) | ||
filesize = str(os.path.getsize('tmp.zip')) | ||
f = open('tmp.zip', 'rb') | ||
l = f.read() | ||
s.sendall(l) | ||
|
||
|
||
def receive_and_unzip(): | ||
filename = "tmp.zip" | ||
f = open(filename, 'wb') | ||
client_data = s.recv(1024) | ||
total = 0 | ||
while (client_data): | ||
f.write(client_data) | ||
total += len(client_data) | ||
client_data = s.recv(1024) | ||
f.close() | ||
with zipfile.ZipFile(filename, 'r') as file: | ||
print('[+] Extracting files...') | ||
file.extractall() | ||
print('[+] Done') | ||
|
||
|
||
start_time = time.time() | ||
zip_and_transfer() | ||
s.close() | ||
|
||
s = socket.socket() | ||
s.connect(ip_port) | ||
server_reply = s.recv(1024).decode('utf-8') | ||
print(server_reply) | ||
|
||
receive_and_unzip() | ||
print("total time: ", time.time() - start_time) | ||
os.remove("tmp.zip") | ||
s.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import socket | ||
import zipfile | ||
import torch | ||
import os | ||
import shutil | ||
import argparse | ||
import time | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-ip', type=str, help='ip address',default="127.0.0.1") | ||
args = parser.parse_args() | ||
|
||
|
||
def zip_and_transfer(path = 'images',zip_name = 'tmp.zip'): | ||
with zipfile.ZipFile(zip_name, 'w') as file: | ||
for fn in os.listdir(path): | ||
file.write(os.path.join(path,fn)) | ||
filesize = str(os.path.getsize('tmp.zip')) | ||
print(filesize) | ||
f = open('tmp.zip', 'rb') | ||
l = f.read() | ||
conn.sendall(l) | ||
|
||
def receive_and_unzip(): | ||
print(f"receive message from {str(address)}" ) | ||
filename = "tmp.zip" | ||
f = open(filename, 'wb') | ||
client_data = conn.recv(1024) | ||
total = 0 | ||
while(client_data): | ||
f.write(client_data) | ||
total += len(client_data) | ||
client_data = conn.recv(1024) | ||
f.close() | ||
with zipfile.ZipFile(filename, 'r') as file: | ||
print('[+] Extracting files...') | ||
file.extractall() | ||
print('[+] Done') | ||
|
||
# 1. set up socket | ||
ip_port = (args.ip, 9999) | ||
sk = socket.socket() | ||
sk.bind(ip_port) | ||
sk.listen(5) | ||
print('socket service start,wait for client to connect...') | ||
conn, address = sk.accept() | ||
|
||
# 2. receive transfer images | ||
receive_and_unzip() | ||
conn.close() | ||
|
||
conn, address = sk.accept() | ||
# 3. start inference | ||
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) | ||
|
||
imgs = os.listdir('images') # batch of images | ||
imgs = list(map(lambda img: os.path.join('images/', img), imgs)) | ||
imgs = imgs[1:] # remove .DS_Store file | ||
|
||
|
||
# Inference | ||
start_time = time.time() | ||
results = model(imgs[:40]) | ||
print("total computing time for yolo:", time.time() - start_time, 's') | ||
|
||
results.save() | ||
conn.sendall('inference finished'.encode('utf-8')) | ||
|
||
# 4. reply the prediction results | ||
zip_and_transfer(path="runs/detect/exp") | ||
|
||
# 5. do the clear and close the connection | ||
os.remove("tmp.zip") | ||
shutil.rmtree("images") | ||
|
||
conn.close() | ||
sk.close() | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import socket | ||
import zipfile | ||
import os | ||
import argparse | ||
import time | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-ip', type=str, help='ip address', default="127.0.0.1") | ||
args = parser.parse_args() | ||
|
||
ip_port = (args.ip, 9999) | ||
s = socket.socket() | ||
s.connect(ip_port) | ||
|
||
|
||
def zip_and_transfer(path='images', zip_name='tmp.zip'): | ||
with zipfile.ZipFile(zip_name, 'w') as file: | ||
for fn in os.listdir(path): | ||
file.write(os.path.join(path, fn)) | ||
filesize = str(os.path.getsize('tmp.zip')) | ||
f = open('tmp.zip', 'rb') | ||
l = f.read() | ||
s.sendall(l) | ||
|
||
|
||
def receive_and_unzip(): | ||
filename = "tmp.zip" | ||
f = open(filename, 'wb') | ||
client_data = s.recv(1024) | ||
total = 0 | ||
while (client_data): | ||
f.write(client_data) | ||
total += len(client_data) | ||
client_data = s.recv(1024) | ||
f.close() | ||
with zipfile.ZipFile(filename, 'r') as file: | ||
print('[+] Extracting files...') | ||
file.extractall() | ||
print('[+] Done') | ||
|
||
|
||
start_time = time.time() | ||
zip_and_transfer() | ||
s.close() | ||
|
||
s = socket.socket() | ||
s.connect(ip_port) | ||
server_reply = s.recv(1024).decode('utf-8') | ||
print(server_reply) | ||
|
||
receive_and_unzip() | ||
print("total time: ", time.time() - start_time) | ||
os.remove("tmp.zip") | ||
s.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import socket | ||
import zipfile | ||
import os | ||
import shutil | ||
import argparse | ||
import torch | ||
import time | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-ip', type=str, help='ip address', default="127.0.0.1") | ||
args = parser.parse_args() | ||
|
||
|
||
def zip_and_transfer(path='image', zip_name='tmp.zip'): | ||
with zipfile.ZipFile(zip_name, 'w') as file: | ||
for fn in os.listdir(path): | ||
file.write(os.path.join(path, fn)) | ||
filesize = str(os.path.getsize('tmp.zip')) | ||
print(filesize) | ||
f = open('tmp.zip', 'rb') | ||
l = f.read() | ||
conn.sendall(l) | ||
|
||
|
||
def receive_and_unzip(): | ||
print(f"receive message from {str(address)}") | ||
filename = "tmp.zip" | ||
f = open(filename, 'wb') | ||
client_data = conn.recv(1024) | ||
total = 0 | ||
while (client_data): | ||
f.write(client_data) | ||
total += len(client_data) | ||
client_data = conn.recv(1024) | ||
f.close() | ||
with zipfile.ZipFile(filename, 'r') as file: | ||
print('[+] Extracting files...') | ||
file.extractall() | ||
print('[+] Done') | ||
|
||
|
||
# 1. set up socket | ||
ip_port = (args.ip, 9999) | ||
sk = socket.socket() | ||
sk.bind(ip_port) | ||
sk.listen(5) | ||
print('socket service start,wait for client to connect...') | ||
conn, address = sk.accept() | ||
|
||
# 2. receive transfer images | ||
receive_and_unzip() | ||
conn.close() | ||
|
||
conn, address = sk.accept() | ||
# 3. start inference | ||
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) | ||
|
||
imgs = os.listdir('images') # batch of images | ||
imgs = list(map(lambda img: os.path.join('images/', img), imgs)) | ||
|
||
|
||
# Inference | ||
start_time = time.time() | ||
results = model(imgs) | ||
print("total computing time for yolo:", time.time() - start_time, 's') | ||
|
||
results.save() | ||
conn.sendall('inference finished'.encode('utf-8')) | ||
|
||
# 4. reply the prediction results | ||
zip_and_transfer(path="runs/detect/exp") | ||
|
||
# 5. do the clear and close the connection | ||
os.remove("tmp.zip") | ||
shutil.rmtree("images") | ||
|
||
conn.close() | ||
sk.close() |
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# pip install -r requirements.txt | ||
|
||
# Base ---------------------------------------- | ||
matplotlib>=3.2.2 | ||
numpy>=1.18.5 | ||
opencv-python>=4.1.2 | ||
Pillow>=7.1.2 | ||
PyYAML>=5.3.1 | ||
requests>=2.23.0 | ||
scipy>=1.4.1 | ||
torch>=1.7.0 | ||
torchvision>=0.8.1 | ||
tqdm>=4.41.0 | ||
|
||
# Logging ------------------------------------- | ||
tensorboard>=2.4.1 | ||
# wandb | ||
|
||
# Plotting ------------------------------------ | ||
pandas>=1.1.4 | ||
seaborn>=0.11.0 | ||
|
||
# Export -------------------------------------- | ||
# coremltools>=4.1 # CoreML export | ||
# onnx>=1.9.0 # ONNX export | ||
# onnx-simplifier>=0.3.6 # ONNX simplifier | ||
# scikit-learn==0.19.2 # CoreML quantization | ||
# tensorflow>=2.4.1 # TFLite export | ||
# tensorflowjs>=3.9.0 # TF.js export | ||
|
||
# Extras -------------------------------------- | ||
# albumentations>=1.0.3 | ||
# Cython # for pycocotools https://github.com/cocodataset/cocoapi/issues/172 | ||
# pycocotools>=2.0 # COCO mAP | ||
# roboflow | ||
thop # FLOPs computation |