mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 09:16:33 +00:00
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:
+1
-1
@@ -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
@@ -18,4 +18,4 @@
|
||||
{ "Id": 16, "Name": "Caponier", "ShortName": "Капонір", "Color": "#ffa500", "MaxSizeM": 10 },
|
||||
{ "Id": 17, "Name": "Ammo", "ShortName": "БК", "Color": "#33658a", "MaxSizeM": 2 },
|
||||
{ "Id": 18, "Name": "Protect.Struct", "ShortName": "Зуби.драк", "Color": "#969647", "MaxSizeM": 2 }
|
||||
]
|
||||
]
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user