윤영준 윤영준 05-30
Fix - Major 1. A bug fix on inference_endpoint is not sending image when nothing is detected.
1. A bug fix on inference_endpoint is not sending image when nothing is detected.
@527ba548327d31500d7451c87f44cbcc355b7d43
inference_endpoint.py
--- inference_endpoint.py
+++ inference_endpoint.py
@@ -61,6 +61,7 @@
         self.mask = None
         self.mask_blob = None
         self.image = None
+        self.image_binary = None
         self.image_type = None
         self.seg_image = None
         self.flag_detected = False
@@ -81,7 +82,10 @@
         self.cctv_longitude = request.headers.get('x-cctv-longitude', 'Not provided')
 
         # timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
+
         image = self.image.read()
+        # self.image.seek(0)
+        self.image_binary = image
         image = np.frombuffer(image, np.uint8)
         image = cv2.imdecode(image, cv2.IMREAD_COLOR)
         # filename = f"{timestamp}_{self.cctv_name}.png"
@@ -136,7 +140,7 @@
                     fields={
                         'image': (
                             f'frame_{self.cctv_name}.{self.image_type}',
-                            self.image,
+                            self.image_binary,
                             f'image/{self.image_type}'
                         ),
                         'mask' : (
@@ -159,7 +163,7 @@
                     fields={
                         'image': (
                             f'frame_{self.cctv_name}.{self.image_type}',
-                            self.image,
+                            self.image_binary,
                             f'image/{self.image_type}'
                         ),
                     }
postprocess_draft.py
--- postprocess_draft.py
+++ postprocess_draft.py
@@ -148,6 +148,7 @@
             else :
                 self.sources[source]["last_send_before"] += 1
 
+        print(f"ok_counts : {self.sources[source]['ok_counts']}")
         if flag_send_event:
             self.sources[source]["most_recent_image"] = image
             self.sources[source]["most_recent_seg_image"] = seg_image
@@ -161,6 +162,7 @@
             self.sources[source]["normal_to_failure_mode_change_alert"] = False
 
     def send_event(self, source):
+        print(f"{source} is now sending data!")
         source_data = self.sources[source]
         try:
             # Connect to the database
@@ -283,9 +285,18 @@
                 raise ValueError(f"Invalid value for x-area-percentage: {self.area_percent}")
 
             # gathering files
-            self.image = request.files.get('image')
-            self.mask = request.files.get('mask')
-            self.seg_image = request.files.get('seg_mask')
+            try:
+                self.image = request.files.get('image')
+            except:
+                raise ValueError("Error reading 'image!'")
+
+            if self.detected:
+                try:
+                    self.mask = request.files.get('mask')
+                    self.seg_image = request.files.get('seg_mask')
+                except:
+                    raise ValueError("Error reading 'mask' and 'seg_mask'")
+
 
             if debug:
                 self.image.save(f"network_test/image_p{time.time()}.png")
Add a comment
List