From dba115e9d4ebe934a8c5d85f4ac989651b511079 Mon Sep 17 00:00:00 2001 From: Mark Otway Date: Wed, 13 Mar 2024 17:40:17 +0000 Subject: [PATCH 1/2] Use extra large thumbs for AI; they'll already be there and better result. --- .../Services/ImageRecognitionService.cs | 16 ++++++++-------- .../ObjectDetector.cs | 18 ++++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Damselfly.Core/Services/ImageRecognitionService.cs b/Damselfly.Core/Services/ImageRecognitionService.cs index b5b33927..543bea07 100644 --- a/Damselfly.Core/Services/ImageRecognitionService.cs +++ b/Damselfly.Core/Services/ImageRecognitionService.cs @@ -409,24 +409,24 @@ private async Task DetectObjects(ImageMetaData metadata) try { - var thumbSize = ThumbSize.Large; - var medThumb = new FileInfo(_thumbService.GetThumbPath(fileName, thumbSize)); + var thumbSize = ThumbSize.ExtraLarge; + var imgThumb = new FileInfo(_thumbService.GetThumbPath(fileName, thumbSize)); // We need a large thumbnail to do AI processing. Ensure it's been created. - if( ! medThumb.Exists ) + if( ! imgThumb.Exists ) { await _thumbService.CreateThumb(image.ImageId, thumbSize); - if( ! File.Exists( medThumb.FullName ) ) + if( ! File.Exists( imgThumb.FullName ) ) { // If we couldn't create the thumb, bail out. throw new InvalidOperationException( - $"Unable to run AI processing - {thumbSize} thumbnail doesn't exist: {medThumb}"); + $"Unable to run AI processing - {thumbSize} thumbnail doesn't exist: {imgThumb}"); } } var enableAIProcessing = _configService.GetBool(ConfigSettings.EnableAIProcessing, true); - MetaDataService.GetImageSize(medThumb.FullName, out var thumbWidth, out var thumbHeight); + MetaDataService.GetImageSize(imgThumb.FullName, out var thumbWidth, out var thumbHeight); var foundObjects = new List(); var foundFaces = new List(); @@ -434,11 +434,11 @@ private async Task DetectObjects(ImageMetaData metadata) if ( enableAIProcessing ) Logging.Log($"Processing AI image detection for {fileName.Name}..."); - if ( !File.Exists(medThumb.FullName) ) + if ( !File.Exists(imgThumb.FullName) ) // The thumb isn't ready yet. return; - using var theImage = SixLabors.ImageSharp.Image.Load(medThumb.FullName); + using var theImage = SixLabors.ImageSharp.Image.Load(imgThumb.FullName); if ( _imageClassifier != null && enableAIProcessing ) { diff --git a/Damselfly.ML.ObjectDetection.ML/ObjectDetector.cs b/Damselfly.ML.ObjectDetection.ML/ObjectDetector.cs index edaf116e..831fd70a 100644 --- a/Damselfly.ML.ObjectDetection.ML/ObjectDetector.cs +++ b/Damselfly.ML.ObjectDetection.ML/ObjectDetector.cs @@ -44,19 +44,21 @@ public Task> DetectObjects(Image image) { if( scorer != null ) { - var watch = new Stopwatch( "DetectObjects" ); - var predictions = scorer.Predict( image ); - - watch.Stop(); + // There's a min of 640x640 for the model. + if( image.Width > 640 && image.Height > 640 ) + { + var predictions = scorer.Predict( image ); - var objectsFound = predictions.Where( x => x.Score > predictionThreshold ) - .Select( x => MakeResult( x ) ) - .ToList(); + watch.Stop(); - result = objectsFound; + var objectsFound = predictions.Where( x => x.Score > predictionThreshold ) + .Select( x => MakeResult( x ) ) + .ToList(); + result = objectsFound; + } } } catch ( Exception ex ) From 6993664531a93ea3ae938361fe2f0c9188572857 Mon Sep 17 00:00:00 2001 From: Mark Otway Date: Thu, 14 Mar 2024 07:38:26 +0000 Subject: [PATCH 2/2] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 627a3f43..4d0dcda0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.1 +4.1.2