From 053719c4a830a20c114dafc50e862e2d569014ff Mon Sep 17 00:00:00 2001 From: Oleksandr Bezdieniezhnykh Date: Sat, 6 Sep 2025 00:44:08 +0300 Subject: [PATCH] fix inference status sending and logging --- Azaion.Inference/inference.pxd | 1 + Azaion.Inference/inference.pyx | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Azaion.Inference/inference.pxd b/Azaion.Inference/inference.pxd index 9515b42..bfd4ba8 100644 --- a/Azaion.Inference/inference.pxd +++ b/Azaion.Inference/inference.pxd @@ -37,6 +37,7 @@ cdef class Inference: cdef stop(self) cdef preprocess(self, frames) + cdef send_detection_status(self, client_id) cdef remove_overlapping_detections(self, list[Detection] detections, float confidence_threshold=?) cdef postprocess(self, output, ai_config) cdef split_list_extend(self, lst, chunk_size) diff --git a/Azaion.Inference/inference.pyx b/Azaion.Inference/inference.pyx index 15cc569..3f39b9c 100644 --- a/Azaion.Inference/inference.pyx +++ b/Azaion.Inference/inference.pyx @@ -51,6 +51,8 @@ else: from onnx_engine import OnnxEngine + + cdef class Inference: def __init__(self, loader_client, remote_handler): self.loader_client = loader_client @@ -295,10 +297,12 @@ cdef class Inference: batch_frames.clear() batch_timestamps.clear() v_input.release() + self.send_detection_status(cmd.client_id) cdef on_annotation(self, RemoteCommand cmd, Annotation annotation): cdef RemoteCommand response = RemoteCommand(CommandType.INFERENCE_DATA, annotation.serialize()) self.remote_handler.send(cmd.client_id, response) + self.detection_counts[annotation.original_media_name] = self.detection_counts.get(annotation.original_media_name, 0) + 1 cdef _process_images(self, RemoteCommand cmd, AIRecognitionConfig ai_config, list[str] image_paths): cdef list frame_data @@ -319,10 +323,23 @@ cdef class Inference: if len(frame_data) > self.engine.get_batch_size(): for chunk in self.split_list_extend(frame_data, self.engine.get_batch_size()): self._process_images_inner(cmd, ai_config, chunk) + self.send_detection_status(cmd.client_id) for chunk in self.split_list_extend(frame_data, self.engine.get_batch_size()): self._process_images_inner(cmd, ai_config, chunk) + self.send_detection_status(cmd.client_id) + cdef send_detection_status(self, client_id): + for media_name in self.detection_counts.keys(): + try: + status = { + "mn": media_name, + "dc": self.detection_counts[media_name] + } + self.remote_handler.send(client_id, RemoteCommand(CommandType.INFERENCE_STATUS, msgpack.packb(status))) + except Exception: + pass + self.detection_counts.clear() cdef split_to_tiles(self, frame, path, tile_size, overlap_percent): constants_inf.log(f'splitting image {path} to tiles...') @@ -369,18 +386,6 @@ cdef class Inference: _, image = cv2.imencode('.jpg', frames[i]) annotation.image = image.tobytes() self.on_annotation(cmd, annotation) - self.detection_counts[original_media_names[i]] = self.detection_counts.get(original_media_names[i], 0) + 1 - - # Send detecting status for each original media name - for media_name in self.detection_counts.keys(): - try: - status = { - "mn": media_name, - "dc": self.detection_counts[media_name] - } - self.remote_handler.send(cmd.client_id, RemoteCommand(CommandType.INFERENCE_STATUS, msgpack.packb(status))) - except Exception: - pass cdef stop(self): self.stop_signal = True