Skip to content

Commit

Permalink
Merge pull request #28 from 5sControl/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
eugenos-programos authored Sep 11, 2023
2 parents f6abd6e + 3c4cd53 commit a51be57
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 4,729 deletions.
1 change: 0 additions & 1 deletion connection/ModelPredictionsReceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def __init__(self, server_url: str, logger: Logger) -> None:
self._server_url = server_url
self._logger = logger
self._port = configs["port"]
print("server_url - ", self._server_url)

@staticmethod
def _convert_image2bytes(image: np.array, format='PNG') -> io.BytesIO:
Expand Down
7 changes: 4 additions & 3 deletions model_image/ObjectDetectionModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@


class YOLOv8ObjDetectionModel:
def __init__(self, path: str, conf_thresh: float, iou_thresh: float, classes: list) -> None:
self.model = YOLO(path)
def __init__(self, model_path: str, conf_thresh: float, iou_thresh: float, classes: list, img_size: int) -> None:
self._model = YOLO(model_path)
self.conf_thresh = conf_thresh
self.iou_thresh = iou_thresh
self.classes = classes
self.img_size = img_size

@torch.no_grad()
def __call__(self, img: np.array, classes: list = None) -> list:
results = self.model(
results = self._model(
source=img,
conf=self.conf_thresh,
iou=self.iou_thresh,
Expand Down
37 changes: 0 additions & 37 deletions model_image/YOLORObjectDetectionModel.py

This file was deleted.

9 changes: 4 additions & 5 deletions model_image/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from PIL import Image
from flask import Flask, jsonify, request
from flask_configs.load_configs import *
from flask_configs.load_configs import bottle_model_configs, box_model_configs, human_model_configs
from ObjectDetectionModel import YOLOv8ObjDetectionModel
from YOLORObjectDetectionModel import YOLORObjectDetectionModel
import numpy as np
import colorlog
import logging
Expand All @@ -24,9 +23,9 @@
logger.propagate = False

app = Flask(__name__)
human_model = YOLORObjectDetectionModel(HUMAN_MODEL_PATH, CONF_PATH, CONF_THRES, IOU_THRES, CLASSES, logger=logger)
box_model = YOLOv8ObjDetectionModel(BOX_MODEL_PATH, CONF_THRES, IOU_THRES, CLASSES)
bottle_model = YOLORObjectDetectionModel(HUMAN_MODEL_PATH, CONF_PATH, 0.2, IOU_THRES, [39], logger=logger)
human_model = YOLOv8ObjDetectionModel(**human_model_configs)
box_model = YOLOv8ObjDetectionModel(**box_model_configs)
bottle_model = YOLOv8ObjDetectionModel(**bottle_model_configs)


convert_bytes2image = lambda bytes: np.array(Image.open(io.BytesIO(bytes)), dtype=np.uint8)
Expand Down
36 changes: 27 additions & 9 deletions model_image/flask_configs/flask_confs.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
{
"classes": [
0
],
"iou_thres": 0.5,
"conf_thres": 0.5,
"config_path": "weigths/yolor_csp_x.cfg",
"box_detect_model": "weigths/min_max_v0.3.10.pt",
"human_detect_model": "weigths/min_max_v0.4.4b.pt",
"img_size": 640,
"box_model": {
"classes": [
0
],
"iou_thresh": 0.5,
"conf_thresh": 0.5,
"model_path": "weigths/min_max_v0.3.10_box.pt",
"img_size": 640
},
"human_model": {
"classes": [
0
],
"iou_thresh": 0.5,
"conf_thresh": 0.5,
"model_path": "weigths/min_max_v0.5.2_bottle.pt",
"img_size": 640
},
"bottle_model": {
"classes": [
0
],
"iou_thresh": 0.5,
"conf_thresh": 0.6,
"model_path": "weigths/min_max_v0.5.2_human.pt",
"img_size": 640
},
"port": 5000
}
11 changes: 3 additions & 8 deletions model_image/flask_configs/load_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

with open("flask_configs/flask_confs.json", "r") as conf:
configs = json.load(conf)
CONF_THRES = configs.get("conf_thres")
IOU_THRES = configs.get("iou_thres")
BOX_MODEL_PATH = configs.get("box_detect_model")
HUMAN_MODEL_PATH = configs.get("human_detect_model")
CONF_PATH = configs.get("config_path")
CLASSES = configs.get("classes")
IMG_SIZE = configs.get("img_size")
PORT = configs.get("port")
box_model_configs = configs["box_model"]
human_model_configs = configs["human_model"]
bottle_model_configs = configs["bottle_model"]
3 changes: 2 additions & 1 deletion model_image/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ httplib2==0.22.0
numpy==1.22.3
opencv_python==4.7.0.72
ultralytics==8.0.136
Flask==2.2.2
Flask==2.2.2
py-cpuinfo==9.0.0
1 change: 0 additions & 1 deletion model_image/yolor/__init__.py

This file was deleted.

12 changes: 0 additions & 12 deletions model_image/yolor/model.py

This file was deleted.

1 change: 0 additions & 1 deletion model_image/yolor/models/__init__.py

This file was deleted.

68 changes: 0 additions & 68 deletions model_image/yolor/models/export.py

This file was deleted.

Loading

0 comments on commit a51be57

Please sign in to comment.