mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 01:16:31 +00:00
fix dataset explorer
This commit is contained in:
@@ -273,7 +273,7 @@ public partial class DatasetExplorer
|
|||||||
var thumbnailDtos = new List<ThumbnailDto>();
|
var thumbnailDtos = new List<ThumbnailDto>();
|
||||||
for (int i = 0; i < thumbnails.Length; i++)
|
for (int i = 0; i < thumbnails.Length; i++)
|
||||||
{
|
{
|
||||||
var thumbnailDto = GetThumbnail(thumbnails[i]);
|
var thumbnailDto = await GetThumbnail(thumbnails[i]);
|
||||||
if (thumbnailDto != null)
|
if (thumbnailDto != null)
|
||||||
thumbnailDtos.Add(thumbnailDto);
|
thumbnailDtos.Add(thumbnailDto);
|
||||||
|
|
||||||
@@ -289,12 +289,14 @@ public partial class DatasetExplorer
|
|||||||
LoadingAnnsBar.Visibility = Visibility.Collapsed;
|
LoadingAnnsBar.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ThumbnailDto? GetThumbnail(string thumbnail)
|
private async Task<ThumbnailDto?> GetThumbnail(string thumbnail)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var name = Path.GetFileNameWithoutExtension(thumbnail)[..^Config.THUMBNAIL_PREFIX.Length];
|
var name = Path.GetFileNameWithoutExtension(thumbnail)[..^Config.THUMBNAIL_PREFIX.Length];
|
||||||
var imagePath = Path.Combine(_config.ImagesDirectory, name);
|
var imagePath = Path.Combine(_config.ImagesDirectory, name);
|
||||||
|
var labelPath = Path.Combine(_config.LabelsDirectory, $"{name}.txt");
|
||||||
|
|
||||||
foreach (var f in _config.ImageFormats)
|
foreach (var f in _config.ImageFormats)
|
||||||
{
|
{
|
||||||
var curName = $"{imagePath}.{f}";
|
var curName = $"{imagePath}.{f}";
|
||||||
@@ -305,27 +307,23 @@ public partial class DatasetExplorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var labelPath = Path.Combine(_config.LabelsDirectory, $"{name}.txt");
|
|
||||||
|
|
||||||
if (!_galleryManager.LabelsCache.TryGetValue(Path.GetFileName(imagePath), out var info))
|
if (!_galleryManager.LabelsCache.TryGetValue(Path.GetFileName(imagePath), out var info))
|
||||||
{
|
{
|
||||||
if (File.Exists(labelPath))
|
if (!File.Exists(imagePath) || !File.Exists(labelPath))
|
||||||
return null;
|
|
||||||
|
|
||||||
var imageExists = File.Exists(imagePath);
|
|
||||||
if (!imageExists)
|
|
||||||
{
|
{
|
||||||
File.Delete(thumbnail);
|
File.Delete(thumbnail);
|
||||||
_logger.LogError($"No label {labelPath} found ! Image {imagePath} not found, thumbnail {thumbnail} was removed");
|
_logger.LogError($"No label {labelPath} found ! Image {imagePath} not found, thumbnail {thumbnail} was removed");
|
||||||
}
|
|
||||||
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;
|
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)
|
if (!info.Classes.Contains(ExplorerEditor.CurrentAnnClass.Id) && ExplorerEditor.CurrentAnnClass.Id != -1)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|||||||
@@ -148,20 +148,17 @@ public class GalleryManager : IGalleryManager
|
|||||||
_logger.LogInformation($"No labels found for image {imgName}! Image deleted!");
|
_logger.LogInformation($"No labels found for image {imgName}! Image deleted!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var labels = (await YoloLabel.ReadFromFile(labelName, cancellationToken))
|
var labels = (await YoloLabel.ReadFromFile(labelName, cancellationToken))
|
||||||
.Select(x => new CanvasLabel(x, size, size))
|
.Select(x => new CanvasLabel(x, size, size))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
var classes = labels.Select(x => x.ClassNumber).Distinct().ToList();
|
||||||
|
|
||||||
|
AddToCache(imgPath, classes);
|
||||||
|
|
||||||
var thumbWhRatio = width / (float)height;
|
var thumbWhRatio = width / (float)height;
|
||||||
var border = _config.ThumbnailConfig.Border;
|
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 frameX = 0.0;
|
||||||
var frameY = 0.0;
|
var frameY = 0.0;
|
||||||
var frameHeight = size.Height;
|
var frameHeight = size.Height;
|
||||||
@@ -223,6 +220,20 @@ public class GalleryManager : IGalleryManager
|
|||||||
return null;
|
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
|
public interface IGalleryManager
|
||||||
@@ -230,6 +241,7 @@ public interface IGalleryManager
|
|||||||
event ThumbnailsUpdatedEventHandler ThumbnailsUpdate;
|
event ThumbnailsUpdatedEventHandler ThumbnailsUpdate;
|
||||||
double ThumbnailsPercentage { get; set; }
|
double ThumbnailsPercentage { get; set; }
|
||||||
Task SaveLabelsCache();
|
Task SaveLabelsCache();
|
||||||
|
LabelInfo AddToCache(string imgPath, List<int> classes);
|
||||||
ConcurrentDictionary<string, LabelInfo> LabelsCache { get; set; }
|
ConcurrentDictionary<string, LabelInfo> LabelsCache { get; set; }
|
||||||
Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
|
Task<ThumbnailDto?> CreateThumbnail(string imgPath, CancellationToken cancellationToken = default);
|
||||||
Task RefreshThumbnails();
|
Task RefreshThumbnails();
|
||||||
|
|||||||
Reference in New Issue
Block a user