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
... | ... | @@ -61,6 +61,7 @@ |
61 | 61 |
self.mask = None |
62 | 62 |
self.mask_blob = None |
63 | 63 |
self.image = None |
64 |
+ self.image_binary = None |
|
64 | 65 |
self.image_type = None |
65 | 66 |
self.seg_image = None |
66 | 67 |
self.flag_detected = False |
... | ... | @@ -81,7 +82,10 @@ |
81 | 82 |
self.cctv_longitude = request.headers.get('x-cctv-longitude', 'Not provided') |
82 | 83 |
|
83 | 84 |
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
85 |
+ |
|
84 | 86 |
image = self.image.read() |
87 |
+ # self.image.seek(0) |
|
88 |
+ self.image_binary = image |
|
85 | 89 |
image = np.frombuffer(image, np.uint8) |
86 | 90 |
image = cv2.imdecode(image, cv2.IMREAD_COLOR) |
87 | 91 |
# filename = f"{timestamp}_{self.cctv_name}.png" |
... | ... | @@ -136,7 +140,7 @@ |
136 | 140 |
fields={ |
137 | 141 |
'image': ( |
138 | 142 |
f'frame_{self.cctv_name}.{self.image_type}', |
139 |
- self.image, |
|
143 |
+ self.image_binary, |
|
140 | 144 |
f'image/{self.image_type}' |
141 | 145 |
), |
142 | 146 |
'mask' : ( |
... | ... | @@ -159,7 +163,7 @@ |
159 | 163 |
fields={ |
160 | 164 |
'image': ( |
161 | 165 |
f'frame_{self.cctv_name}.{self.image_type}', |
162 |
- self.image, |
|
166 |
+ self.image_binary, |
|
163 | 167 |
f'image/{self.image_type}' |
164 | 168 |
), |
165 | 169 |
} |
--- postprocess_draft.py
+++ postprocess_draft.py
... | ... | @@ -148,6 +148,7 @@ |
148 | 148 |
else : |
149 | 149 |
self.sources[source]["last_send_before"] += 1 |
150 | 150 |
|
151 |
+ print(f"ok_counts : {self.sources[source]['ok_counts']}") |
|
151 | 152 |
if flag_send_event: |
152 | 153 |
self.sources[source]["most_recent_image"] = image |
153 | 154 |
self.sources[source]["most_recent_seg_image"] = seg_image |
... | ... | @@ -161,6 +162,7 @@ |
161 | 162 |
self.sources[source]["normal_to_failure_mode_change_alert"] = False |
162 | 163 |
|
163 | 164 |
def send_event(self, source): |
165 |
+ print(f"{source} is now sending data!") |
|
164 | 166 |
source_data = self.sources[source] |
165 | 167 |
try: |
166 | 168 |
# Connect to the database |
... | ... | @@ -283,9 +285,18 @@ |
283 | 285 |
raise ValueError(f"Invalid value for x-area-percentage: {self.area_percent}") |
284 | 286 |
|
285 | 287 |
# gathering files |
286 |
- self.image = request.files.get('image') |
|
287 |
- self.mask = request.files.get('mask') |
|
288 |
- self.seg_image = request.files.get('seg_mask') |
|
288 |
+ try: |
|
289 |
+ self.image = request.files.get('image') |
|
290 |
+ except: |
|
291 |
+ raise ValueError("Error reading 'image!'") |
|
292 |
+ |
|
293 |
+ if self.detected: |
|
294 |
+ try: |
|
295 |
+ self.mask = request.files.get('mask') |
|
296 |
+ self.seg_image = request.files.get('seg_mask') |
|
297 |
+ except: |
|
298 |
+ raise ValueError("Error reading 'mask' and 'seg_mask'") |
|
299 |
+ |
|
289 | 300 |
|
290 | 301 |
if debug: |
291 | 302 |
self.image.save(f"network_test/image_p{time.time()}.png") |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?