mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 09:46:30 +00:00
fix dataset explorer
This commit is contained in:
@@ -273,7 +273,7 @@ public partial class DatasetExplorer
|
||||
var thumbnailDtos = new List<ThumbnailDto>();
|
||||
for (int i = 0; i < thumbnails.Length; i++)
|
||||
{
|
||||
var thumbnailDto = GetThumbnail(thumbnails[i]);
|
||||
var thumbnailDto = await GetThumbnail(thumbnails[i]);
|
||||
if (thumbnailDto != null)
|
||||
thumbnailDtos.Add(thumbnailDto);
|
||||
|
||||
@@ -289,12 +289,14 @@ public partial class DatasetExplorer
|
||||
LoadingAnnsBar.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private ThumbnailDto? GetThumbnail(string thumbnail)
|
||||
private async Task<ThumbnailDto?> GetThumbnail(string thumbnail)
|
||||
{
|
||||
try
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(thumbnail)[..^Config.THUMBNAIL_PREFIX.Length];
|
||||
var imagePath = Path.Combine(_config.ImagesDirectory, name);
|
||||
var labelPath = Path.Combine(_config.LabelsDirectory, $"{name}.txt");
|
||||
|
||||
foreach (var f in _config.ImageFormats)
|
||||
{
|
||||
var curName = $"{imagePath}.{f}";
|
||||
@@ -305,25 +307,21 @@ public partial class DatasetExplorer
|
||||
}
|
||||
}
|
||||
|
||||
var labelPath = Path.Combine(_config.LabelsDirectory, $"{name}.txt");
|
||||
|
||||
if (!_galleryManager.LabelsCache.TryGetValue(Path.GetFileName(imagePath), out var info))
|
||||
{
|
||||
if (File.Exists(labelPath))
|
||||
return null;
|
||||
|
||||
var imageExists = File.Exists(imagePath);
|
||||
if (!imageExists)
|
||||
if (!File.Exists(imagePath) || !File.Exists(labelPath))
|
||||
{
|
||||
File.Delete(thumbnail);
|
||||
_logger.LogError($"No label {labelPath} found ! Image {imagePath} not found, thumbnail {thumbnail} was removed");
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Move(imagePath, Path.Combine(_config.UnknownImages, imagePath));
|
||||
_logger.LogError($"No label {labelPath} found! But Image {imagePath} exists! Image moved to {_config.UnknownImages} directory!");
|
||||
}
|
||||
return null;
|
||||
|
||||
var classes = (await YoloLabel.ReadFromFile(labelPath))
|
||||
.Select(x => x.ClassNumber)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
info = _galleryManager.AddToCache(imagePath, classes);
|
||||
}
|
||||
|
||||
if (!info.Classes.Contains(ExplorerEditor.CurrentAnnClass.Id) && ExplorerEditor.CurrentAnnClass.Id != -1)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user