mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 08:36:29 +00:00
fix inference status sending and logging
This commit is contained in:
@@ -37,6 +37,7 @@ cdef class Inference:
|
|||||||
cdef stop(self)
|
cdef stop(self)
|
||||||
|
|
||||||
cdef preprocess(self, frames)
|
cdef preprocess(self, frames)
|
||||||
|
cdef send_detection_status(self, client_id)
|
||||||
cdef remove_overlapping_detections(self, list[Detection] detections, float confidence_threshold=?)
|
cdef remove_overlapping_detections(self, list[Detection] detections, float confidence_threshold=?)
|
||||||
cdef postprocess(self, output, ai_config)
|
cdef postprocess(self, output, ai_config)
|
||||||
cdef split_list_extend(self, lst, chunk_size)
|
cdef split_list_extend(self, lst, chunk_size)
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ else:
|
|||||||
from onnx_engine import OnnxEngine
|
from onnx_engine import OnnxEngine
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cdef class Inference:
|
cdef class Inference:
|
||||||
def __init__(self, loader_client, remote_handler):
|
def __init__(self, loader_client, remote_handler):
|
||||||
self.loader_client = loader_client
|
self.loader_client = loader_client
|
||||||
@@ -295,10 +297,12 @@ cdef class Inference:
|
|||||||
batch_frames.clear()
|
batch_frames.clear()
|
||||||
batch_timestamps.clear()
|
batch_timestamps.clear()
|
||||||
v_input.release()
|
v_input.release()
|
||||||
|
self.send_detection_status(cmd.client_id)
|
||||||
|
|
||||||
cdef on_annotation(self, RemoteCommand cmd, Annotation annotation):
|
cdef on_annotation(self, RemoteCommand cmd, Annotation annotation):
|
||||||
cdef RemoteCommand response = RemoteCommand(CommandType.INFERENCE_DATA, annotation.serialize())
|
cdef RemoteCommand response = RemoteCommand(CommandType.INFERENCE_DATA, annotation.serialize())
|
||||||
self.remote_handler.send(cmd.client_id, response)
|
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 _process_images(self, RemoteCommand cmd, AIRecognitionConfig ai_config, list[str] image_paths):
|
||||||
cdef list frame_data
|
cdef list frame_data
|
||||||
@@ -319,10 +323,23 @@ cdef class Inference:
|
|||||||
if len(frame_data) > self.engine.get_batch_size():
|
if len(frame_data) > self.engine.get_batch_size():
|
||||||
for chunk in self.split_list_extend(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._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()):
|
for chunk in self.split_list_extend(frame_data, self.engine.get_batch_size()):
|
||||||
self._process_images_inner(cmd, ai_config, chunk)
|
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>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):
|
cdef split_to_tiles(self, frame, path, tile_size, overlap_percent):
|
||||||
constants_inf.log(<str>f'splitting image {path} to tiles...')
|
constants_inf.log(<str>f'splitting image {path} to tiles...')
|
||||||
@@ -369,18 +386,6 @@ cdef class Inference:
|
|||||||
_, image = cv2.imencode('.jpg', frames[i])
|
_, image = cv2.imencode('.jpg', frames[i])
|
||||||
annotation.image = image.tobytes()
|
annotation.image = image.tobytes()
|
||||||
self.on_annotation(cmd, annotation)
|
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>RemoteCommand(CommandType.INFERENCE_STATUS, msgpack.packb(status)))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
cdef stop(self):
|
cdef stop(self):
|
||||||
self.stop_signal = True
|
self.stop_signal = True
|
||||||
|
|||||||
Reference in New Issue
Block a user