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
-4
View File
@@ -99,10 +99,6 @@ public class CanvasEditor : Canvas
Fill = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128)), Fill = new SolidColorBrush(Color.FromArgb(128, 128, 128, 128)),
}; };
KeyDown += (_, args) =>
{
Console.WriteLine($"pressed {args.Key}");
};
MouseDown += CanvasMouseDown; MouseDown += CanvasMouseDown;
MouseMove += CanvasMouseMove; MouseMove += CanvasMouseMove;
MouseUp += CanvasMouseUp; MouseUp += CanvasMouseUp;
+2 -1
View File
@@ -9,6 +9,7 @@ using LinqToDB.Mapping;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json; using Newtonsoft.Json;
using Serilog;
namespace Azaion.Common.Database; namespace Azaion.Common.Database;
@@ -138,7 +139,7 @@ public class DbFactory : IDbFactory
{ {
var detDeleted = await db.Detections.DeleteAsync(x => annotationNames.Contains(x.AnnotationName), token: cancellationToken); var detDeleted = await db.Detections.DeleteAsync(x => annotationNames.Contains(x.AnnotationName), token: cancellationToken);
var annDeleted = await db.Annotations.DeleteAsync(x => annotationNames.Contains(x.Name), token: cancellationToken); var annDeleted = await db.Annotations.DeleteAsync(x => annotationNames.Contains(x.Name), token: cancellationToken);
Console.WriteLine($"Deleted {detDeleted} detections, {annDeleted} annotations"); _logger.LogInformation($"Deleted {detDeleted} detections, {annDeleted} annotations");
}); });
} }
} }
+1 -2
View File
@@ -4,8 +4,7 @@ public static class ResilienceExt
{ {
public static void WithRetry(this Action operation, int retryCount = 3, int delayMs = 150) => public static void WithRetry(this Action operation, int retryCount = 3, int delayMs = 150) =>
Policy.Handle<Exception>() Policy.Handle<Exception>()
.WaitAndRetry(retryCount, num => TimeSpan.FromMilliseconds(num * delayMs), .WaitAndRetry(retryCount, num => TimeSpan.FromMilliseconds(num * delayMs))
(exception, timeSpan) => Console.WriteLine($"Exception: {exception}, TimeSpan: {timeSpan}"))
.Execute(operation); .Execute(operation);
public static TResult WithRetry<TResult>(this Func<TResult> operation, int retryCount = 3, int delayMs = 150) => public static TResult WithRetry<TResult>(this Func<TResult> operation, int retryCount = 3, int delayMs = 150) =>
+3 -2
View File
@@ -1,6 +1,7 @@
using System.IO; using System.IO;
using Azaion.Common.DTO; using Azaion.Common.DTO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Serilog;
namespace Azaion.Common; namespace Azaion.Common;
@@ -59,7 +60,7 @@ public class SecurityConstants
}; };
#endregion ExternalClientsConfig #endregion ExternalClientsConfig
public static InitConfig ReadInitConfig() public static InitConfig ReadInitConfig(ILogger logger)
{ {
try try
{ {
@@ -72,7 +73,7 @@ public class SecurityConstants
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); logger.Error(e, e.Message);
return DefaultInitConfig; return DefaultInitConfig;
} }
} }
+4 -2
View File
@@ -4,7 +4,9 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text; using System.Text;
using Azaion.Common.DTO; using Azaion.Common.DTO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Serilog;
namespace Azaion.Common.Services; namespace Azaion.Common.Services;
@@ -16,7 +18,7 @@ public interface IAzaionApi
//Stream GetResource(string filename, string folder); //Stream GetResource(string filename, string folder);
} }
public class AzaionApi(HttpClient client, ICache cache, ApiCredentials credentials) : IAzaionApi public class AzaionApi(ILogger logger, HttpClient client, ICache cache, ApiCredentials credentials) : IAzaionApi
{ {
private string _jwtToken = null!; private string _jwtToken = null!;
const string APP_JSON = "application/json"; const string APP_JSON = "application/json";
@@ -116,7 +118,7 @@ public class AzaionApi(HttpClient client, ICache cache, ApiCredentials credentia
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); logger.Error(e, e.Message);
throw; throw;
} }
} }
+2 -2
View File
@@ -149,7 +149,7 @@ public class GalleryService(
if (!existingAnnotations.ContainsKey(fName)) if (!existingAnnotations.ContainsKey(fName))
{ {
if (missedAnnotations.ContainsKey(fName)) if (missedAnnotations.ContainsKey(fName))
Console.WriteLine($"{fName} is already exists! Duplicate!"); logger.LogInformation($"{fName} is already exists! Duplicate!");
else else
missedAnnotations.TryAdd(fName, annotation); missedAnnotations.TryAdd(fName, annotation);
} }
@@ -168,7 +168,7 @@ public class GalleryService(
{ {
ProgressFn = async num => ProgressFn = async num =>
{ {
Console.WriteLine($"Processed {num} item by Thread {Environment.CurrentManagedThreadId}"); logger.LogInformation($"Processed {num} item by Thread {Environment.CurrentManagedThreadId}");
ProcessedThumbnailsPercentage = imagesCount == 0 ? 0 : Math.Min(100, num * 100 / (double)imagesCount); ProcessedThumbnailsPercentage = imagesCount == 0 ? 0 : Math.Min(100, num * 100 / (double)imagesCount);
ThumbnailsUpdate?.Invoke(ProcessedThumbnailsPercentage); ThumbnailsUpdate?.Invoke(ProcessedThumbnailsPercentage);
await Task.CompletedTask; await Task.CompletedTask;
+2 -5
View File
@@ -54,15 +54,12 @@ public class GpsMatcherClient : IGpsMatcherClient
WorkingDirectory = SecurityConstants.EXTERNAL_GPS_DENIED_FOLDER, WorkingDirectory = SecurityConstants.EXTERNAL_GPS_DENIED_FOLDER,
CreateNoWindow = true CreateNoWindow = true
}; };
process.OutputDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.ErrorDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.Start(); process.Start();
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); _logger.LogError(e, e.ToString());
//throw; throw;
} }
_requestAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqPort}"; _requestAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqPort}";
+6 -6
View File
@@ -2,6 +2,7 @@
using System.Text; using System.Text;
using Azaion.Common.DTO; using Azaion.Common.DTO;
using MessagePack; using MessagePack;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using NetMQ; using NetMQ;
using NetMQ.Sockets; using NetMQ.Sockets;
@@ -18,6 +19,7 @@ public interface IInferenceClient : IDisposable
public class InferenceClient : IInferenceClient public class InferenceClient : IInferenceClient
{ {
private readonly ILogger<InferenceClient> _logger;
public event EventHandler<RemoteCommand>? BytesReceived; public event EventHandler<RemoteCommand>? BytesReceived;
public event EventHandler<RemoteCommand>? InferenceDataReceived; public event EventHandler<RemoteCommand>? InferenceDataReceived;
public event EventHandler<RemoteCommand>? AIAvailabilityReceived; public event EventHandler<RemoteCommand>? AIAvailabilityReceived;
@@ -28,8 +30,9 @@ public class InferenceClient : IInferenceClient
private readonly InferenceClientConfig _inferenceClientConfig; private readonly InferenceClientConfig _inferenceClientConfig;
private readonly LoaderClientConfig _loaderClientConfig; private readonly LoaderClientConfig _loaderClientConfig;
public InferenceClient(IOptions<InferenceClientConfig> inferenceConfig, IOptions<LoaderClientConfig> loaderConfig) public InferenceClient(ILogger<InferenceClient> logger, IOptions<InferenceClientConfig> inferenceConfig, IOptions<LoaderClientConfig> loaderConfig)
{ {
_logger = logger;
_inferenceClientConfig = inferenceConfig.Value; _inferenceClientConfig = inferenceConfig.Value;
_loaderClientConfig = loaderConfig.Value; _loaderClientConfig = loaderConfig.Value;
Start(); Start();
@@ -46,15 +49,12 @@ public class InferenceClient : IInferenceClient
Arguments = $"-p {_inferenceClientConfig.ZeroMqPort} -lp {_loaderClientConfig.ZeroMqPort} -a {_inferenceClientConfig.ApiUrl}", Arguments = $"-p {_inferenceClientConfig.ZeroMqPort} -lp {_loaderClientConfig.ZeroMqPort} -a {_inferenceClientConfig.ApiUrl}",
CreateNoWindow = true CreateNoWindow = true
}; };
process.OutputDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.ErrorDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.Start(); process.Start();
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); _logger.LogError(e, e.Message);
//throw; throw;
} }
_dealer.Options.Identity = Encoding.UTF8.GetBytes(_clientId.ToString("N")); _dealer.Options.Identity = Encoding.UTF8.GetBytes(_clientId.ToString("N"));
+1 -10
View File
@@ -26,20 +26,11 @@ public class LoaderClient(LoaderClientConfig config, ILogger logger, Cancellatio
Arguments = $"--port {config.ZeroMqPort} --api {config.ApiUrl}", Arguments = $"--port {config.ZeroMqPort} --api {config.ApiUrl}",
CreateNoWindow = true CreateNoWindow = true
}; };
process.OutputDataReceived += (_, e) =>
{
if (e.Data != null) Console.WriteLine(e.Data);
};
process.ErrorDataReceived += (_, e) =>
{
if (e.Data != null) Console.WriteLine(e.Data);
};
process.Start(); process.Start();
} }
catch (Exception e) catch (Exception e)
{ {
logger.Error(e.Message); logger.Error(e, e.Message);
throw; throw;
} }
} }
@@ -146,7 +146,7 @@ public class SatelliteDownloader(
} }
catch (Exception) catch (Exception)
{ {
Console.WriteLine($"Error while loading tile: {tileData}"); logger.LogError($"Error while loading tile: {tileData}");
} }
if (token.IsCancellationRequested) if (token.IsCancellationRequested)
return; return;
+1 -1
View File
@@ -4,7 +4,7 @@ from PyInstaller.utils.hooks import collect_all
datas = [('venv\\Lib\\site-packages\\cv2', 'cv2')] datas = [('venv\\Lib\\site-packages\\cv2', 'cv2')]
binaries = [] 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') hiddenimports += collect_submodules('cv2')
tmp_ret = collect_all('psutil') tmp_ret = collect_all('psutil')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] 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 pynvml ^
--collect-all jwt ^ --collect-all jwt ^
--collect-all loguru ^ --collect-all loguru ^
--hidden-import constants ^ --hidden-import constants_inf ^
--hidden-import file_data ^ --hidden-import file_data ^
--hidden-import remote_command ^ --hidden-import remote_command_inf ^
--hidden-import remote_command_handler ^ --hidden-import remote_command_handler_inf ^
--hidden-import annotation ^ --hidden-import annotation ^
--hidden-import loader_client ^ --hidden-import loader_client ^
--hidden-import ai_config ^ --hidden-import ai_config ^
@@ -49,8 +49,8 @@ venv\Scripts\pyinstaller --name=azaion-inference ^
start.py 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" "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" "constants_inf.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" "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" "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" "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" 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 annotation cimport Annotation, Detection
from ai_config cimport AIRecognitionConfig from ai_config cimport AIRecognitionConfig
from loader_client cimport LoaderClient from loader_client cimport LoaderClient
+16 -16
View File
@@ -2,8 +2,8 @@ import mimetypes
import time import time
import cv2 import cv2
import numpy as np import numpy as np
cimport constants cimport constants_inf
from remote_command cimport RemoteCommand from remote_command_inf cimport RemoteCommand
from annotation cimport Detection, Annotation from annotation cimport Detection, Annotation
from ai_config cimport AIRecognitionConfig from ai_config cimport AIRecognitionConfig
import pynvml import pynvml
@@ -16,7 +16,7 @@ cdef int check_tensor_gpu_index():
deviceCount = pynvml.nvmlDeviceGetCount() deviceCount = pynvml.nvmlDeviceGetCount()
if deviceCount == 0: if deviceCount == 0:
constants.logerror('No NVIDIA GPUs found.') constants_inf.logerror('No NVIDIA GPUs found.')
return -1 return -1
for i in range(deviceCount): for i in range(deviceCount):
@@ -24,10 +24,10 @@ cdef int check_tensor_gpu_index():
major, minor = pynvml.nvmlDeviceGetCudaComputeCapability(handle) major, minor = pynvml.nvmlDeviceGetCudaComputeCapability(handle)
if major > 6 or (major == 6 and minor >= 1): if major > 6 or (major == 6 and minor >= 1):
constants.log('found NVIDIA GPU!') constants_inf.log('found NVIDIA GPU!')
return i return i
constants.logerror('NVIDIA GPU doesnt support TensorRT!') constants_inf.logerror('NVIDIA GPU doesnt support TensorRT!')
return -1 return -1
except pynvml.NVMLError: except pynvml.NVMLError:
@@ -36,7 +36,7 @@ cdef int check_tensor_gpu_index():
try: try:
pynvml.nvmlShutdown() pynvml.nvmlShutdown()
except: 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 pass
tensor_gpu_index = check_tensor_gpu_index() tensor_gpu_index = check_tensor_gpu_index()
@@ -63,23 +63,23 @@ cdef class Inference:
try: try:
engine_filename = TensorRTEngine.get_engine_filename(0) engine_filename = TensorRTEngine.get_engine_filename(0)
models_dir = constants.MODELS_FOLDER models_dir = constants_inf.MODELS_FOLDER
self.is_building_engine = True self.is_building_engine = True
updater_callback('downloading') updater_callback('downloading')
res = self.loader_client.load_big_small_resource(engine_filename, models_dir) res = self.loader_client.load_big_small_resource(engine_filename, models_dir)
if res.err is None: 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 self.is_building_engine = False
updater_callback('enabled') updater_callback('enabled')
return return
constants.logerror(res.err) constants_inf.logerror(res.err)
# time.sleep(8) # prevent simultaneously loading dll and models # time.sleep(8) # prevent simultaneously loading dll and models
updater_callback('converting') updater_callback('converting')
constants.log('try to load onnx') constants_inf.log('try to load onnx')
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: if res.err is not None:
updater_callback(f'Error. {res.err}') updater_callback(f'Error. {res.err}')
model_bytes = TensorRTEngine.convert_from_onnx(res.data) 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) res = self.loader_client.upload_big_small_resource(model_bytes, <str> engine_filename, models_dir)
if res.err is not None: if res.err is not None:
updater_callback(f'Error. {res.err}') 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 self.is_building_engine = False
updater_callback('enabled') updater_callback('enabled')
except Exception as e: except Exception as e:
@@ -97,7 +97,7 @@ cdef class Inference:
if self.engine is not None: if self.engine is not None:
return return
models_dir = constants.MODELS_FOLDER models_dir = constants_inf.MODELS_FOLDER
if tensor_gpu_index > -1: if tensor_gpu_index > -1:
while self.is_building_engine: while self.is_building_engine:
time.sleep(1) time.sleep(1)
@@ -108,7 +108,7 @@ cdef class Inference:
raise Exception(res.err) raise Exception(res.err)
self.engine = TensorRTEngine(res.data) self.engine = TensorRTEngine(res.data)
else: 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: if res.err is not None:
raise Exception(res.err) raise Exception(res.err)
self.engine = OnnxEngine(res.data) self.engine = OnnxEngine(res.data)
@@ -212,11 +212,11 @@ cdef class Inference:
# images first, it's faster # images first, it's faster
if len(images) > 0: if len(images) > 0:
for chunk in self.split_list_extend(images, self.engine.get_batch_size()): 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) self._process_images(cmd, ai_config, chunk)
if len(videos) > 0: if len(videos) > 0:
for v in videos: 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) 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 class LoadResult:
cdef public str err cdef public str err
+1 -1
View File
@@ -1,5 +1,5 @@
import zmq import zmq
from remote_command cimport RemoteCommand, CommandType from remote_command_inf cimport RemoteCommand, CommandType
from file_data cimport FileData, UploadFileData from file_data cimport FileData, UploadFileData
cdef class LoadResult: cdef class LoadResult:
+6 -6
View File
@@ -1,14 +1,14 @@
import queue import queue
import traceback import traceback
from queue import Queue from queue import Queue
cimport constants cimport constants_inf
from threading import Thread from threading import Thread
from annotation cimport Annotation from annotation cimport Annotation
from inference cimport Inference from inference cimport Inference
from loader_client cimport LoaderClient from loader_client cimport LoaderClient
from remote_command cimport RemoteCommand, CommandType from remote_command_inf cimport RemoteCommand, CommandType
from remote_command_handler cimport RemoteCommandHandler from remote_command_handler_inf cimport RemoteCommandHandler
cdef class CommandProcessor: 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): 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.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.remote_handler.start()
self.running = True self.running = True
self.loader_client = LoaderClient(loader_zmq_host, loader_zmq_port) self.loader_client = LoaderClient(loader_zmq_host, loader_zmq_port)
@@ -37,7 +37,7 @@ cdef class CommandProcessor:
continue continue
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
constants.log('EXIT!') constants_inf.log('EXIT!')
cdef on_command(self, RemoteCommand command): cdef on_command(self, RemoteCommand command):
try: try:
@@ -54,7 +54,7 @@ cdef class CommandProcessor:
else: else:
pass pass
except Exception as e: 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 on_annotation(self, RemoteCommand cmd, Annotation annotation):
cdef RemoteCommand response = RemoteCommand(CommandType.INFERENCE_DATA, annotation.serialize()) cdef RemoteCommand response = RemoteCommand(CommandType.INFERENCE_DATA, annotation.serialize())
+3 -3
View File
@@ -1,6 +1,6 @@
from inference_engine cimport InferenceEngine from inference_engine cimport InferenceEngine
import onnxruntime as onnx import onnxruntime as onnx
cimport constants cimport constants_inf
cdef class OnnxEngine(InferenceEngine): cdef class OnnxEngine(InferenceEngine):
def __init__(self, model_bytes: bytes, batch_size: int = 1, **kwargs): 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_name = self.model_inputs[0].name
self.input_shape = self.model_inputs[0].shape self.input_shape = self.model_inputs[0].shape
self.batch_size = self.input_shape[0] if self.input_shape[0] != -1 else batch_size 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() 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): cpdef tuple get_input_shape(self):
shape = self.input_shape shape = self.input_shape
@@ -1,8 +1,8 @@
import time import time
import zmq import zmq
from threading import Thread, Event from threading import Thread, Event
from remote_command cimport RemoteCommand from remote_command_inf cimport RemoteCommand
cimport constants cimport constants_inf
cdef class RemoteCommandHandler: cdef class RemoteCommandHandler:
def __init__(self, int zmq_port, object on_command): def __init__(self, int zmq_port, object on_command):
@@ -27,7 +27,7 @@ cdef class RemoteCommandHandler:
for _ in range(4): # 4 worker threads for _ in range(4): # 4 worker threads
worker = Thread(target=self._worker_loop, daemon=True) worker = Thread(target=self._worker_loop, daemon=True)
self._workers.append(worker) 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): cdef start(self):
self._proxy_thread.start() self._proxy_thread.start()
@@ -39,7 +39,7 @@ cdef class RemoteCommandHandler:
zmq.proxy_steerable(self._router, self._dealer, control=self._control) zmq.proxy_steerable(self._router, self._dealer, control=self._control)
except zmq.error.ZMQError as e: except zmq.error.ZMQError as e:
if self._shutdown_event.is_set(): if self._shutdown_event.is_set():
constants.log("Shutdown, exit proxy loop.") constants_inf.log("Shutdown, exit proxy loop.")
else: else:
raise raise
@@ -58,11 +58,11 @@ cdef class RemoteCommandHandler:
client_id, message = worker_socket.recv_multipart() client_id, message = worker_socket.recv_multipart()
cmd = RemoteCommand.from_msgpack(<bytes> message) cmd = RemoteCommand.from_msgpack(<bytes> message)
cmd.client_id = client_id cmd.client_id = client_id
constants.log(cmd) constants_inf.log(str(cmd))
self._on_command(cmd) self._on_command(cmd)
except Exception as e: except Exception as e:
if not self._shutdown_event.is_set(): if not self._shutdown_event.is_set():
constants.log(f"Worker error: {e}") constants_inf.log(f"Worker error: {e}")
import traceback import traceback
traceback.print_exc() traceback.print_exc()
finally: finally:
+3 -3
View File
@@ -3,10 +3,10 @@ from Cython.Build import cythonize
import numpy as np import numpy as np
extensions = [ extensions = [
Extension('constants', ['constants.pyx']), Extension('constants_inf', ['constants_inf.pyx']),
Extension('file_data', ['file_data.pyx']), Extension('file_data', ['file_data.pyx']),
Extension('remote_command', ['remote_command.pyx']), Extension('remote_command_inf', ['remote_command_inf.pyx']),
Extension('remote_command_handler', ['remote_command_handler.pyx']), Extension('remote_command_handler_inf', ['remote_command_handler_inf.pyx']),
Extension('annotation', ['annotation.pyx']), Extension('annotation', ['annotation.pyx']),
Extension('loader_client', ['loader_client.pyx']), Extension('loader_client', ['loader_client.pyx']),
Extension('ai_config', ['ai_config.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 pycuda.autoinit # required for automatically initialize CUDA, do not remove.
import pynvml import pynvml
import numpy as np import numpy as np
cimport constants cimport constants_inf
cdef class TensorRTEngine(InferenceEngine): cdef class TensorRTEngine(InferenceEngine):
@@ -100,16 +100,16 @@ cdef class TensorRTEngine(InferenceEngine):
return None return None
if builder.platform_has_fast_fp16: 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) config.set_flag(trt.BuilderFlag.FP16)
else: 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) plan = builder.build_serialized_network(network, config)
if plan is None: if plan is None:
constants.logerror('Conversion failed.') constants_inf.logerror('Conversion failed.')
return None return None
constants.log('conversion done!') constants_inf.log('conversion done!')
return bytes(plan) return bytes(plan)
cpdef tuple get_input_shape(self): cpdef tuple get_input_shape(self):
+1 -1
View File
@@ -45,7 +45,7 @@ start.py
robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "security.cp312-win_amd64.pyd" "cdn_manager.cp312-win_amd64.pyd" robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "security.cp312-win_amd64.pyd" "cdn_manager.cp312-win_amd64.pyd"
robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "credentials.cp312-win_amd64.pyd" "api_client.cp312-win_amd64.pyd" robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "constants.cp312-win_amd64.pyd" "credentials.cp312-win_amd64.pyd" "api_client.cp312-win_amd64.pyd"
robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "hardware_service.cp312-win_amd64.pyd" "user.cp312-win_amd64.pyd" robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "hardware_service.cp312-win_amd64.pyd" "user.cp312-win_amd64.pyd"
robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "main_loader.cp312-win_amd64.pyd" robocopy "dist\azaion-loader\_internal" "..\dist-azaion\_internal" "main_loader.cp312-win_amd64.pyd"
+1 -1
View File
@@ -59,7 +59,7 @@ cdef class RemoteCommandHandler:
client_id, message = worker_socket.recv_multipart() client_id, message = worker_socket.recv_multipart()
cmd = RemoteCommand.from_msgpack(<bytes> message) cmd = RemoteCommand.from_msgpack(<bytes> message)
cmd.client_id = client_id cmd.client_id = client_id
constants.log(<str>f'{cmd}') constants.log(str(cmd))
self._on_command(cmd) self._on_command(cmd)
except Exception as e: except Exception as e:
if not self._shutdown_event.is_set(): if not self._shutdown_event.is_set():
+2 -2
View File
@@ -106,7 +106,7 @@ public partial class App
try try
{ {
new ConfigUpdater().CheckConfig(); new ConfigUpdater().CheckConfig();
var initConfig = SecurityConstants.ReadInitConfig(); var initConfig = SecurityConstants.ReadInitConfig(Log.Logger);
var apiDir = initConfig.DirectoriesConfig.ApiResourcesDirectory; var apiDir = initConfig.DirectoriesConfig.ApiResourcesDirectory;
_loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, _mainCTokenSource.Token); _loaderClient = new LoaderClient(initConfig.LoaderClientConfig, Log.Logger, _mainCTokenSource.Token);
@@ -114,7 +114,7 @@ public partial class App
_loaderClient.Connect(); //Client app should be already started by LoaderUI _loaderClient.Connect(); //Client app should be already started by LoaderUI
_loaderClient.Login(credentials); _loaderClient.Login(credentials);
var azaionApi = new AzaionApi(new HttpClient { BaseAddress = new Uri(initConfig.InferenceClientConfig.ApiUrl) }, _cache, credentials); var azaionApi = new AzaionApi(Log.Logger, new HttpClient { BaseAddress = new Uri(initConfig.InferenceClientConfig.ApiUrl) }, _cache, credentials);
_host = Host.CreateDefaultBuilder() _host = Host.CreateDefaultBuilder()
.ConfigureAppConfiguration((_, config) => config .ConfigureAppConfiguration((_, config) => config