fix loader bug with _CACHED_HW_INFO

put tile size to name and set it dynamically for AI recognition
This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-09-02 13:59:23 +03:00
parent 067f02cc63
commit b6b6751c37
19 changed files with 83 additions and 104 deletions
+3 -3
View File
@@ -15,9 +15,9 @@ public static class Constants
public const string LOADER_CONFIG_PATH = "loaderconfig.json";
public const string DEFAULT_API_URL = "https://api.azaion.com";
public const string AZAION_SUITE_EXE = "Azaion.Suite.exe";
public const int AI_TILE_SIZE = 1280;
public const int AI_TILE_SIZE_DEFAULT = 1280;
#region ExternalClientsConfig
private const string DEFAULT_ZMQ_LOADER_HOST = "127.0.0.1";
+2 -2
View File
@@ -482,8 +482,8 @@ public class CanvasEditor : Canvas
canvasLabel = new CanvasLabel(detection, RenderSize, mediaSize, detection.Confidence);
else
{
canvasLabel = new CanvasLabel(detection, new Size(Constants.AI_TILE_SIZE, Constants.AI_TILE_SIZE), null, detection.Confidence)
.ReframeFromSmall(annotation.SplitTile!);
canvasLabel = new CanvasLabel(detection, annotation.SplitTile!.Size, null, detection.Confidence)
.ReframeFromSmall(annotation.SplitTile);
//From CurrentMediaSize to Render Size
var yoloLabel = new YoloLabel(canvasLabel, mediaSize);
+5 -5
View File
@@ -59,13 +59,13 @@ public class Annotation
return _splitTile;
var startCoordIndex = Name.IndexOf(Constants.SPLIT_SUFFIX, StringComparison.Ordinal) + Constants.SPLIT_SUFFIX.Length;
var coordsStr = Name.Substring(startCoordIndex, 9).Split('_');
var coordsStr = Name.Substring(startCoordIndex, 14).Split('_');
_splitTile = new CanvasLabel
{
Left = double.Parse(coordsStr[0]),
Top = double.Parse(coordsStr[1]),
Width = Constants.AI_TILE_SIZE,
Height = Constants.AI_TILE_SIZE
Left = double.Parse(coordsStr[1]),
Top = double.Parse(coordsStr[2]),
Width = double.Parse(coordsStr[0]),
Height = double.Parse(coordsStr[0])
};
return _splitTile;
}
+1 -1
View File
@@ -6,5 +6,5 @@ public static class SizeExtensions
{
public static bool FitSizeForAI(this Size size) =>
// Allow to be up to FullHD to save as 1280*1280
size.Width <= Constants.AI_TILE_SIZE * 1.5 && size.Height <= Constants.AI_TILE_SIZE * 1.5;
size.Width <= Constants.AI_TILE_SIZE_DEFAULT * 1.5 && size.Height <= Constants.AI_TILE_SIZE_DEFAULT * 1.5;
}
@@ -7,50 +7,44 @@ namespace Azaion.Common.Services.Inference;
public interface IInferenceService
{
Task RunInference(List<string> mediaPaths, CancellationToken ct = default);
Task RunInference(List<string> mediaPaths, int tileSize, CancellationToken ct = default);
CancellationTokenSource InferenceCancelTokenSource { get; set; }
void StopInference();
}
// SHOULD BE ONLY ONE INSTANCE OF InferenceService. Do not add ANY NotificationHandler to it!
// _inferenceCancelTokenSource should be created only once.
public class InferenceService : IInferenceService
public class InferenceService(
IInferenceClient client,
IAzaionApi azaionApi,
IOptions<AIRecognitionConfig> aiConfigOptions) : IInferenceService
{
private readonly IInferenceClient _client;
private readonly IAzaionApi _azaionApi;
private readonly IOptions<AIRecognitionConfig> _aiConfigOptions;
public CancellationTokenSource InferenceCancelTokenSource { get; set; } = new();
public CancellationTokenSource CheckAIAvailabilityTokenSource { get; set; } = new();
public InferenceService(IInferenceClient client, IAzaionApi azaionApi, IOptions<AIRecognitionConfig> aiConfigOptions)
{
_client = client;
_azaionApi = azaionApi;
_aiConfigOptions = aiConfigOptions;
}
public async Task CheckAIAvailabilityStatus()
{
CheckAIAvailabilityTokenSource = new CancellationTokenSource();
while (!CheckAIAvailabilityTokenSource.IsCancellationRequested)
{
_client.Send(RemoteCommand.Create(CommandType.AIAvailabilityCheck));
client.Send(RemoteCommand.Create(CommandType.AIAvailabilityCheck));
await Task.Delay(10000, CheckAIAvailabilityTokenSource.Token);
}
}
public async Task RunInference(List<string> mediaPaths, CancellationToken ct = default)
public async Task RunInference(List<string> mediaPaths, int tileSize, CancellationToken ct = default)
{
InferenceCancelTokenSource = new CancellationTokenSource();
_client.Send(RemoteCommand.Create(CommandType.Login, _azaionApi.Credentials));
client.Send(RemoteCommand.Create(CommandType.Login, azaionApi.Credentials));
var aiConfig = _aiConfigOptions.Value;
var aiConfig = aiConfigOptions.Value;
aiConfig.Paths = mediaPaths;
_client.Send(RemoteCommand.Create(CommandType.Inference, aiConfig));
aiConfig.TileSize = tileSize;
client.Send(RemoteCommand.Create(CommandType.Inference, aiConfig));
using var combinedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(ct, InferenceCancelTokenSource.Token);
await combinedTokenSource.Token.AsTask();
}
public void StopInference() => _client.Stop();
public void StopInference() => client.Stop();
}
+4 -10
View File
@@ -4,16 +4,10 @@ using Azaion.Common.DTO;
namespace Azaion.Common.Services;
public class TileResult
public class TileResult(CanvasLabel tile, List<CanvasLabel> detections)
{
public CanvasLabel Tile { get; set; }
public List<CanvasLabel> Detections { get; set; }
public TileResult(CanvasLabel tile, List<CanvasLabel> detections)
{
Tile = tile;
Detections = detections;
}
public CanvasLabel Tile { get; set; } = tile;
public List<CanvasLabel> Detections { get; set; } = detections;
}
public static class TileProcessor
@@ -41,7 +35,7 @@ public static class TileProcessor
private static TileResult GetDetectionsInTile(Size originalSize, CanvasLabel startDet, List<CanvasLabel> allDetections)
{
var tile = new CanvasLabel(startDet.Left, startDet.Right, startDet.Top, startDet.Bottom);
var maxSize = new List<double> { startDet.Width + BORDER, startDet.Height + BORDER, Constants.AI_TILE_SIZE }.Max();
var maxSize = new List<double> { startDet.Width + BORDER, startDet.Height + BORDER, Constants.AI_TILE_SIZE_DEFAULT }.Max();
var selectedDetections = new List<CanvasLabel>{startDet};
foreach (var det in allDetections)