diff --git a/Azaion.CommonSecurity/Services/PythonResourceLoader.cs b/Azaion.CommonSecurity/Services/PythonResourceLoader.cs index 1cd5e99..4388760 100644 --- a/Azaion.CommonSecurity/Services/PythonResourceLoader.cs +++ b/Azaion.CommonSecurity/Services/PythonResourceLoader.cs @@ -22,8 +22,6 @@ public interface IAuthProvider public class PythonResourceLoader : IResourceLoader, IAuthProvider { - private readonly ApiCredentials _credentials; - private readonly AzaionApiClient _api; private readonly DealerSocket _dealer = new(); private readonly Guid _clientId = Guid.NewGuid(); @@ -31,9 +29,7 @@ public class PythonResourceLoader : IResourceLoader, IAuthProvider public PythonResourceLoader(ApiConfig apiConfig, ApiCredentials credentials, AzaionApiClient api) { - _credentials = credentials; - _api = api; - //StartPython(apiConfig, credentials); + StartPython(apiConfig, credentials); _dealer.Options.Identity = Encoding.UTF8.GetBytes(_clientId.ToString("N")); _dealer.Connect($"tcp://{SecurityConstants.ZMQ_HOST}:{SecurityConstants.ZMQ_PORT}"); diff --git a/Azaion.Inference/inference.pxd b/Azaion.Inference/inference.pxd index fad6182..3b9979d 100644 --- a/Azaion.Inference/inference.pxd +++ b/Azaion.Inference/inference.pxd @@ -1,8 +1,10 @@ from remote_command cimport RemoteCommand from annotation cimport Annotation, Detection from ai_config cimport AIRecognitionConfig +from api_client cimport ApiClient cdef class Inference: + cdef ApiClient api_client cdef object session cdef object on_annotation cdef Annotation _previous_annotation diff --git a/Azaion.Inference/inference.pyx b/Azaion.Inference/inference.pyx index 7106186..be46b4f 100644 --- a/Azaion.Inference/inference.pyx +++ b/Azaion.Inference/inference.pyx @@ -11,13 +11,22 @@ from annotation cimport Detection, Annotation from ai_config cimport AIRecognitionConfig cdef class Inference: - def __init__(self, model_bytes, on_annotation): + def __init__(self, api_client, on_annotation): + self.api_client = api_client + self.on_annotation = on_annotation self.stop_signal = False + self.session = None + self.model_input = None + self.model_width = 0 + self.model_height = 0 + self.class_names = None + self.ai_config = AIRecognitionConfig(4, 2, 0.25, 0.15, 15, 0.8, b'') + + def init_ai(self): + model_bytes = self.api_client.load_ai_model() self.session = onnx.InferenceSession( model_bytes, providers=["CUDAExecutionProvider", "CPUExecutionProvider"] ) - self.on_annotation = on_annotation - self.ai_config = AIRecognitionConfig(4, 2, 0.25, 0.15, 15, 0.8, b'') model_inputs = self.session.get_inputs() self.model_input = model_inputs[0].name input_shape = model_inputs[0].shape @@ -38,7 +47,6 @@ cdef class Inference: for frame in frames] return np.vstack(blobs) - cdef postprocess(self, output): cdef list[Detection] detections = [] cdef int ann_index @@ -112,6 +120,8 @@ cdef class Inference: self.ai_config = AIRecognitionConfig.from_msgpack(cmd.data) self.stop_signal = False + if self.session is None: + self.init_ai() for m in medias: if self.is_video(m): diff --git a/Azaion.Inference/main.pyx b/Azaion.Inference/main.pyx index 64bf79d..add76b7 100644 --- a/Azaion.Inference/main.pyx +++ b/Azaion.Inference/main.pyx @@ -32,10 +32,10 @@ cdef class CommandProcessor: self.inference_queue = Queue(maxsize=constants.QUEUE_MAXSIZE) self.remote_handler.start() self.running = True - model = self.api_client.load_ai_model() - self.inference = Inference(model, self.on_annotation) + self.inference = Inference(self.api_client, self.on_annotation) def start(self): + print('Started!') while self.running: try: command = self.inference_queue.get(timeout=0.5) diff --git a/Azaion.Inference/token b/Azaion.Inference/token index e441bc2..34fc187 100644 --- a/Azaion.Inference/token +++ b/Azaion.Inference/token @@ -1 +1 @@ -eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI5N2U5MWI2OC1hNmRlLTQ3YTgtOTgzYi0xOTU3YzViNDQ2MTkiLCJ1bmlxdWVfbmFtZSI6ImFkbWluLXJlbW90ZUBhemFpb24uY29tIiwicm9sZSI6IkFwaUFkbWluIiwibmJmIjoxNzM5Mjk0ODY2LCJleHAiOjE3MzkzMDkyNjYsImlhdCI6MTczOTI5NDg2NiwiaXNzIjoiQXphaW9uQXBpIiwiYXVkIjoiQW5ub3RhdG9ycy9PcmFuZ2VQaS9BZG1pbnMifQ.fp0YzE42mqtG2fd4BtaX2ZH-0-9YLXHPDqoAHSpfWjk \ No newline at end of file +eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI5N2U5MWI2OC1hNmRlLTQ3YTgtOTgzYi0xOTU3YzViNDQ2MTkiLCJ1bmlxdWVfbmFtZSI6ImFkbWluLXJlbW90ZUBhemFpb24uY29tIiwicm9sZSI6IkFwaUFkbWluIiwibmJmIjoxNzM5MzUxNDEwLCJleHAiOjE3MzkzNjU4MTAsImlhdCI6MTczOTM1MTQxMCwiaXNzIjoiQXphaW9uQXBpIiwiYXVkIjoiQW5ub3RhdG9ycy9PcmFuZ2VQaS9BZG1pbnMifQ.P32xRe6nk-0u2jjBi3rdsd3YwlmGXL0NX_eE2xb7OUI \ No newline at end of file