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
+1 -1
View File
@@ -4,7 +4,7 @@ from PyInstaller.utils.hooks import collect_all
datas = [('venv\\Lib\\site-packages\\cv2', 'cv2')]
binaries = []
hiddenimports = ['constants', 'file_data', 'remote_command', 'remote_command_handler', 'annotation', 'loader_client', 'ai_config', 'tensorrt_engine', 'onnx_engine', 'inference_engine', 'inference', 'main-inf']
hiddenimports = ['constants_inf', 'file_data', 'remote_command_inf', 'remote_command_handler_inf', 'annotation', 'loader_client', 'ai_config', 'tensorrt_engine', 'onnx_engine', 'inference_engine', 'inference', 'main-inf']
hiddenimports += collect_submodules('cv2')
tmp_ret = collect_all('psutil')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
+5 -5
View File
@@ -34,10 +34,10 @@ venv\Scripts\pyinstaller --name=azaion-inference ^
--collect-all pynvml ^
--collect-all jwt ^
--collect-all loguru ^
--hidden-import constants ^
--hidden-import constants_inf ^
--hidden-import file_data ^
--hidden-import remote_command ^
--hidden-import remote_command_handler ^
--hidden-import remote_command_inf ^
--hidden-import remote_command_handler_inf ^
--hidden-import annotation ^
--hidden-import loader_client ^
--hidden-import ai_config ^
@@ -49,8 +49,8 @@ venv\Scripts\pyinstaller --name=azaion-inference ^
start.py
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "ai_config.cp312-win_amd64.pyd" "annotation.cp312-win_amd64.pyd"
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "constants.cp312-win_amd64.pyd" "file_data.cp312-win_amd64.pyd"
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "remote_command.cp312-win_amd64.pyd" "remote_command_handler.cp312-win_amd64.pyd"
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "constants_inf.cp312-win_amd64.pyd" "file_data.cp312-win_amd64.pyd"
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "remote_command_inf.cp312-win_amd64.pyd" "remote_command_handler_inf.cp312-win_amd64.pyd"
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "inference.cp312-win_amd64.pyd" "inference_engine.cp312-win_amd64.pyd"
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "loader_client.cp312-win_amd64.pyd" "tensorrt_engine.cp312-win_amd64.pyd"
robocopy "dist\azaion-inference\_internal" "..\dist-azaion\_internal" "onnx_engine.cp312-win_amd64.pyd" "main_inference.cp312-win_amd64.pyd"
+1 -1
View File
@@ -1,4 +1,4 @@
from remote_command cimport RemoteCommand
from remote_command_inf cimport RemoteCommand
from annotation cimport Annotation, Detection
from ai_config cimport AIRecognitionConfig
from loader_client cimport LoaderClient
+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)
+1 -1
View File
@@ -1,4 +1,4 @@
from remote_command cimport RemoteCommand
from remote_command_inf cimport RemoteCommand
cdef class LoadResult:
cdef public str err
+1 -1
View File
@@ -1,5 +1,5 @@
import zmq
from remote_command cimport RemoteCommand, CommandType
from remote_command_inf cimport RemoteCommand, CommandType
from file_data cimport FileData, UploadFileData
cdef class LoadResult:
+6 -6
View File
@@ -1,14 +1,14 @@
import queue
import traceback
from queue import Queue
cimport constants
cimport constants_inf
from threading import Thread
from annotation cimport Annotation
from inference cimport Inference
from loader_client cimport LoaderClient
from remote_command cimport RemoteCommand, CommandType
from remote_command_handler cimport RemoteCommandHandler
from remote_command_inf cimport RemoteCommand, CommandType
from remote_command_handler_inf cimport RemoteCommandHandler
cdef class CommandProcessor:
@@ -20,7 +20,7 @@ cdef class CommandProcessor:
def __init__(self, int zmq_port, str loader_zmq_host, int loader_zmq_port, str api_url):
self.remote_handler = RemoteCommandHandler(zmq_port, self.on_command)
self.inference_queue = Queue(maxsize=constants.QUEUE_MAXSIZE)
self.inference_queue = Queue(maxsize=constants_inf.QUEUE_MAXSIZE)
self.remote_handler.start()
self.running = True
self.loader_client = LoaderClient(loader_zmq_host, loader_zmq_port)
@@ -37,7 +37,7 @@ cdef class CommandProcessor:
continue
except Exception as e:
traceback.print_exc()
constants.log('EXIT!')
constants_inf.log('EXIT!')
cdef on_command(self, RemoteCommand command):
try:
@@ -54,7 +54,7 @@ cdef class CommandProcessor:
else:
pass
except Exception as e:
constants.logerror(f"Error handling client: {e}")
constants_inf.logerror(f"Error handling client: {e}")
cdef on_annotation(self, RemoteCommand cmd, Annotation annotation):
cdef RemoteCommand response = RemoteCommand(CommandType.INFERENCE_DATA, annotation.serialize())
+3 -3
View File
@@ -1,6 +1,6 @@
from inference_engine cimport InferenceEngine
import onnxruntime as onnx
cimport constants
cimport constants_inf
cdef class OnnxEngine(InferenceEngine):
def __init__(self, model_bytes: bytes, batch_size: int = 1, **kwargs):
@@ -11,9 +11,9 @@ cdef class OnnxEngine(InferenceEngine):
self.input_name = self.model_inputs[0].name
self.input_shape = self.model_inputs[0].shape
self.batch_size = self.input_shape[0] if self.input_shape[0] != -1 else batch_size
constants.log(f'AI detection model input: {self.model_inputs} {self.input_shape}')
constants_inf.log(f'AI detection model input: {self.model_inputs} {self.input_shape}')
model_meta = self.session.get_modelmeta()
constants.log(f"Metadata: {model_meta.custom_metadata_map}")
constants_inf.log(f"Metadata: {model_meta.custom_metadata_map}")
cpdef tuple get_input_shape(self):
shape = self.input_shape
@@ -1,8 +1,8 @@
import time
import zmq
from threading import Thread, Event
from remote_command cimport RemoteCommand
cimport constants
from remote_command_inf cimport RemoteCommand
cimport constants_inf
cdef class RemoteCommandHandler:
def __init__(self, int zmq_port, object on_command):
@@ -27,7 +27,7 @@ cdef class RemoteCommandHandler:
for _ in range(4): # 4 worker threads
worker = Thread(target=self._worker_loop, daemon=True)
self._workers.append(worker)
constants.log(f'Listening to commands on port {zmq_port}...')
constants_inf.log(f'Listening to commands on port {zmq_port}...')
cdef start(self):
self._proxy_thread.start()
@@ -39,7 +39,7 @@ cdef class RemoteCommandHandler:
zmq.proxy_steerable(self._router, self._dealer, control=self._control)
except zmq.error.ZMQError as e:
if self._shutdown_event.is_set():
constants.log("Shutdown, exit proxy loop.")
constants_inf.log("Shutdown, exit proxy loop.")
else:
raise
@@ -58,11 +58,11 @@ cdef class RemoteCommandHandler:
client_id, message = worker_socket.recv_multipart()
cmd = RemoteCommand.from_msgpack(<bytes> message)
cmd.client_id = client_id
constants.log(cmd)
constants_inf.log(str(cmd))
self._on_command(cmd)
except Exception as e:
if not self._shutdown_event.is_set():
constants.log(f"Worker error: {e}")
constants_inf.log(f"Worker error: {e}")
import traceback
traceback.print_exc()
finally:
+3 -3
View File
@@ -3,10 +3,10 @@ from Cython.Build import cythonize
import numpy as np
extensions = [
Extension('constants', ['constants.pyx']),
Extension('constants_inf', ['constants_inf.pyx']),
Extension('file_data', ['file_data.pyx']),
Extension('remote_command', ['remote_command.pyx']),
Extension('remote_command_handler', ['remote_command_handler.pyx']),
Extension('remote_command_inf', ['remote_command_inf.pyx']),
Extension('remote_command_handler_inf', ['remote_command_handler_inf.pyx']),
Extension('annotation', ['annotation.pyx']),
Extension('loader_client', ['loader_client.pyx']),
Extension('ai_config', ['ai_config.pyx']),
+5 -5
View File
@@ -4,7 +4,7 @@ import pycuda.driver as cuda
import pycuda.autoinit # required for automatically initialize CUDA, do not remove.
import pynvml
import numpy as np
cimport constants
cimport constants_inf
cdef class TensorRTEngine(InferenceEngine):
@@ -100,16 +100,16 @@ cdef class TensorRTEngine(InferenceEngine):
return None
if builder.platform_has_fast_fp16:
constants.log('Converting to supported fp16')
constants_inf.log('Converting to supported fp16')
config.set_flag(trt.BuilderFlag.FP16)
else:
constants.log('Converting to supported fp32. (fp16 is not supported)')
constants_inf.log('Converting to supported fp32. (fp16 is not supported)')
plan = builder.build_serialized_network(network, config)
if plan is None:
constants.logerror('Conversion failed.')
constants_inf.logerror('Conversion failed.')
return None
constants.log('conversion done!')
constants_inf.log('conversion done!')
return bytes(plan)
cpdef tuple get_input_shape(self):