fixed console Log

fix same files problem in python different libs
correct command logging in command handler
This commit is contained in:
Alex Bezdieniezhnykh
2025-06-14 21:01:32 +03:00
parent 09cfcdf61a
commit c0f8dd792d
29 changed files with 74 additions and 87 deletions
+16 -16
View File
@@ -2,8 +2,8 @@ import mimetypes
import time
import cv2
import numpy as np
cimport constants
from remote_command cimport RemoteCommand
cimport constants_inf
from remote_command_inf cimport RemoteCommand
from annotation cimport Detection, Annotation
from ai_config cimport AIRecognitionConfig
import pynvml
@@ -16,7 +16,7 @@ cdef int check_tensor_gpu_index():
deviceCount = pynvml.nvmlDeviceGetCount()
if deviceCount == 0:
constants.logerror('No NVIDIA GPUs found.')
constants_inf.logerror('No NVIDIA GPUs found.')
return -1
for i in range(deviceCount):
@@ -24,10 +24,10 @@ cdef int check_tensor_gpu_index():
major, minor = pynvml.nvmlDeviceGetCudaComputeCapability(handle)
if major > 6 or (major == 6 and minor >= 1):
constants.log('found NVIDIA GPU!')
constants_inf.log('found NVIDIA GPU!')
return i
constants.logerror('NVIDIA GPU doesnt support TensorRT!')
constants_inf.logerror('NVIDIA GPU doesnt support TensorRT!')
return -1
except pynvml.NVMLError:
@@ -36,7 +36,7 @@ cdef int check_tensor_gpu_index():
try:
pynvml.nvmlShutdown()
except:
constants.logerror('Failed to shutdown pynvml cause probably no NVIDIA GPU')
constants_inf.logerror('Failed to shutdown pynvml cause probably no NVIDIA GPU')
pass
tensor_gpu_index = check_tensor_gpu_index()
@@ -63,23 +63,23 @@ cdef class Inference:
try:
engine_filename = TensorRTEngine.get_engine_filename(0)
models_dir = constants.MODELS_FOLDER
models_dir = constants_inf.MODELS_FOLDER
self.is_building_engine = True
updater_callback('downloading')
res = self.loader_client.load_big_small_resource(engine_filename, models_dir)
if res.err is None:
constants.log('tensor rt engine is here, no need to build')
constants_inf.log('tensor rt engine is here, no need to build')
self.is_building_engine = False
updater_callback('enabled')
return
constants.logerror(res.err)
constants_inf.logerror(res.err)
# time.sleep(8) # prevent simultaneously loading dll and models
updater_callback('converting')
constants.log('try to load onnx')
res = self.loader_client.load_big_small_resource(constants.AI_ONNX_MODEL_FILE, models_dir)
constants_inf.log('try to load onnx')
res = self.loader_client.load_big_small_resource(constants_inf.AI_ONNX_MODEL_FILE, models_dir)
if res.err is not None:
updater_callback(f'Error. {res.err}')
model_bytes = TensorRTEngine.convert_from_onnx(res.data)
@@ -87,7 +87,7 @@ cdef class Inference:
res = self.loader_client.upload_big_small_resource(model_bytes, <str> engine_filename, models_dir)
if res.err is not None:
updater_callback(f'Error. {res.err}')
constants.log(f'uploaded {engine_filename} to CDN and API')
constants_inf.log(f'uploaded {engine_filename} to CDN and API')
self.is_building_engine = False
updater_callback('enabled')
except Exception as e:
@@ -97,7 +97,7 @@ cdef class Inference:
if self.engine is not None:
return
models_dir = constants.MODELS_FOLDER
models_dir = constants_inf.MODELS_FOLDER
if tensor_gpu_index > -1:
while self.is_building_engine:
time.sleep(1)
@@ -108,7 +108,7 @@ cdef class Inference:
raise Exception(res.err)
self.engine = TensorRTEngine(res.data)
else:
res = self.loader_client.load_big_small_resource(constants.AI_ONNX_MODEL_FILE, models_dir)
res = self.loader_client.load_big_small_resource(constants_inf.AI_ONNX_MODEL_FILE, models_dir)
if res.err is not None:
raise Exception(res.err)
self.engine = OnnxEngine(res.data)
@@ -212,11 +212,11 @@ cdef class Inference:
# images first, it's faster
if len(images) > 0:
for chunk in self.split_list_extend(images, self.engine.get_batch_size()):
constants.log(f'run inference on {" ".join(chunk)}...')
constants_inf.log(f'run inference on {" ".join(chunk)}...')
self._process_images(cmd, ai_config, chunk)
if len(videos) > 0:
for v in videos:
constants.log(f'run inference on {v}...')
constants_inf.log(f'run inference on {v}...')
self._process_video(cmd, ai_config, v)