refactor external clients

put model batch size as parameter in config
This commit is contained in:
Alex Bezdieniezhnykh
2025-03-24 00:33:41 +02:00
parent 32f9de3c71
commit 6429ad62c2
28 changed files with 352 additions and 226 deletions
+36 -23
View File
@@ -33,7 +33,10 @@ public partial class App
private IMediator _mediator = null!;
private FormState _formState = null!;
private PythonResourceLoader _resourceLoader = null!;
private InferenceExternalClient _inferenceClient = null!;
private IResourceLoader _resourceLoader = null!;
private IAuthProvider _authProvider = null!;
private Stream _securedConfig = null!;
private static readonly Guid KeyPressTaskId = Guid.NewGuid();
@@ -55,41 +58,44 @@ public partial class App
"Azaion.Dataset"
];
private static PythonConfig ReadPythonConfig()
private static SecureAppConfig ReadSecureAppConfig()
{
try
{
if (!File.Exists(SecurityConstants.CONFIG_PATH))
throw new FileNotFoundException(SecurityConstants.CONFIG_PATH);
var configStr = File.ReadAllText(SecurityConstants.CONFIG_PATH);
return JsonConvert.DeserializeObject<SecureAppConfig>(configStr)!.PythonConfig;
var config = JsonConvert.DeserializeObject<SecureAppConfig>(configStr);
return config ?? SecurityConstants.DefaultSecureAppConfig;
}
catch (Exception e)
{
Console.WriteLine(e);
return new PythonConfig
{
ZeroMqHost = SecurityConstants.DEFAULT_ZMQ_HOST,
ZeroMqPort = SecurityConstants.DEFAULT_ZMQ_PORT,
OneTryTimeoutSeconds = SecurityConstants.DEFAULT_TIMEOUT_SECONDS,
RetryCount = SecurityConstants.DEFAULT_RETRY_COUNT,
ResourcesFolder = ""
};
return SecurityConstants.DefaultSecureAppConfig;
}
}
private void StartLogin()
{
new ConfigUpdater().CheckConfig();
var secureAppConfig = ReadSecureAppConfig();
_inferenceClient = new InferenceExternalClient(new OptionsWrapper<InferenceClientConfig>(secureAppConfig.InferenceClientConfig));
_resourceLoader = new ResourceLoader(_inferenceClient);
_authProvider = new AuthProvider(_inferenceClient);
var login = new Login();
var pythonConfig = ReadPythonConfig();
_resourceLoader = new PythonResourceLoader(pythonConfig);
login.Closed += (sender, args) =>
{
if (!login.MainSuiteOpened)
_inferenceClient.Stop();
};
login.CredentialsEntered += (_, credentials) =>
{
credentials.Folder = pythonConfig.ResourcesFolder;
_resourceLoader.Login(credentials);
_securedConfig = _resourceLoader.LoadFileFromPython("secured-config.json");
credentials.Folder = secureAppConfig.InferenceClientConfig.ResourcesFolder;
_authProvider.Login(credentials);
_securedConfig = _resourceLoader.LoadFile("secured-config.json");
AppDomain.CurrentDomain.AssemblyResolve += (_, a) =>
{
@@ -98,7 +104,7 @@ public partial class App
{
try
{
var stream = _resourceLoader.LoadFileFromPython($"{assemblyName}.dll");
var stream = _resourceLoader.LoadFile($"{assemblyName}.dll");
return Assembly.Load(stream.ToArray());
}
catch (Exception e)
@@ -147,18 +153,25 @@ public partial class App
services.AddSingleton<MainSuite>();
services.AddSingleton<IHardwareService, HardwareService>();
services.AddSingleton<IResourceLoader>(_resourceLoader);
services.AddSingleton<IAuthProvider>(_resourceLoader);
services.AddSingleton<IInferenceService, PythonInferenceService>();
services.Configure<AppConfig>(context.Configuration);
services.ConfigureSection<PythonConfig>(context.Configuration);
services.ConfigureSection<QueueConfig>(context.Configuration);
services.ConfigureSection<DirectoriesConfig>(context.Configuration);
services.ConfigureSection<AnnotationConfig>(context.Configuration);
services.ConfigureSection<AIRecognitionConfig>(context.Configuration);
services.ConfigureSection<ThumbnailConfig>(context.Configuration);
#region External Services
services.ConfigureSection<InferenceClientConfig>(context.Configuration);
services.ConfigureSection<GpsDeniedClientConfig>(context.Configuration);
services.AddKeyedSingleton<IExternalClient>(SecurityConstants.EXTERNAL_INFERENCE_PATH, _inferenceClient);
services.AddKeyedSingleton<IExternalClient, GpsDeniedExternalClient>(SecurityConstants.EXTERNAL_GPS_DENIED_PATH);
services.AddSingleton<IResourceLoader>(_resourceLoader);
services.AddSingleton<IAuthProvider>(_authProvider);
services.AddSingleton<IInferenceService, InferenceService>();
#endregion
services.AddSingleton<IConfigUpdater, ConfigUpdater>();
services.AddSingleton<Annotator.Annotator>();
services.AddSingleton<DatasetExplorer>();
+2 -2
View File
@@ -60,8 +60,8 @@
<Target Name="PostBuild" AfterTargets="Build">
<MakeDir Directories="$(TargetDir)dummy" />
<Move SourceFiles="$(TargetDir)Azaion.Annotator.dll" DestinationFolder="$(TargetDir)dummy" />
<Move SourceFiles="$(TargetDir)Azaion.Dataset.dll" DestinationFolder="$(TargetDir)dummy" />
<Copy SourceFiles="$(TargetDir)Azaion.Annotator.dll" DestinationFolder="$(TargetDir)dummy" />
<Copy SourceFiles="$(TargetDir)Azaion.Dataset.dll" DestinationFolder="$(TargetDir)dummy" />
<Exec Command="upload.cmd $(ConfigurationName) stage" />
</Target>
+3
View File
@@ -8,6 +8,8 @@ namespace Azaion.Suite;
public partial class Login
{
public bool MainSuiteOpened { get; set; } = false;
public Login()
{
InitializeComponent();
@@ -20,6 +22,7 @@ public partial class Login
LoginBtn.Cursor = Cursors.Wait;
Cursor = Cursors.Wait;
CredentialsEntered?.Invoke(this, new ApiCredentials(TbEmail.Text, TbPassword.Password));
MainSuiteOpened = true;
Close();
}
+10 -4
View File
@@ -25,6 +25,7 @@ public partial class MainSuite
private readonly IDbFactory _dbFactory;
private readonly Dictionary<WindowEnum, Window> _openedWindows = new();
private readonly IResourceLoader _resourceLoader;
private readonly IEnumerable<IExternalClient> _externalClients;
private static readonly Guid SaveConfigTaskId = Guid.NewGuid();
public MainSuite(IOptions<AppConfig> appConfig,
@@ -33,7 +34,8 @@ public partial class MainSuite
IServiceProvider sp,
IGalleryService galleryService,
IDbFactory dbFactory,
IResourceLoader resourceLoader)
IResourceLoader resourceLoader,
IEnumerable<IExternalClient> externalClients)
{
_configUpdater = configUpdater;
_modules = modules;
@@ -41,6 +43,7 @@ public partial class MainSuite
_galleryService = galleryService;
_dbFactory = dbFactory;
_resourceLoader = resourceLoader;
_externalClients = externalClients;
_appConfig = appConfig.Value;
InitializeComponent();
Loaded += OnLoaded;
@@ -111,10 +114,13 @@ public partial class MainSuite
_openedWindows[module.WindowEnum] = window;
window.Closed += (_, _) =>
{
_resourceLoader.StopPython();
_openedWindows.Remove(module.WindowEnum);
if (!_openedWindows.Any())
Close();
if (_openedWindows.Any())
return;
foreach (var client in _externalClients)
client.Stop();
Close();
};
window.Show();
window.Activate();
+10 -2
View File
@@ -1,11 +1,17 @@
{
"PythonConfig": {
"InferenceClientConfig": {
"ZeroMqHost": "127.0.0.1",
"ZeroMqPort": 5127,
"RetryCount": 25,
"TimeoutSeconds": 5,
"ResourcesFolder": "stage"
},
"GpsDeniedClientConfig": {
"ZeroMqHost": "127.0.0.1",
"ZeroMqPort": 5227,
"RetryCount": 25,
"TimeoutSeconds": 5
},
"DirectoriesConfig": {
"VideosDirectory": "E:\\Azaion6",
"LabelsDirectory": "E:\\labels",
@@ -44,7 +50,9 @@
"TrackingDistanceConfidence": 0.15,
"TrackingProbabilityIncrease": 15.0,
"TrackingIntersectionThreshold": 0.8
"TrackingIntersectionThreshold": 0.8,
"ModelBatchSize": 2
},
"ThumbnailConfig": { "Size": "240,135", "Border": 10 },
"MapConfig":
+8 -1
View File
@@ -1,8 +1,15 @@
{
"PythonConfig": {
"InferenceClientConfig": {
"ZeroMqHost": "127.0.0.1",
"ZeroMqPort": 5131,
"RetryCount": 25,
"TimeoutSeconds": 5,
"ResourcesFolder": "stage"
},
"GpsDeniedClientConfig": {
"ZeroMqHost": "127.0.0.1",
"ZeroMqPort": 5231,
"RetryCount": 25,
"TimeoutSeconds": 5
},
"DirectoriesConfig": {