Skip to content

Commit

Permalink
Merge pull request #34 from 5sControl/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
eugenos-programos authored Oct 11, 2023
2 parents bd424ce + 04d6540 commit 50ee54f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 179 deletions.
2 changes: 1 addition & 1 deletion connection/ImageCapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def __init__(self, path, **kwargs):
self._username = kwargs.get('username')
self._password = kwargs.get('password')
self._logger : Logger = kwargs.get('logger')
self._server_url = kwargs.get("server_url")
self._prev_img = None
if not self._username or not self._password:
self.logger.warning("Empty password or username")
Expand All @@ -29,5 +28,6 @@ def get_snapshot(self) -> cv2.Mat:
self._prev_img = image
return image, ssim_value
except Exception as exc:
print(self._camera_ip)
self._logger.warning(f"Empty image.\n {exc} \n Skipping iteration...")
return None, None
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
username = os.environ.get("username")
password = os.environ.get("password")
server_url = os.environ.get("server_url")
camera_ip = os.environ.get("camera_url")
camera_url = os.environ.get("camera_url")
folder = os.environ.get("folder")

logger = create_logger()

dataset = ImageCapture(
camera_ip,
camera_url,
username=username,
password=password,
logger=logger,
Expand Down
2 changes: 1 addition & 1 deletion min_max_utils/MinMaxReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@ def send_report_to_server(self, report: dict) -> None:
f'{self.server_url}:8000/api/reports/report-with-photos/'])
)
try:
requests.post(url=f'{self.server_url}:80/api/reports/report-with-photos/', json=report)
requests.post(url=os.environ.get("link_reports"), json=report)
except Exception as exc:
self.logger.error("Error while sending report occurred: {}".format(exc))
15 changes: 6 additions & 9 deletions min_max_utils/min_max_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@ def most_common(lst):


def check_box_in_area(box_coord: list, area_coord: list):
box_corners = (
(box_coord[0], box_coord[1]),
(box_coord[0], box_coord[3]),
(box_coord[2], box_coord[1]),
(box_coord[2], box_coord[3])
)
for box_corner in box_corners:
if area_coord[0] < box_corner[0] <= area_coord[2] and area_coord[1] < box_corner[1] <= area_coord[3]:
return True
box_center = [
(box_coord[0] + box_coord[2]) / 2,
(box_coord[1] + box_coord[3]) / 2
]
if area_coord[0] < box_center[0] < area_coord[2] and area_coord[1] < box_center[1] < area_coord[3]:
return True
return False


Expand Down
4 changes: 2 additions & 2 deletions model_image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10
FROM python:3.9
RUN apt-get update
RUN pip install torch==1.13.1+cpu torchvision==0.14.1+cpu --extra-index-url https://download.pytorch.org/whl/cpu
COPY requirements.txt .
Expand All @@ -9,4 +9,4 @@ WORKDIR /var/www/5scontrol
COPY . .
RUN mkdir -p /usr/src/app
EXPOSE 5000
CMD [ "flask", "run","--host","0.0.0.0","--port","5000"]
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "5000"]
153 changes: 0 additions & 153 deletions model_image/ONNXModel.py

This file was deleted.

26 changes: 26 additions & 0 deletions model_image/YOLONASObjDetectionModel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from super_gradients.training import models
from super_gradients.common.object_names import Models
import torch
import numpy as np


class YOLONASObjDetectionModel:
def __init__(self, model_path: str, conf_thresh: float, iou_thresh: float, classes: list, img_size: int) -> None:
# self.device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
self._model = models.get(model_path, pretrained_weights='coco', num_classes=80)
self._model.eval()
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) -> list:
results = self._model.predict(img, fuse_model=False)
prediction = results[0].prediction
labels = prediction.labels.astype(int) == self.classes[0]
boxes = prediction.bboxes_xyxy[labels]
confs = np.expand_dims(prediction.confidence.astype(float)[labels], -1)
#confs =
coords_with_confs = np.hstack((boxes, confs))
return coords_with_confs
5 changes: 3 additions & 2 deletions model_image/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask import Flask, jsonify, request
from flask_configs.load_configs import bottle_model_configs, box_model_configs, human_model_configs
from ObjectDetectionModel import YOLOv8ObjDetectionModel
from YOLONASObjDetectionModel import YOLONASObjDetectionModel
import numpy as np
import colorlog
import logging
Expand All @@ -23,9 +24,9 @@
logger.propagate = False

app = Flask(__name__)
human_model = YOLOv8ObjDetectionModel(**human_model_configs)
human_model = YOLONASObjDetectionModel(**human_model_configs)
box_model = YOLOv8ObjDetectionModel(**box_model_configs)
bottle_model = YOLOv8ObjDetectionModel(**bottle_model_configs)
bottle_model = YOLONASObjDetectionModel(**bottle_model_configs)


convert_bytes2image = lambda bytes: np.array(Image.open(io.BytesIO(bytes)), dtype=np.uint8)
Expand Down
4 changes: 2 additions & 2 deletions model_image/flask_configs/flask_confs.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"iou_thresh": 0.5,
"conf_thresh": 0.5,
"model_path": "weigths/min_max_v0.5.2_human.pt",
"model_path": "yolo_nas_s",
"img_size": 640
},
"bottle_model": {
Expand All @@ -23,7 +23,7 @@
],
"iou_thresh": 0.5,
"conf_thresh": 0.5,
"model_path": "weigths/min_max_v0.5.2_bottle.pt",
"model_path": "yolo_nas_m",
"img_size": 640
},
"port": 5000
Expand Down
13 changes: 6 additions & 7 deletions model_image/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
colorlog==4.8.0
httplib2==0.22.0
numpy==1.22.3
opencv_python==4.7.0.72
ultralytics==8.0.136
ultralytics==8.0.191
super-gradients==3.2.1
timm==0.6.7
Flask==2.2.2
py-cpuinfo==9.0.0
onnxruntime==1.15.1
numpy==1.23.0
Werkzeug==2.2.2
colorlog==4.8.0

0 comments on commit 50ee54f

Please sign in to comment.