윤영준 윤영준 05-21
fixing a critical bug
@6657e94befd3a8657cd7f4571d39824617925c07
inference_endpoint.py
--- inference_endpoint.py
+++ inference_endpoint.py
@@ -79,12 +79,14 @@
 
         t1 = time.time()
         detections, self.mask = inference_engine.run_inference(cv2.resize(image, model_input_shape))
+
         t2 = time.time()
         if len(self.mask) > 0:
             print(self.mask.shape)
+            print(type(self.mask))
             self.mask_blob = cv2.imencode('.png', self.mask)
             self.mask_blob = self.mask.tobytes()
-
+            self.mask = cv2.resize(self.mask, (image.shape[0], image.shape[1]))
 
         # print(t2 - t1)
 
@@ -93,8 +95,6 @@
             self.area_percent = 0
         else :
             self.area_percent = np.sum(self.mask) / image.shape[0] * image.shape[1]
-
-
 
         # self.send_result()
         # write another post request for pushing a detection result
yoloseg/inference_.py
--- yoloseg/inference_.py
+++ yoloseg/inference_.py
@@ -60,11 +60,14 @@
             thres = self.model_score_threshold
             w_thres = 20
             h_thres = 20
+
+            x, y, w, h = detection[:4]
+            # if bboxes are too small, it just skips, and it is not a bad idea since we do not need to detect small areas
+            if w < w_thres or h < h_thres:
+                continue
+
             if confidence > thres:
-                x, y, w, h = detection[:4]
-                # if bboxes are too small, it just skips, and it is not a bad idea since we do not need to detect small areas
-                if w < w_thres or h < h_thres:
-                    continue
+
                 left = int((x - 0.5 * w) * x_factor)
                 top = int((y - 0.5 * h) * y_factor)
                 width = int(w * x_factor)
@@ -102,7 +105,7 @@
         for idx, det in enumerate(detections):
             box = det['box']
             x1, y1, w, h = box
-            print(f"x1 : {x1}, y1 : {y1}, w: {w}, h: {h}")
+            # print(f"x1 : {x1}, y1 : {y1}, w: {w}, h: {h}")
 
             x1, y1, x2, y2 = x1, y1, x1 + w, y1 + h
 
@@ -120,7 +123,7 @@
             if x2 > image_shape[0]:
                 w = image_shape[1] - y1
 
-            print(f"x2: {x2}, y2 : {y2}")
+            # print(f"x2: {x2}, y2 : {y2}")
 
             # Get the corresponding mask coefficients for this detection
             coeffs = det["mask_coefficients"]
@@ -149,7 +152,9 @@
             # Combine the mask with the masks of other detections
             full_masks[idx] = full_mask
         all_mask = full_masks.sum(axis=0)
-        return all_mask
+        # Append a dimension so that cv2 can understand this as an image.
+        all_mask = all_mask.reshape((image_shape[0], image_shape[1], 1))
+        return all_mask.astype(np.uint8)
 
     def load_classes_from_file(self):
         with open(self.classes_path, 'r') as f:
Add a comment
List