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 class Annotation:
cdef public str name cdef public str name
cdef public str original_media_name cdef public str original_media_name
cdef public long time cdef long time
cdef public list[Detection] detections cdef public list[Detection] detections
cdef public bytes image cdef public bytes image
+1 -1
View File
@@ -18,4 +18,4 @@
{ "Id": 16, "Name": "Caponier", "ShortName": "Капонір", "Color": "#ffa500", "MaxSizeM": 10 }, { "Id": 16, "Name": "Caponier", "ShortName": "Капонір", "Color": "#ffa500", "MaxSizeM": 10 },
{ "Id": 17, "Name": "Ammo", "ShortName": "БК", "Color": "#33658a", "MaxSizeM": 2 }, { "Id": 17, "Name": "Ammo", "ShortName": "БК", "Color": "#33658a", "MaxSizeM": 2 },
{ "Id": 18, "Name": "Protect.Struct", "ShortName": "Зуби.драк", "Color": "#969647", "MaxSizeM": 2 } { "Id": 18, "Name": "Protect.Struct", "ShortName": "Зуби.драк", "Color": "#969647", "MaxSizeM": 2 }
] ]
+1 -1
View File
@@ -21,7 +21,7 @@ cdef log(str log_message)
cdef logerror(str error) cdef logerror(str error)
cdef format_time(int ms) cdef format_time(int ms)
cdef dict annotations_dict cdef dict[int, AnnotationClass] annotations_dict
cdef class AnnotationClass: cdef class AnnotationClass:
cdef public int id cdef public int id
-3
View File
@@ -70,9 +70,6 @@ logger.add(
colorize=True colorize=True
) )
def get_annotations_dict():
return annotations_dict
cdef log(str log_message): cdef log(str log_message):
logger.info(log_message) logger.info(log_message)
+1 -3
View File
@@ -264,9 +264,7 @@ cdef class Inference:
if frame is None: if frame is None:
raise ValueError("Invalid image data") raise ValueError("Invalid image data")
cdef int bs = self.engine.get_batch_size() input_blob = self.preprocess([frame])
frames = [frame] * bs
input_blob = self.preprocess(frames)
outputs = self.engine.run(input_blob) outputs = self.engine.run(input_blob)
list_detections = self.postprocess(outputs, ai_config) list_detections = self.postprocess(outputs, ai_config)
if list_detections: if list_detections:
+3 -8
View File
@@ -109,10 +109,9 @@ class AIConfigDto(BaseModel):
def detection_to_dto(det) -> DetectionDto: def detection_to_dto(det) -> DetectionDto:
import constants_inf import constants_inf
ann = constants_inf.get_annotations_dict()
label = "" label = ""
if det.cls in ann: if det.cls in constants_inf.annotations_dict:
label = ann[det.cls].name label = constants_inf.annotations_dict[det.cls].name
return DetectionDto( return DetectionDto(
centerX=det.x, centerX=det.x,
centerY=det.y, centerY=det.y,
@@ -178,14 +177,10 @@ def _post_annotation_to_service(token_mgr: TokenManager, media_id: str,
try: try:
token = token_mgr.get_valid_token() token = token_mgr.get_valid_token()
image_b64 = base64.b64encode(annotation.image).decode() if annotation.image else None 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 = { payload = {
"mediaId": media_id, "mediaId": media_id,
"source": 0, "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], "detections": [d.model_dump() for d in dtos],
} }
if image_b64: if image_b64: