mirror of
https://github.com/azaion/detections.git
synced 2026-06-23 17:01:08 +00:00
[AZ-180] Refactor inference and engine factory for improved model handling
- Updated the autopilot state to reflect the current task status as in progress. - Refactored the inference module to streamline model downloading and conversion processes, replacing the download_model method with a more efficient load_source method. - Introduced asynchronous model building in the inference module to enhance performance during model conversion. - Enhanced the engine factory to include a new method for building and caching models, improving error handling and logging during the upload process. - Added calibration cache handling in the Jetson TensorRT engine for better resource management. Made-with: Cursor
This commit is contained in:
@@ -1,5 +1,39 @@
|
||||
import os
|
||||
import tempfile
|
||||
from engines.tensorrt_engine cimport TensorRTEngine
|
||||
from loader_http_client cimport LoaderHttpClient, LoadResult
|
||||
|
||||
|
||||
cdef class JetsonTensorRTEngine(TensorRTEngine):
|
||||
pass
|
||||
@staticmethod
|
||||
def convert_from_source(bytes onnx_model, LoaderHttpClient loader_client, str models_dir):
|
||||
cdef str calib_cache_path
|
||||
calib_cache_path = JetsonTensorRTEngine._download_calib_cache(loader_client, models_dir)
|
||||
try:
|
||||
return TensorRTEngine.convert_from_source(onnx_model, calib_cache_path)
|
||||
finally:
|
||||
if calib_cache_path is not None:
|
||||
try:
|
||||
os.unlink(calib_cache_path)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _download_calib_cache(LoaderHttpClient loader_client, str models_dir):
|
||||
cdef LoadResult res
|
||||
import constants_inf
|
||||
try:
|
||||
res = loader_client.load_big_small_resource(
|
||||
constants_inf.INT8_CALIB_CACHE_FILE, models_dir
|
||||
)
|
||||
if res.err is not None:
|
||||
constants_inf.log(f"INT8 calibration cache not available: {res.err}")
|
||||
return None
|
||||
fd, path = tempfile.mkstemp(suffix=".cache")
|
||||
with os.fdopen(fd, "wb") as f:
|
||||
f.write(res.data)
|
||||
constants_inf.log("INT8 calibration cache downloaded")
|
||||
return path
|
||||
except Exception as e:
|
||||
constants_inf.log(f"INT8 calibration cache download failed: {str(e)}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user