윤영준 윤영준 05-23
inference result sending fix
exception handling when there is no mask
@dd791b5cd9c9458c00fa6fb59e296e152f32c1fe
inference_endpoint.py
--- inference_endpoint.py
+++ inference_endpoint.py
@@ -6,6 +6,7 @@
 from yoloseg.inference_ import Inference, overlay_mask
 import cv2
 import time
+from zoneinfo import ZoneInfo
 import base64
 import requests
 from requests_toolbelt import MultipartEncoder
@@ -59,6 +60,7 @@
         self.image_type = None
         self.seg_image = None
         self.area_percent = 0
+        self.time_zone = self.time_zone = ZoneInfo("Asia/Seoul")
 
     @ns.response(200, 'Success')
     @ns.response(400, 'Validation Error')
@@ -83,9 +85,10 @@
 
         t2 = time.time()
         if len(self.mask) > 0:
+            self.mask = cv2.resize(self.mask, (image.shape[0], image.shape[1]))
             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)
 
@@ -95,7 +98,7 @@
         else :
             self.area_percent = np.sum(self.mask) / image.shape[0] * image.shape[1]
 
-        # self.send_result()
+        self.send_result()
         # write another post request for pushing a detection result
         return {"message": f"Image {self.mask} uploaded successfully!"}
 
@@ -110,27 +113,44 @@
             'x-area-percentage' : str(self.area_percent),
         }
         session = requests.Session()
-
+        seg_binary = cv2.imencode('.png', self.seg_image)
+        seg_binary = seg_binary[1].tobytes()
+        print(type(self.seg_image))
+        print(type(self.mask))
+        print(type(self.image))
         try:
-            multipart_data = MultipartEncoder(
-                fields={
-                    'image': (
-                        f'frame_{self.cctv_name}.{self.image_type}',
-                        self.image,
-                        f'image/{self.image_type}'
-                    ),
-                    'mask' : (
-                        f'frame_mask_{self.cctv_name}.{self.image_type}',
-                        self.mask_blob,
-                        f'image/{self.image_type}'
-                    ),
-                    'seg_mask' : (
-                        f'frame_seg_{self.cctv_name}.{self.image_type}',
-                        self.seg_image,
-                        f'image/{self.image_type}'
-                    )
-                }
-            )
+            if len(self.mask) != 0:
+                multipart_data = MultipartEncoder(
+                    fields={
+                        'image': (
+                            f'frame_{self.cctv_name}.{self.image_type}',
+                            self.image,
+                            f'image/{self.image_type}'
+                        ),
+                        'mask' : (
+                            f'frame_mask_{self.cctv_name}.{self.image_type}',
+                            self.mask_blob,
+                            f'image/{self.image_type}'
+                        ),
+                        'seg_mask' : (
+                            f'frame_seg_{self.cctv_name}.{self.image_type}',
+                            seg_binary,
+                            f'image/{self.image_type}'
+                        )
+                    }
+                )
+                header["Content-Type"] = multipart_data.content_type
+                response = session.post(self.endpoint, headers=header, data=multipart_data)
+            else:
+                multipart_data = MultipartEncoder(
+                    fields={
+                        'image': (
+                            f'frame_{self.cctv_name}.{self.image_type}',
+                            self.image,
+                            f'image/{self.image_type}'
+                        ),
+                    }
+                )
             header["Content-Type"] = multipart_data.content_type
             response = session.post(self.endpoint, headers=header, data=multipart_data)
 
yoloseg/inference_.py
--- yoloseg/inference_.py
+++ yoloseg/inference_.py
@@ -59,8 +59,8 @@
             confidence = scores_classification[class_id]
 
             thres = self.model_score_threshold
-            w_thres = 20
-            h_thres = 20
+            w_thres = 40
+            h_thres = 40
 
             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
Add a comment
List