fix dataset explorer

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-05 22:24:46 +02:00
parent 5d537aeef6
commit 36afeb7379
2 changed files with 33 additions and 23 deletions
+19 -7
View File
@@ -148,20 +148,17 @@ public class GalleryManager : IGalleryManager
_logger.LogInformation($"No labels found for image {imgName}! Image deleted!");
return null;
}
var labels = (await YoloLabel.ReadFromFile(labelName, cancellationToken))
.Select(x => new CanvasLabel(x, size, size))
.ToList();
var classes = labels.Select(x => x.ClassNumber).Distinct().ToList();
AddToCache(imgPath, classes);
var thumbWhRatio = width / (float)height;
var border = _config.ThumbnailConfig.Border;
var classes = labels.Select(x => x.ClassNumber).Distinct().ToList();
LabelsCache.TryAdd(imgName, new LabelInfo
{
Classes = classes,
ImageDateTime = File.GetCreationTimeUtc(imgPath)
});
var frameX = 0.0;
var frameY = 0.0;
var frameHeight = size.Height;
@@ -223,6 +220,20 @@ public class GalleryManager : IGalleryManager
return null;
}
}
public LabelInfo AddToCache(string imgPath, List<int> classes)
{
var labelInfo = new LabelInfo
{
Classes = classes,
ImageDateTime = File.GetCreationTimeUtc(imgPath)
};
LabelsCache.TryAdd(Path.GetFileName(imgPath), labelInfo);
//Save to file only each 2 seconds
_ = ThrottleExt.Throttle(async () => await SaveLabelsCache(), TimeSpan.FromSeconds(2));
return labelInfo;
}
}
public interface IGalleryManager
@@ -230,6 +241,7 @@ public interface IGalleryManager
event ThumbnailsUpdatedEventHandler ThumbnailsUpdate;
double ThumbnailsPercentage { get; set; }
Task SaveLabelsCache();
LabelInfo AddToCache(string imgPath, List<int> classes);
ConcurrentDictionary<string, LabelInfo> LabelsCache { get; set; }
Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
Task RefreshThumbnails();