From 9973a16ada72e5c684e81dba6ac7b85377270c43 Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Mon, 10 Feb 2025 18:02:44 +0200 Subject: [PATCH] print detection results --- Azaion.Inference/annotation.pxd | 1 + Azaion.Inference/annotation.pyx | 10 ++++++++++ Azaion.Inference/inference.pxd | 1 + Azaion.Inference/inference.pyx | 5 +++-- Azaion.Inference/token | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Azaion.Inference/token diff --git a/Azaion.Inference/annotation.pxd b/Azaion.Inference/annotation.pxd index b6c4c6b..e8af677 100644 --- a/Azaion.Inference/annotation.pxd +++ b/Azaion.Inference/annotation.pxd @@ -14,4 +14,5 @@ cdef class Annotation: cdef format_time(self, ms) cdef bytes serialize(self) + cdef to_str(self, class_names) diff --git a/Azaion.Inference/annotation.pyx b/Azaion.Inference/annotation.pyx index 3b91440..4614156 100644 --- a/Azaion.Inference/annotation.pyx +++ b/Azaion.Inference/annotation.pyx @@ -32,6 +32,16 @@ cdef class Annotation: d.annotation_name = self.name self.image = b'' + cdef to_str(self, class_names): + if not self.detections: + return f"{self.name}: No detections" + + detections_str = ", ".join( + f"{class_names[d.cls]} {d.confidence * 100:.1f}% ({d.x:.2f}, {d.y:.2f})" + for d in self.detections + ) + return f"{self.name}: {detections_str}" + cdef format_time(self, ms): # Calculate hours, minutes, seconds, and hundreds of milliseconds. h = ms // 3600000 # Total full hours. diff --git a/Azaion.Inference/inference.pxd b/Azaion.Inference/inference.pxd index 21a3c82..fad6182 100644 --- a/Azaion.Inference/inference.pxd +++ b/Azaion.Inference/inference.pxd @@ -7,6 +7,7 @@ cdef class Inference: cdef object on_annotation cdef Annotation _previous_annotation cdef AIRecognitionConfig ai_config + cdef object class_names cdef bint stop_signal cdef str model_input diff --git a/Azaion.Inference/inference.pyx b/Azaion.Inference/inference.pyx index fe0c696..bd94495 100644 --- a/Azaion.Inference/inference.pyx +++ b/Azaion.Inference/inference.pyx @@ -26,6 +26,7 @@ cdef class Inference: print(f'AI detection model input: {self.model_input} ({self.model_width}, {self.model_height})') model_meta = self.session.get_modelmeta() print("Metadata:", model_meta.custom_metadata_map) + self.class_names = eval(model_meta.custom_metadata_map["names"]) cdef preprocess(self, frames): blobs = [cv2.dnn.blobFromImage(frame, @@ -75,11 +76,9 @@ cdef class Inference: if det1_index in filtered_out_indexes: continue det1 = detections[det1_index] - print(f'det1 size: {det1.w}, {det1.h}') res = det1_index for det2_index in range(det1_index + 1, len(detections)): det2 = detections[det2_index] - print(f'det2 size: {det2.w}, {det2.h}') if det1.overlaps(det2): if det1.confidence > det2.confidence or ( det1.confidence == det2.confidence and det1.cls < det2.cls): # det1 has higher confidence or lower class_id @@ -158,6 +157,7 @@ cdef class Inference: if self.is_valid_annotation(annotation): _, image = cv2.imencode('.jpg', frame) annotation.image = image.tobytes() + print(annotation.to_str(self.class_names)) self.on_annotation(cmd, annotation) self._previous_annotation = annotation @@ -183,6 +183,7 @@ cdef class Inference: annotation = Annotation(image_paths[i], timestamps[i], detections) _, image = cv2.imencode('.jpg', frames[i]) annotation.image = image.tobytes() + print(annotation.to_str(self.class_names)) self.on_annotation(cmd, annotation) diff --git a/Azaion.Inference/token b/Azaion.Inference/token new file mode 100644 index 0000000..6e6d30b --- /dev/null +++ b/Azaion.Inference/token @@ -0,0 +1 @@ +eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI5N2U5MWI2OC1hNmRlLTQ3YTgtOTgzYi0xOTU3YzViNDQ2MTkiLCJ1bmlxdWVfbmFtZSI6ImFkbWluLXJlbW90ZUBhemFpb24uY29tIiwicm9sZSI6IkFwaUFkbWluIiwibmJmIjoxNzM5MTk5MzM1LCJleHAiOjE3MzkyMTM3MzUsImlhdCI6MTczOTE5OTMzNSwiaXNzIjoiQXphaW9uQXBpIiwiYXVkIjoiQW5ub3RhdG9ycy9PcmFuZ2VQaS9BZG1pbnMifQ.HmfaeFn9T_eJuRZSjBV_EhiSB41ippBVPLRggC7gBZk \ No newline at end of file