From 6e5ab3030a82629a9549b2cb3dfa6dff8a640b9f Mon Sep 17 00:00:00 2001 From: KatterMaw Date: Thu, 28 Sep 2023 15:15:11 +0500 Subject: [PATCH] Create DataTemplate for Weights, ToolTip looks good, but general info is a mess; DataTemplate stored in App.xaml because i didnt found the way to store it in separate file, as it can be stored in dictionary, but resources in dictionary must have x:Key, which isn't suitable --- SightKeeper.Avalonia/App.axaml | 57 ++++++++++++++++++- SightKeeper.Avalonia/AppBootstrapper.cs | 1 + .../Annotating/AnnotatorViewModel.cs | 1 + .../AutoAnnotationViewModel.cs | 9 ++- .../FakeAutoAnnotationViewModel.cs | 27 +++++++++ .../IAutoAnnotationViewModel.cs | 17 ++++++ .../Annotating/FakeAnnotatorViewModel.cs | 1 + .../Annotating/IAnnotatorViewModel.cs | 1 + .../Views/Annotating/AutoAnnotation.axaml | 9 ++- .../Views/Annotating/AutoAnnotation.axaml.cs | 2 +- 10 files changed, 117 insertions(+), 8 deletions(-) rename SightKeeper.Avalonia/ViewModels/Annotating/{ => AutoAnnotating}/AutoAnnotationViewModel.cs (93%) create mode 100644 SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/FakeAutoAnnotationViewModel.cs create mode 100644 SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/IAutoAnnotationViewModel.cs diff --git a/SightKeeper.Avalonia/App.axaml b/SightKeeper.Avalonia/App.axaml index 5a319d68..bbc637eb 100644 --- a/SightKeeper.Avalonia/App.axaml +++ b/SightKeeper.Avalonia/App.axaml @@ -3,6 +3,7 @@ x:Class="SightKeeper.Avalonia.App" xmlns:materialIcons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" xmlns:local="clr-namespace:SightKeeper.Avalonia" + xmlns:model="clr-namespace:SightKeeper.Domain.Model;assembly=SightKeeper.Domain.Model" RequestedThemeVariant="Dark"> @@ -20,9 +21,63 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SightKeeper.Avalonia/AppBootstrapper.cs b/SightKeeper.Avalonia/AppBootstrapper.cs index 0bfee810..249e3774 100644 --- a/SightKeeper.Avalonia/AppBootstrapper.cs +++ b/SightKeeper.Avalonia/AppBootstrapper.cs @@ -16,6 +16,7 @@ using SightKeeper.Application.Training; using SightKeeper.Avalonia.Misc; using SightKeeper.Avalonia.ViewModels.Annotating; +using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; using SightKeeper.Avalonia.ViewModels.Dialogs; using SightKeeper.Avalonia.ViewModels.Dialogs.DataSet; using SightKeeper.Avalonia.ViewModels.Elements; diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/AnnotatorViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/AnnotatorViewModel.cs index b5efa839..80c5d955 100644 --- a/SightKeeper.Avalonia/ViewModels/Annotating/AnnotatorViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Annotating/AnnotatorViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reactive.Disposables; +using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; using SightKeeper.Avalonia.ViewModels.Elements; using SightKeeper.Commons; diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotationViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/AutoAnnotationViewModel.cs similarity index 93% rename from SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotationViewModel.cs rename to SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/AutoAnnotationViewModel.cs index c775feba..7a1b6498 100644 --- a/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotationViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/AutoAnnotationViewModel.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using System.Windows.Input; using CommunityToolkit.Diagnostics; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -11,9 +12,9 @@ using SightKeeper.Domain.Model; using SightKeeper.Domain.Model.Detector; -namespace SightKeeper.Avalonia.ViewModels.Annotating; +namespace SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; -public sealed partial class AutoAnnotationViewModel : ViewModel +public sealed partial class AutoAnnotationViewModel : ViewModel, IAutoAnnotationViewModel { public IReadOnlyCollection Weights => _selectedDataSetViewModel.Weights; @@ -62,6 +63,7 @@ public AutoAnnotationViewModel(Detector detector, SelectedScreenshotViewModel se private readonly SelectedScreenshotViewModel _selectedScreenshotViewModel; private readonly SelectedDataSetViewModel _selectedDataSetViewModel; + ICommand IAutoAnnotationViewModel.AnnotateCommand => AnnotateCommand; [RelayCommand(CanExecute = nameof(CanAnnotate))] private async Task Annotate(CancellationToken cancellationToken) { @@ -74,7 +76,8 @@ private async Task Annotate(CancellationToken cancellationToken) ClearCommand.NotifyCanExecuteChanged(); } private bool CanAnnotate() => SelectedWeights != null && _selectedScreenshotViewModel.Value != null && !AutoAnnotatingEnabled; - + + ICommand IAutoAnnotationViewModel.ClearCommand => ClearCommand; [RelayCommand(CanExecute = nameof(CanClear))] private void Clear() { diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/FakeAutoAnnotationViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/FakeAutoAnnotationViewModel.cs new file mode 100644 index 00000000..5704db7d --- /dev/null +++ b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/FakeAutoAnnotationViewModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Input; +using SightKeeper.Domain.Model; +using SightKeeper.Domain.Model.Common; + +namespace SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; + +public sealed class FakeAutoAnnotationViewModel : IAutoAnnotationViewModel +{ + public IReadOnlyCollection Weights { get; } + public float ProbabilityThreshold { get; set; } + public float IoU { get; set; } + public Weights? SelectedWeights { get; set; } + public bool AutoAnnotatingEnabled { get; set; } + public ICommand ClearCommand => FakeViewModel.CommandSubstitute; + public ICommand AnnotateCommand => FakeViewModel.CommandSubstitute; + + public FakeAutoAnnotationViewModel() + { + DataSet dataSet = new(""); + dataSet.WeightsLibrary.CreateWeights(Array.Empty(), Array.Empty(), ModelSize.Nano, 100, 1.123f, 0.2345f, 2.3456f, Enumerable.Empty()); + dataSet.WeightsLibrary.CreateWeights(Array.Empty(), Array.Empty(), ModelSize.Small, 200, 0.623f, 0.6445f, 0.3646f, Enumerable.Empty()); + Weights = dataSet.WeightsLibrary.Weights; + } +} \ No newline at end of file diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/IAutoAnnotationViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/IAutoAnnotationViewModel.cs new file mode 100644 index 00000000..553778ce --- /dev/null +++ b/SightKeeper.Avalonia/ViewModels/Annotating/AutoAnnotating/IAutoAnnotationViewModel.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Windows.Input; +using SightKeeper.Domain.Model; + +namespace SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; + +public interface IAutoAnnotationViewModel +{ + IReadOnlyCollection Weights { get; } + float ProbabilityThreshold { get; set; } + float IoU { get; set; } + Weights? SelectedWeights { get; set; } + bool AutoAnnotatingEnabled { get; set; } + + ICommand ClearCommand { get; } + ICommand AnnotateCommand { get; } +} \ No newline at end of file diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/FakeAnnotatorViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/FakeAnnotatorViewModel.cs index 3d4a9be7..6a66f918 100644 --- a/SightKeeper.Avalonia/ViewModels/Annotating/FakeAnnotatorViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Annotating/FakeAnnotatorViewModel.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using NSubstitute; +using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; using SightKeeper.Avalonia.ViewModels.Elements; using SightKeeper.Domain.Model; using SightKeeper.Domain.Services; diff --git a/SightKeeper.Avalonia/ViewModels/Annotating/IAnnotatorViewModel.cs b/SightKeeper.Avalonia/ViewModels/Annotating/IAnnotatorViewModel.cs index 32d0481a..8b39e4e5 100644 --- a/SightKeeper.Avalonia/ViewModels/Annotating/IAnnotatorViewModel.cs +++ b/SightKeeper.Avalonia/ViewModels/Annotating/IAnnotatorViewModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; using SightKeeper.Avalonia.ViewModels.Elements; namespace SightKeeper.Avalonia.ViewModels.Annotating; diff --git a/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml b/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml index 3cdb89dc..423e5529 100644 --- a/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml +++ b/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml @@ -2,11 +2,14 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:annotatingViewModels="clr-namespace:SightKeeper.Avalonia.ViewModels.Annotating" xmlns:icons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" - mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + xmlns:autoAnnotatingViewModels="clr-namespace:SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating" + mc:Ignorable="d" d:DesignWidth="250" x:Class="SightKeeper.Avalonia.Views.Annotating.AutoAnnotation" - x:DataType="annotatingViewModels:AutoAnnotationViewModel"> + x:DataType="autoAnnotatingViewModels:IAutoAnnotationViewModel"> + + + diff --git a/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml.cs b/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml.cs index 0ccc435e..23f8e852 100644 --- a/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml.cs +++ b/SightKeeper.Avalonia/Views/Annotating/AutoAnnotation.axaml.cs @@ -1,5 +1,5 @@ using Avalonia.ReactiveUI; -using SightKeeper.Avalonia.ViewModels.Annotating; +using SightKeeper.Avalonia.ViewModels.Annotating.AutoAnnotating; namespace SightKeeper.Avalonia.Views.Annotating;