fix inference

fix small issues
This commit is contained in:
Alex Bezdieniezhnykh
2025-02-14 09:00:04 +02:00
parent cfd5483a18
commit 961d2499de
15 changed files with 42 additions and 29 deletions
+1
View File
@@ -8,6 +8,7 @@ cdef class AIRecognitionConfig:
cdef public double tracking_intersection_threshold
cdef public bytes file_data
cdef public list[str] paths
@staticmethod
cdef from_msgpack(bytes data)
+10 -4
View File
@@ -10,7 +10,8 @@ cdef class AIRecognitionConfig:
tracking_probability_increase,
tracking_intersection_threshold,
file_data
file_data,
paths
):
self.frame_period_recognition = frame_period_recognition
self.frame_recognition_seconds = frame_recognition_seconds
@@ -21,10 +22,14 @@ cdef class AIRecognitionConfig:
self.tracking_intersection_threshold = tracking_intersection_threshold
self.file_data = file_data
self.paths = paths
def __str__(self):
return (f'frame_seconds : {self.frame_recognition_seconds}, distance_confidence : {self.tracking_distance_confidence}, '
f'probability_increase : {self.tracking_probability_increase}, intersection_threshold : {self.tracking_intersection_threshold}, frame_period_recognition : {self.frame_period_recognition}')
f'probability_increase : {self.tracking_probability_increase}, '
f'intersection_threshold : {self.tracking_intersection_threshold}, '
f'frame_period_recognition : {self.frame_period_recognition}, '
f'paths: {self.paths}')
@staticmethod
cdef from_msgpack(bytes data):
@@ -38,5 +43,6 @@ cdef class AIRecognitionConfig:
unpacked.get("TrackingProbabilityIncrease", 0.0),
unpacked.get("TrackingIntersectionThreshold", 0.0),
unpacked.get("Data", b''))
unpacked.get("Data", b''),
unpacked.get("Paths", []),
)
+1 -1
View File
@@ -12,7 +12,7 @@ cdef class ApiClient:
cdef set_token(self, str token)
cdef get_user(self)
cdef load_bytes(self, FileData file_data)
cdef load_bytes(self, str filename, str folder=*)
cdef load_ai_model(self)
cdef load_queue_config(self)
+4 -4
View File
@@ -60,8 +60,8 @@ cdef class ApiClient:
self.login()
return self.user
cdef load_bytes(self, FileData file_data):
folder = file_data.folder or self.credentials.folder
cdef load_bytes(self, str filename, str folder=None):
folder = folder or self.credentials.folder
hardware_service = HardwareService()
cdef HardwareInfo hardware = hardware_service.get_hardware_info()
@@ -78,7 +78,7 @@ cdef class ApiClient:
{
"password": self.credentials.password,
"hardware": hardware.to_json_object(),
"fileName": file_data.filename
"fileName": filename
}, indent=4)
response = requests.post(url, data=payload, headers=headers, stream=True)
@@ -97,7 +97,7 @@ cdef class ApiClient:
stream = BytesIO(response.raw.read())
data = Security.decrypt_to(stream, key)
print(f'loaded file: {file_data.filename}, {len(data)} bytes')
print(f'loaded file: {filename}, {len(data)} bytes')
return data
cdef load_ai_model(self):
+2 -3
View File
@@ -20,7 +20,7 @@ cdef class Inference:
self.model_width = 0
self.model_height = 0
self.class_names = None
self.ai_config = AIRecognitionConfig(4, 2, 0.25, 0.15, 15, 0.8, b'')
self.ai_config = AIRecognitionConfig(4, 2, 0.25, 0.15, 15, 0.8, b'', [])
def init_ai(self):
model_bytes = self.api_client.load_ai_model()
@@ -114,7 +114,6 @@ cdef class Inference:
return chunks
cdef run_inference(self, RemoteCommand cmd):
cdef list[str] medias = json.loads(<str> cmd.filename)
cdef list[str] videos = []
cdef list[str] images = []
@@ -123,7 +122,7 @@ cdef class Inference:
if self.session is None:
self.init_ai()
for m in medias:
for m in self.ai_config.paths:
if self.is_video(m):
videos.append(m)
else:
+2 -1
View File
@@ -66,7 +66,8 @@ cdef class CommandProcessor:
self.remote_handler.send(command.client_id, user.serialize())
cdef load_file(self, RemoteCommand command):
response = self.api_client.load_bytes(FileData.from_msgpack(command.data))
cdef FileData file_data = FileData.from_msgpack(command.data)
response = self.api_client.load_bytes(file_data.filename, file_data.folder)
self.remote_handler.send(command.client_id, response)
cdef on_annotation(self, RemoteCommand cmd, Annotation annotation):