From e57a817e325ced5e27b70b86e85e7d573f1f5ff7 Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Wed, 2 Oct 2024 17:56:56 +0200 Subject: [PATCH 1/7] allow to set USE_BACKDOOR_CONTROLS in env --- detector/docker.sh | 1 + trainer/docker.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/detector/docker.sh b/detector/docker.sh index e8efa28..266fce2 100755 --- a/detector/docker.sh +++ b/detector/docker.sh @@ -75,6 +75,7 @@ run_args="-it" run_args+=" -v $HOME/node_data/$DETECTOR_NAME:/data" run_args+=" -h ${HOSTNAME}_DEV" run_args+=" -e HOST=$LOOP_HOST -e ORGANIZATION=$LOOP_ORGANIZATION -e PROJECT=$LOOP_PROJECT" +run_args+=" -e USE_BACKDOOR_CONTROLS=$USE_BACKDOOR_CONTROLS" run_args+=" --name $DETECTOR_NAME" run_args+=" --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all" run_args+=" -p 8004:80" diff --git a/trainer/docker.sh b/trainer/docker.sh index dabbbe2..2ef80f3 100755 --- a/trainer/docker.sh +++ b/trainer/docker.sh @@ -74,6 +74,7 @@ run_args+=" -h ${HOSTNAME}_DEV" run_args+=" -e HOST=$HOST -e USERNAME=$USERNAME -e PASSWORD=$PASSWORD -e LOOP_SSL_CERT_PATH=$LOOP_SSL_CERT_PATH" run_args+=" -e BATCH_SIZE=$BATCH_SIZE -e UVICORN_RELOAD=$UVICORN_RELOAD -e RESET_POINTS=$RESET_POINTS -e KEEP_OLD_TRAININGS=$KEEP_OLD_TRAININGS" run_args+=" -e NODE_TYPE=trainer -e YOLOV5_MODE=$YOLOV5_MODE -e RESTART_AFTER_TRAINING=$RESTART_AFTER_TRAINING -e TRAINER_IDLE_TIMEOUT_SEC=$TRAINER_IDLE_TIMEOUT_SEC" +run_args+=" -e USE_BACKDOOR_CONTROLS=$USE_BACKDOOR_CONTROLS" run_args+=" --name $TRAINER_NAME" run_args+=" --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all --gpus all" run_args+=" --ipc host" From 9274bbb0ae1ec72d8b91034b95a53fd412b68062 Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Wed, 2 Oct 2024 17:57:30 +0200 Subject: [PATCH 2/7] set timing loglevel to debug fix some type hints and simplify calculation of box center --- detector/yolov5_detector.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/detector/yolov5_detector.py b/detector/yolov5_detector.py index 4acff1c..41111f9 100644 --- a/detector/yolov5_detector.py +++ b/detector/yolov5_detector.py @@ -4,7 +4,7 @@ import re import subprocess import time -from typing import List, Optional, Tuple +from typing import Optional, Tuple import cv2 import numpy as np @@ -61,7 +61,7 @@ def clip_point(x: float, y: float, img_width: int, img_height: int) -> Tuple[flo y = min(max(0, y), img_height) return x, y - def evaluate(self, image: List[np.uint8]) -> Detections: + def evaluate(self, image: np.ndarray) -> Detections: assert self.yolov5 is not None, 'init() must be executed first. Maybe loading the engine failed?!' detections = Detections() try: @@ -70,7 +70,7 @@ def evaluate(self, image: List[np.uint8]) -> Detections: im_height, im_width, _ = cv_image.shape results, inference_ms = self.yolov5.infer(cv_image) skipped_detections = [] - logging.info(f'took {inference_ms} s, overall {time.time() -t} s') + logging.debug('took %f s, overall %f s', inference_ms, time.time() - t) for detection in results: x, y, w, h, category_idx, probability = detection category = self.model_info.categories[category_idx] @@ -80,14 +80,24 @@ def evaluate(self, image: List[np.uint8]) -> Detections: if category.type == CategoryType.Box: x, y, w, h = self.clip_box(x, y, w, h, im_width, im_height) detections.box_detections.append( - BoxDetection(category_name=category.name, x=x, y=y, width=w, height=h, category_id=category.id, - model_name=self.model_info.version, confidence=probability)) + BoxDetection(category_name=category.name, + x=round(x), + y=round(y), + width=round(w), + height=round(h), + category_id=category.id, + model_name=self.model_info.version, + confidence=probability)) elif category.type == CategoryType.Point: - cx, cy = (np.average([x, x + w]), np.average([y, y + h])) + cx, cy = x + w/2, y + h/2 cx, cy = self.clip_point(cx, cy, im_width, im_height) detections.point_detections.append( - PointDetection(category_name=category.name, x=int(cx), y=int(cy), category_id=category.id, - model_name=self.model_info.version, confidence=probability)) + PointDetection(category_name=category.name, + x=cx, + y=cy, + category_id=category.id, + model_name=self.model_info.version, + confidence=probability)) if skipped_detections: log_msg = '\n'.join([str(d) for d in skipped_detections]) logging.warning( From fafabe76d1efd55f17a69ed5866441906bf86d31 Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Wed, 2 Oct 2024 18:00:32 +0200 Subject: [PATCH 3/7] bump nodelib version for detector and trainer to 0.10.13 --- detector/docker.sh | 4 ++-- trainer/docker.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/detector/docker.sh b/detector/docker.sh index 266fce2..3a77cfe 100755 --- a/detector/docker.sh +++ b/detector/docker.sh @@ -28,8 +28,8 @@ fi # ========================== BUILD CONFIGURATION / IMAGE SELECTION ======================= -SEMANTIC_VERSION=0.1.3 -NODE_LIB_VERSION=0.10.11 +SEMANTIC_VERSION=0.1.4 +NODE_LIB_VERSION=0.10.13 build_args=" --build-arg NODE_LIB_VERSION=$NODE_LIB_VERSION" if [ -f /etc/nv_tegra_release ] # Check if we are on a Jetson device diff --git a/trainer/docker.sh b/trainer/docker.sh index 2ef80f3..27be1ae 100755 --- a/trainer/docker.sh +++ b/trainer/docker.sh @@ -44,8 +44,8 @@ fi # NODE_LIB_VERSION should only be used, to build the corresponding version and deploy to docker # make sure the remote repository always has the 'latest' tag (otherwise the CI tests will fail) -SEMANTIC_VERSION=0.1.3 -NODE_LIB_VERSION=0.10.12 +SEMANTIC_VERSION=0.1.4 +NODE_LIB_VERSION=0.10.13 #image="zauberzeug/yolov5-trainer:$SEMANTIC_VERSION-nlv$NODE_LIB_VERSION" image="zauberzeug/yolov5-trainer:latest" From 3a17704c91ce95feae47ade8f9fd92e993b92a86 Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Wed, 2 Oct 2024 18:15:56 +0200 Subject: [PATCH 4/7] Make sure debug prints are by default not visible --- detector/yolov5_detector.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/detector/yolov5_detector.py b/detector/yolov5_detector.py index 41111f9..d724885 100644 --- a/detector/yolov5_detector.py +++ b/detector/yolov5_detector.py @@ -22,6 +22,8 @@ def __init__(self) -> None: self.yolov5: Optional[yolov5.YoLov5TRT] = None self.weight_type = os.getenv('WEIGHT_TYPE', 'FP16') assert self.weight_type in ['FP16', 'FP32', 'INT8'], 'WEIGHT_TYPE must be one of FP16, FP32, INT8' + self.log = logging.getLogger('Yolov5Detector') + self.log.setLevel(logging.INFO) def init(self) -> None: resolution = self.model_info.resolution @@ -70,7 +72,7 @@ def evaluate(self, image: np.ndarray) -> Detections: im_height, im_width, _ = cv_image.shape results, inference_ms = self.yolov5.infer(cv_image) skipped_detections = [] - logging.debug('took %f s, overall %f s', inference_ms, time.time() - t) + self.log.debug('took %f s, overall %f s', inference_ms, time.time() - t) for detection in results: x, y, w, h, category_idx, probability = detection category = self.model_info.categories[category_idx] From 6b8ef0402d0f903fcba45b226434efb764cb9180 Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Wed, 2 Oct 2024 18:17:39 +0200 Subject: [PATCH 5/7] use self.log everywhere --- detector/yolov5_detector.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/detector/yolov5_detector.py b/detector/yolov5_detector.py index d724885..a54ce6e 100644 --- a/detector/yolov5_detector.py +++ b/detector/yolov5_detector.py @@ -105,7 +105,7 @@ def evaluate(self, image: np.ndarray) -> Detections: logging.warning( f'Removed {len(skipped_detections)} small detections from result: \n{log_msg}') except Exception: - logging.exception('inference failed') + self.log.exception('inference failed') return detections def _create_engine(self, resolution: int, cat_count: int, wts_file: str) -> str: @@ -122,13 +122,13 @@ def _create_engine(self, resolution: int, cat_count: int, wts_file: str) -> str: with open('../src/config.h', 'r+') as f: content = f.read() if self.weight_type == 'INT8': - logging.info('using INT8') + self.log.info('using INT8') content = content.replace('#define USE_FP16', '#define USE_INT8') elif self.weight_type == 'FP32': - logging.info('using FP32') + self.log.info('using FP32') content = content.replace('#define USE_FP16', '#define USE_FP32') else: - logging.info('using FP16') + self.log.info('using FP16') content = re.sub('(kNumClass =) \d*', r'\1 ' + str(cat_count), content) @@ -140,7 +140,7 @@ def _create_engine(self, resolution: int, cat_count: int, wts_file: str) -> str: subprocess.run('make -j6 -Wno-deprecated-declarations', shell=True, check=True) - logging.warning('currently we assume a Yolov5 s6 model;\ + self.logself.log.warning('currently we assume a Yolov5 s6 model;\ parameterization of the variant (s, s6, m, m6, ...) still needs to be done') # TODO parameterize variant "s6" subprocess.run( From f26812b609cd339a524f0a2185e0039bcb635800 Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Wed, 2 Oct 2024 18:18:19 +0200 Subject: [PATCH 6/7] fix copy paste error --- detector/yolov5_detector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detector/yolov5_detector.py b/detector/yolov5_detector.py index a54ce6e..a909a4d 100644 --- a/detector/yolov5_detector.py +++ b/detector/yolov5_detector.py @@ -140,7 +140,7 @@ def _create_engine(self, resolution: int, cat_count: int, wts_file: str) -> str: subprocess.run('make -j6 -Wno-deprecated-declarations', shell=True, check=True) - self.logself.log.warning('currently we assume a Yolov5 s6 model;\ + self.log.warning('currently we assume a Yolov5 s6 model;\ parameterization of the variant (s, s6, m, m6, ...) still needs to be done') # TODO parameterize variant "s6" subprocess.run( From 702c360d8aeb4578fe87519ad5509ee798bf6e65 Mon Sep 17 00:00:00 2001 From: "Dr. Dennis Wittich" Date: Thu, 10 Oct 2024 10:07:34 +0200 Subject: [PATCH 7/7] Update detector/yolov5_detector.py Co-authored-by: Niklas Neugebauer <68709968+NiklasNeugebauer@users.noreply.github.com> --- detector/yolov5_detector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detector/yolov5_detector.py b/detector/yolov5_detector.py index a909a4d..1038388 100644 --- a/detector/yolov5_detector.py +++ b/detector/yolov5_detector.py @@ -85,8 +85,8 @@ def evaluate(self, image: np.ndarray) -> Detections: BoxDetection(category_name=category.name, x=round(x), y=round(y), - width=round(w), - height=round(h), + width=round(x+w)-round(x), + height=round(y+h)-round(y), category_id=category.id, model_name=self.model_info.version, confidence=probability))