From 2e178c29f8713146f907a63f11bbc06ba4a04b8d Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 4 Aug 2023 15:11:39 +0300 Subject: [PATCH 1/4] added bbox border check --- serve/serve/src/main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/serve/serve/src/main.py b/serve/serve/src/main.py index 807dc47..2eb5452 100644 --- a/serve/serve/src/main.py +++ b/serve/serve/src/main.py @@ -31,9 +31,7 @@ def load_on_device( name = F.SupportedModels.instance_by_name(NAME) self.model = F.Tracker(name) - def initialize( - self, init_rgb_image: np.ndarray, target_bbox: PredictionBBox - ) -> None: + def initialize(self, init_rgb_image: np.ndarray, target_bbox: PredictionBBox) -> None: y1, x1, y2, x2 = target_bbox.bbox_tlbr w = abs(x2 - x1) h = abs(y2 - y1) @@ -48,9 +46,19 @@ def predict( ) -> PredictionBBox: class_name = target_bbox.class_name x, y, w, h = self.model.track(rgb_image) - tlbr = [int(y), int(x), int(y + h), int(x + w)] + # tlbr = [int(y), int(x), int(y + h), int(x + w)] + max_h, max_w = rgb_image.shape + tlbr = self._build_bbox_params(x, y, w, h, max_w, max_h) return PredictionBBox(class_name, tlbr, None) + def _build_bbox_params(x: float, y: float, w: float, h: float, max_w: int, max_h: int): + sly.logger.debug(f"Image height={max_h}, width={max_w}") + top = min(max(0, int(y)), max_h - 1) + left = min(max(0, int(x)), max_w - 1) + bottom = min(max(0, int(y + h)), max_h - 1) + right = min(max(0, int(x + w)), max_w - 1) + return [top, left, bottom, right] + if sly.is_debug_with_sly_net() or not sly.is_production(): create_default_local_file_ITP_test(str(root), "", str(root / "save")) @@ -72,7 +80,7 @@ def predict( imgs_names = sorted(os.listdir(img_path)) start, end = 80, 180 - imgs_pth = [img_path / name for name in imgs_names[start:end] if 'jpg' in name] + imgs_pth = [img_path / name for name in imgs_names[start:end] if "jpg" in name] # top left bottom right order start_object = PredictionBBox("", [187, 244, 236, 365], None) From 426f3e6a8e6cef9838df27a9f52fb95f46009fc0 Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 4 Aug 2023 15:25:36 +0300 Subject: [PATCH 2/4] fix shape def --- serve/serve/src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serve/serve/src/main.py b/serve/serve/src/main.py index 2eb5452..b78bf6c 100644 --- a/serve/serve/src/main.py +++ b/serve/serve/src/main.py @@ -47,7 +47,7 @@ def predict( class_name = target_bbox.class_name x, y, w, h = self.model.track(rgb_image) # tlbr = [int(y), int(x), int(y + h), int(x + w)] - max_h, max_w = rgb_image.shape + max_h, max_w, _ = rgb_image.shape tlbr = self._build_bbox_params(x, y, w, h, max_w, max_h) return PredictionBBox(class_name, tlbr, None) From eba704469a964c787d5b835e3d6da593aef99c55 Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 4 Aug 2023 15:29:57 +0300 Subject: [PATCH 3/4] added self --- serve/serve/src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serve/serve/src/main.py b/serve/serve/src/main.py index b78bf6c..3c2576b 100644 --- a/serve/serve/src/main.py +++ b/serve/serve/src/main.py @@ -51,7 +51,7 @@ def predict( tlbr = self._build_bbox_params(x, y, w, h, max_w, max_h) return PredictionBBox(class_name, tlbr, None) - def _build_bbox_params(x: float, y: float, w: float, h: float, max_w: int, max_h: int): + def _build_bbox_params(self, x: float, y: float, w: float, h: float, max_w: int, max_h: int): sly.logger.debug(f"Image height={max_h}, width={max_w}") top = min(max(0, int(y)), max_h - 1) left = min(max(0, int(x)), max_w - 1) From 5b92c40df06b8f5b7f4ac4fd034ec014897cedbb Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 4 Aug 2023 16:59:03 +0300 Subject: [PATCH 4/4] rm comments --- serve/serve/src/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/serve/serve/src/main.py b/serve/serve/src/main.py index 3c2576b..f3b7174 100644 --- a/serve/serve/src/main.py +++ b/serve/serve/src/main.py @@ -46,13 +46,11 @@ def predict( ) -> PredictionBBox: class_name = target_bbox.class_name x, y, w, h = self.model.track(rgb_image) - # tlbr = [int(y), int(x), int(y + h), int(x + w)] max_h, max_w, _ = rgb_image.shape tlbr = self._build_bbox_params(x, y, w, h, max_w, max_h) return PredictionBBox(class_name, tlbr, None) def _build_bbox_params(self, x: float, y: float, w: float, h: float, max_w: int, max_h: int): - sly.logger.debug(f"Image height={max_h}, width={max_w}") top = min(max(0, int(y)), max_h - 1) left = min(max(0, int(x)), max_w - 1) bottom = min(max(0, int(y + h)), max_h - 1)