mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:06:30 +00:00
fix split tile size
rework inference events and handling todo: add Medias table and reflect recognition status there
This commit is contained in:
@@ -48,6 +48,8 @@ public enum CommandType
|
||||
DataBytes = 25,
|
||||
Inference = 30,
|
||||
InferenceData = 35,
|
||||
InferenceStatus = 37,
|
||||
InferenceDone = 38,
|
||||
StopInference = 40,
|
||||
AIAvailabilityCheck = 80,
|
||||
AIAvailabilityResult = 85,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using Azaion.Common.Database;
|
||||
using Azaion.Common.DTO;
|
||||
using MediatR;
|
||||
using MessagePack;
|
||||
@@ -49,7 +50,7 @@ public class InferenceClient : IInferenceClient
|
||||
Arguments = $"-p {_inferenceClientConfig.ZeroMqPort} -lp {_loaderClientConfig.ZeroMqPort} -a {_inferenceClientConfig.ApiUrl}",
|
||||
CreateNoWindow = true
|
||||
};
|
||||
process.Start();
|
||||
//process.Start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -75,7 +76,15 @@ public class InferenceClient : IInferenceClient
|
||||
switch (remoteCommand.CommandType)
|
||||
{
|
||||
case CommandType.InferenceData:
|
||||
await _mediator.Publish(new InferenceDataEvent(remoteCommand), ct);
|
||||
var annotationImage = MessagePackSerializer.Deserialize<AnnotationImage>(remoteCommand.Data, cancellationToken: ct);
|
||||
await _mediator.Publish(new InferenceDataEvent(annotationImage), ct);
|
||||
break;
|
||||
case CommandType.InferenceStatus:
|
||||
var statusEvent = MessagePackSerializer.Deserialize<InferenceStatusEvent>(remoteCommand.Data, cancellationToken: ct);
|
||||
await _mediator.Publish(statusEvent, ct);
|
||||
break;
|
||||
case CommandType.InferenceDone:
|
||||
await _mediator.Publish(new InferenceDoneEvent(), ct);
|
||||
break;
|
||||
case CommandType.AIAvailabilityResult:
|
||||
var aiAvailabilityStatus = MessagePackSerializer.Deserialize<AIAvailabilityStatusEvent>(remoteCommand.Data, cancellationToken: ct);
|
||||
|
||||
@@ -12,32 +12,23 @@ public class InferenceServiceEventHandler(IInferenceService inferenceService,
|
||||
IMediator mediator,
|
||||
ILogger<InferenceServiceEventHandler> logger) :
|
||||
INotificationHandler<InferenceDataEvent>,
|
||||
INotificationHandler<AIAvailabilityStatusEvent>
|
||||
INotificationHandler<InferenceStatusEvent>,
|
||||
INotificationHandler<InferenceDoneEvent>
|
||||
{
|
||||
|
||||
public async Task Handle(InferenceDataEvent e, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Command.Message == "DONE")
|
||||
{
|
||||
await inferenceService.InferenceCancelTokenSource.CancelAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var annImage = MessagePackSerializer.Deserialize<AnnotationImage>(e.Command.Data, cancellationToken: ct);
|
||||
var annotation = await annotationService.SaveAnnotation(annImage, ct);
|
||||
await mediator.Publish(new AnnotationAddedEvent(annotation), ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, ex.Message);
|
||||
}
|
||||
var annotation = await annotationService.SaveAnnotation(e.AnnotationImage, ct);
|
||||
await mediator.Publish(new AnnotationAddedEvent(annotation), ct);
|
||||
}
|
||||
|
||||
public async Task Handle(AIAvailabilityStatusEvent e, CancellationToken ct)
|
||||
public async Task Handle(InferenceStatusEvent e, CancellationToken ct)
|
||||
{
|
||||
await mediator.Publish(new SetStatusTextEvent($"{e.MediaName}: {e.DetectionsCount} detections"), ct);
|
||||
}
|
||||
|
||||
e.Status = AIAvailabilityEnum.Enabled;
|
||||
|
||||
public async Task Handle(InferenceDoneEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
await inferenceService.InferenceCancelTokenSource.CancelAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,22 @@
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.Database;
|
||||
using MediatR;
|
||||
using MessagePack;
|
||||
|
||||
namespace Azaion.Common.Services.Inference;
|
||||
|
||||
public class InferenceDataEvent(RemoteCommand command) : INotification
|
||||
public class InferenceDataEvent(AnnotationImage annotationImage) : INotification
|
||||
{
|
||||
public RemoteCommand Command { get; set; } = command;
|
||||
public AnnotationImage AnnotationImage { get; set; } = annotationImage;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class InferenceStatusEvent : INotification
|
||||
{
|
||||
[Key("mn")]
|
||||
public string MediaName { get; set; }
|
||||
|
||||
[Key("dc")]
|
||||
public int DetectionsCount { get; set; }
|
||||
}
|
||||
|
||||
public class InferenceDoneEvent : INotification;
|
||||
@@ -65,7 +65,7 @@ public static class TileProcessor
|
||||
tile.Left = Math.Max(0, Math.Min(originalSize.Width - maxSize, centerX - tile.Width / 2.0));
|
||||
tile.Top = Math.Max(0, Math.Min(originalSize.Height - maxSize, centerY - tile.Height / 2.0));
|
||||
|
||||
return new TileResult(tile, selectedDetections);
|
||||
return new TileResult( tile, selectedDetections);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user