Refactor annotation handling and inference processing: Update 'time' attribute in Annotation class to private, streamline video time formatting in main processing function, and adjust annotations dictionary access in detection conversion. Ensure consistency in handling input frames during inference.

This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-03-26 00:40:02 +02:00
parent 4afa1a4eec
commit 1e4ef299f9
6 changed files with 7 additions and 17 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ cdef class Detection:
cdef class Annotation:
cdef public str name
cdef public str original_media_name
cdef public long time
cdef long time
cdef public list[Detection] detections
cdef public bytes image
+1 -1
View File
@@ -21,7 +21,7 @@ cdef log(str log_message)
cdef logerror(str error)
cdef format_time(int ms)
cdef dict annotations_dict
cdef dict[int, AnnotationClass] annotations_dict
cdef class AnnotationClass:
cdef public int id
-3
View File
@@ -70,9 +70,6 @@ logger.add(
colorize=True
)
def get_annotations_dict():
return annotations_dict
cdef log(str log_message):
logger.info(log_message)
+1 -3
View File
@@ -264,9 +264,7 @@ cdef class Inference:
if frame is None:
raise ValueError("Invalid image data")
cdef int bs = self.engine.get_batch_size()
frames = [frame] * bs
input_blob = self.preprocess(frames)
input_blob = self.preprocess([frame])
outputs = self.engine.run(input_blob)
list_detections = self.postprocess(outputs, ai_config)
if list_detections:
+3 -8
View File
@@ -109,10 +109,9 @@ class AIConfigDto(BaseModel):
def detection_to_dto(det) -> DetectionDto:
import constants_inf
ann = constants_inf.get_annotations_dict()
label = ""
if det.cls in ann:
label = ann[det.cls].name
if det.cls in constants_inf.annotations_dict:
label = constants_inf.annotations_dict[det.cls].name
return DetectionDto(
centerX=det.x,
centerY=det.y,
@@ -178,14 +177,10 @@ def _post_annotation_to_service(token_mgr: TokenManager, media_id: str,
try:
token = token_mgr.get_valid_token()
image_b64 = base64.b64encode(annotation.image).decode() if annotation.image else None
total_seconds = annotation.time // 1000 if annotation.time else 0
hours = total_seconds // 3600
minutes = (total_seconds % 3600) // 60
seconds = total_seconds % 60
payload = {
"mediaId": media_id,
"source": 0,
"videoTime": f"{hours:02d}:{minutes:02d}:{seconds:02d}",
"videoTime": f"00:00:{annotation.time // 1000:02d}" if annotation.time else "00:00:00",
"detections": [d.model_dump() for d in dtos],
}
if image_b64: