新增标注与训练参数保存按钮

This commit is contained in:
tfarcraw 2026-11-09 11:01:07 +08:00
parent c7aab2f96e
commit ef41b97037
3 changed files with 15 additions and 1 deletions

View File

@ -97,6 +97,7 @@ public sealed class MainViewModel : BindableBase
public Func<string>? ReadApiKey { get; set; }
public DelegateCommand ImportCommand { get; }
public DelegateCommand OpenCommand { get; }
public DelegateCommand SaveParametersCommand { get; }
public DelegateCommand DoctorCommand { get; }
public DelegateCommand PropagateCommand { get; }
public DelegateCommand ExportCommand { get; }
@ -123,6 +124,11 @@ public sealed class MainViewModel : BindableBase
while (directory.Parent != null && !File.Exists(Path.Combine(directory.FullName, "SopHelper.Avalonia.slnx"))) directory = directory.Parent;
Root = File.Exists(Path.Combine(directory.FullName, "SopHelper.Avalonia.slnx")) ? directory.FullName : AppContext.BaseDirectory;
LoadSettings();
SaveParametersCommand = Command(() =>
{
SaveSettings();
Status = "参数已保存,下次打开时自动恢复";
});
ImportCommand = Command(Import);
OpenCommand = Command(async () =>
{

View File

@ -21,6 +21,7 @@
<Button Content="相机与录像" Click="OpenCameraClicked" />
<Button Content="导入视频" Command="{Binding ImportCommand}" />
<Button Content="打开项目" Command="{Binding OpenCommand}" />
<Button Content="保存参数" Command="{Binding SaveParametersCommand}" ToolTip.Tip="保存标注、训练和设置参数,下次打开时自动恢复" />
<Button Content="项目文件夹" Command="{Binding RevealCommand}" />
<Button Content="取消任务" Command="{Binding CancelCommand}" IsEnabled="{Binding IsBusy}" />
</StackPanel>
@ -158,4 +159,4 @@
</DockPanel>
</Grid>
</ScrollViewer>
</UserControl>
</UserControl>

View File

@ -111,6 +111,13 @@ internal static class Smoke
var trainer=app.Container.Resolve<SopHelper.Training.MainViewModel>();
Check(trainer.Recipes.Contains(Path.GetFileNameWithoutExtension(sop.SelectedRecipe)!) && trainer.RecipeName==Path.GetFileNameWithoutExtension(sop.SelectedRecipe),"Training offers the current SOP recipe automatically");
var trainingView=window.GetVisualDescendants().OfType<TrainingPage>().Single();
var saveParameters=trainingView.GetVisualDescendants().OfType<Button>().Single(b=>b.Content?.ToString()=="保存参数");
Check(ReferenceEquals(saveParameters.Command,trainer.SaveParametersCommand)&&trainer.Project is null&&saveParameters.Command!.CanExecute(null),"Save parameters is available without an annotation project");
trainer.ExtractStride=3;trainer.MaxFrames=420;trainer.ExportEvery=2;trainer.ImageSize=960;trainer.Epochs=12;trainer.Batch=2;
saveParameters.Command!.Execute(null);
var restoredTrainer=new SopHelper.Training.MainViewModel(new WorkerClient());
Check(restoredTrainer.ExtractStride==3&&restoredTrainer.MaxFrames==420&&restoredTrainer.ExportEvery==2&&restoredTrainer.ImageSize==960&&restoredTrainer.Epochs==12&&restoredTrainer.Batch==2,"Explicit save restores annotation and training parameters in a new view model");
Check(trainer.Status=="参数已保存,下次打开时自动恢复"&&!trainer.IsBusy,"Saving confirms success without starting a worker task");
var trainingTabs=trainingView.GetVisualDescendants().OfType<TabControl>().Single();
trainingTabs.SelectedIndex=1;await Task.Delay(80);
Check(trainingView.GetVisualDescendants().OfType<Button>().Any(b=>b.Content?.ToString()=="训练并更新配方模型"),"Recipe model update action is visible on the training tab");