Errors sending to UI

notifying client of AI model conversion
This commit is contained in:
dzaitsev
2025-05-07 17:32:29 +03:00
committed by Alex Bezdieniezhnykh
42 changed files with 630 additions and 363 deletions
+16 -13
View File
@@ -32,7 +32,7 @@ cdef class Inference:
self.engine = None
self.is_building_engine = False
cdef build_tensor_engine(self):
cdef build_tensor_engine(self, object updater_callback):
is_nvidia = HardwareService.has_nvidia_gpu()
if not is_nvidia:
return
@@ -40,18 +40,22 @@ cdef class Inference:
engine_filename = TensorRTEngine.get_engine_filename(0)
key = Security.get_model_encryption_key()
models_dir = constants.MODELS_FOLDER
if not os.path.exists(os.path.join(<str> models_dir, f'{engine_filename}.big')):
#TODO: Check cdn on engine exists, if there is, download
self.is_building_engine = True
time.sleep(8) # prevent simultaneously loading dll and models
onnx_model = self.api_client.load_big_small_resource(constants.AI_ONNX_MODEL_FILE, models_dir, key)
model_bytes = TensorRTEngine.convert_from_onnx(onnx_model)
self.api_client.upload_big_small_resource(model_bytes, <str> engine_filename, models_dir, key)
print('uploaded ')
self.is_building_engine = False
else:
print('tensor rt engine is here, no need to build')
self.is_building_engine = True
updater_callback('downloading')
if self.api_client.load_big_small_resource(engine_filename, models_dir, key):
print('tensor rt engine is here, no need to build')
self.is_building_engine = False
return
# time.sleep(8) # prevent simultaneously loading dll and models
updater_callback('converting')
onnx_model = self.api_client.load_big_small_resource(constants.AI_ONNX_MODEL_FILE, models_dir, key)
model_bytes = TensorRTEngine.convert_from_onnx(onnx_model)
updater_callback('uploading')
self.api_client.upload_big_small_resource(model_bytes, <str> engine_filename, models_dir, key)
print(f'uploaded {engine_filename} to CDN and API')
self.is_building_engine = False
cdef init_ai(self):
if self.engine is not None:
@@ -161,7 +165,6 @@ cdef class Inference:
self.stop_signal = False
self.init_ai()
print(ai_config.paths)
for m in ai_config.paths:
if self.is_video(m):
videos.append(m)