Skip to content

Commit

Permalink
Use extra large thumbs for AI; they'll already be there and better re…
Browse files Browse the repository at this point in the history
…sult.
  • Loading branch information
Webreaper committed Mar 13, 2024
1 parent f1e6ce3 commit dba115e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
16 changes: 8 additions & 8 deletions Damselfly.Core/Services/ImageRecognitionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,36 +409,36 @@ 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<ImageObject>();
var foundFaces = new List<ImageObject>();

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<Rgb24>(medThumb.FullName);
using var theImage = SixLabors.ImageSharp.Image.Load<Rgb24>(imgThumb.FullName);

if ( _imageClassifier != null && enableAIProcessing )
{
Expand Down
18 changes: 10 additions & 8 deletions Damselfly.ML.ObjectDetection.ML/ObjectDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ public Task<IList<ImageDetectResult>> DetectObjects(Image<Rgb24> 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 )
Expand Down

0 comments on commit dba115e

Please sign in to comment.