155 lines
10 KiB
XML
155 lines
10 KiB
XML
<UserControl xmlns="https://github.com/avaloniaui" xmlns:local="clr-namespace:SopHelper.Training" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SopHelper.Training.TrainingPage" xmlns:conv="using:Avalonia.Data.Converters">
|
||
<UserControl.Styles>
|
||
<StyleInclude Source="avares://SopHelper.Avalonia/Training/Styles.axaml" />
|
||
</UserControl.Styles>
|
||
<UserControl.Resources>
|
||
</UserControl.Resources>
|
||
<ScrollViewer Margin="12" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
|
||
<Grid Height="{Binding Viewport.Height, RelativeSource={RelativeSource AncestorType=ScrollViewer}}" MinWidth="1080" MinHeight="720">
|
||
<Grid.RowDefinitions>
|
||
<RowDefinition Height="Auto" />
|
||
<RowDefinition Height="*" />
|
||
<RowDefinition Height="176" />
|
||
<RowDefinition Height="Auto" />
|
||
</Grid.RowDefinitions>
|
||
<DockPanel Margin="0,0,0,14">
|
||
<StackPanel DockPanel.Dock="Left" Margin="0,0,28,0">
|
||
<TextBlock Text="零件标注与训练" FontSize="23" FontWeight="Bold" Foreground="{StaticResource Accent}" />
|
||
<TextBlock Text="视频 → 标注 → 复核 → YOLO" Foreground="{StaticResource Dim}" />
|
||
</StackPanel>
|
||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
|
||
<Button Content="相机与录像" Click="OpenCameraClicked" />
|
||
<Button Content="导入视频" Command="{Binding ImportCommand}" />
|
||
<Button Content="打开项目" Command="{Binding OpenCommand}" />
|
||
<Button Content="项目文件夹" Command="{Binding RevealCommand}" />
|
||
<Button Content="取消任务" Command="{Binding CancelCommand}" IsEnabled="{Binding IsBusy}" />
|
||
</StackPanel>
|
||
</DockPanel>
|
||
<Grid Grid.Row="1">
|
||
<Grid.ColumnDefinitions>
|
||
<ColumnDefinition Width="220" />
|
||
<ColumnDefinition Width="12" />
|
||
<ColumnDefinition Width="*" />
|
||
<ColumnDefinition Width="12" />
|
||
<ColumnDefinition Width="330" />
|
||
</Grid.ColumnDefinitions>
|
||
<DockPanel>
|
||
<StackPanel DockPanel.Dock="Top" Margin="0,0,0,10">
|
||
<TextBlock Text="视频帧" FontSize="16" FontWeight="Bold" />
|
||
<TextBlock Text="{Binding Summary}" Classes="Hint" />
|
||
</StackPanel>
|
||
<ListBox ItemsSource="{Binding Frames}" SelectedItem="{Binding SelectedFrame}" IsEnabled="{Binding IsIdle}">
|
||
<ListBox.ItemTemplate>
|
||
<DataTemplate>
|
||
<TextBlock Text="{Binding Display}" FontSize="12" />
|
||
</DataTemplate>
|
||
</ListBox.ItemTemplate>
|
||
</ListBox>
|
||
</DockPanel>
|
||
<Grid Grid.Column="2">
|
||
<Grid.RowDefinitions>
|
||
<RowDefinition Height="Auto" />
|
||
<RowDefinition Height="*" />
|
||
<RowDefinition Height="Auto" />
|
||
<RowDefinition Height="Auto" />
|
||
</Grid.RowDefinitions>
|
||
<TextBlock Text="{Binding FrameInfo}" Margin="0,0,0,10" TextWrapping="Wrap" />
|
||
<Border Grid.Row="1" Background="#080E14" BorderBrush="{StaticResource Line}" BorderThickness="1" CornerRadius="6" ClipToBounds="True" Classes="panel">
|
||
<local:AnnotationCanvas x:Name="Canvas" Source="{Binding Preview}" Box="{Binding CurrentBox}" IsEnabled="{Binding IsIdle}" />
|
||
</Border>
|
||
<WrapPanel Grid.Row="2" Margin="0,12,0,0">
|
||
<Button Content="← 上一帧" Command="{Binding PreviousCommand}" />
|
||
<Button Content="下一帧 →" Command="{Binding NextCommand}" />
|
||
<Button Content="确认当前框" Command="{Binding ApproveCommand}" />
|
||
<Button Content="一键复核" Command="{Binding ApproveAllCommand}" ToolTip.Tip="确认本项目中所有带目标框的待复核帧,并立即保存" />
|
||
<Button Content="无目标" Command="{Binding AbsentCommand}" />
|
||
<Button Content="排除此帧" Command="{Binding ExcludeCommand}" />
|
||
</WrapPanel>
|
||
<TextBlock Grid.Row="3" Text="拖动画框或修正,自动保存为关键帧。← → 切帧,Enter 确认当前框并进入下一帧。" Classes="Hint" />
|
||
</Grid>
|
||
<TabControl Grid.Column="4" IsEnabled="{Binding IsIdle}">
|
||
<TabItem Header="标注">
|
||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||
<StackPanel>
|
||
<TextBlock Text="01 导入旋转视频" FontWeight="Bold" Foreground="{StaticResource Accent}" />
|
||
<TextBlock Text="零件类别名称" Margin="0,12,0,0" />
|
||
<TextBox Text="{Binding Label, Mode=TwoWay}" />
|
||
<TextBlock Text="抽帧间隔(原视频帧数)" />
|
||
<TextBox Text="{Binding ExtractStride, Mode=TwoWay}" />
|
||
<TextBlock Text="最多导入帧数" />
|
||
<TextBox Text="{Binding MaxFrames, Mode=TwoWay}" />
|
||
<TextBlock Text="默认最多600帧;长视频会自动增大间隔覆盖全片。快速旋转建议分成短片导入。" Classes="Hint" />
|
||
<TextBlock Text="02 画框并自动传播" FontWeight="Bold" Foreground="{StaticResource Accent}" Margin="0,10,0,8" />
|
||
<Button Content="开始 SAM2 传播" Command="{Binding PropagateCommand}" BorderBrush="{StaticResource Accent}" />
|
||
<TextBlock Text="先在清晰帧画一个框。旋转幅度大时,可在多个角度补框后再运行。传播保留已复核帧。" Classes="Hint" />
|
||
<TextBlock Text="03 人工复核" FontWeight="Bold" Foreground="{StaticResource Accent}" />
|
||
<TextBlock Text="逐帧确认目标框;框偏了直接重画。无目标用于负样本,排除帧不参与训练。只导出已复核数据。" Classes="Hint" />
|
||
</StackPanel>
|
||
</ScrollViewer>
|
||
</TabItem>
|
||
<TabItem Header="训练">
|
||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||
<StackPanel>
|
||
<TextBlock Text="YOLO 目标检测训练" FontSize="16" FontWeight="Bold" />
|
||
<TextBlock Text="按时间分段:前段训练、末尾20%验证,边界留出间隔。正式评估请另拍独立测试视频。" Classes="Hint" />
|
||
<TextBlock Text="训练抽样间隔(导入后的帧数)" />
|
||
<TextBox Text="{Binding ExportEvery, Mode=TwoWay}" />
|
||
<TextBlock Text="YOLO 初始模型 / 本地 .pt 路径" />
|
||
<TextBox Text="{Binding Model, Mode=TwoWay}" />
|
||
<TextBlock Text="训练轮数" />
|
||
<TextBox Text="{Binding Epochs, Mode=TwoWay}" />
|
||
<TextBlock Text="图像尺寸(32的倍数)" />
|
||
<TextBox Text="{Binding ImageSize, Mode=TwoWay}" />
|
||
<TextBlock Text="批次大小" />
|
||
<TextBox Text="{Binding Batch, Mode=TwoWay}" />
|
||
<Button Content="导出 YOLO 数据集" Command="{Binding ExportCommand}" />
|
||
<Button Content="开始训练" Command="{Binding TrainCommand}" BorderBrush="{StaticResource Accent}" />
|
||
<Button Content="导出最新模型为 ONNX" Command="{Binding OnnxCommand}" />
|
||
<TextBlock Text="每次训练重新导出当前复核数据。best.pt、ONNX 和训练指标保存在项目 runs 文件夹。默认 yolo11n,检测框格式便于接入 SopHelper,仍需现场验证。" Classes="Hint" />
|
||
</StackPanel>
|
||
</ScrollViewer>
|
||
</TabItem>
|
||
<TabItem Header="设置">
|
||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||
<StackPanel>
|
||
<Button Content="检查环境与 CUDA" Command="{Binding DoctorCommand}" />
|
||
<TextBlock Text="设备:auto / cpu / cuda(训练可填0)" />
|
||
<TextBox Text="{Binding Device, Mode=TwoWay}" />
|
||
<TextBlock Text="SAM2 checkpoint(留空自动下载 tiny)" />
|
||
<TextBox Text="{Binding Checkpoint, Mode=TwoWay}" />
|
||
<TextBlock Text="SAM2 配置(仅本地 checkpoint 使用)" />
|
||
<TextBox Text="{Binding SamConfig, Mode=TwoWay}" />
|
||
<TextBlock Text="可选:视觉大模型建议框" FontWeight="Bold" Margin="0,12,0,0" />
|
||
<TextBlock Text="兼容 chat/completions 的视觉接口。点击时会上传当前帧到下方地址;结果需人工确认,再用于 SAM2 传播。" Classes="Hint" />
|
||
<TextBlock Text="API Base URL(包含 /v1,不含 /chat/completions)" />
|
||
<TextBox Text="{Binding Endpoint, Mode=TwoWay}" />
|
||
<TextBlock Text="视觉模型名称" />
|
||
<TextBox Text="{Binding ApiModel, Mode=TwoWay}" />
|
||
<TextBlock Text="API Key(仅本次运行,不写入项目)" />
|
||
<TextBox x:Name="ApiKey" PasswordChar="●" />
|
||
<TextBlock Text="零件外观描述" />
|
||
<TextBox Text="{Binding Description, Mode=TwoWay}" AcceptsReturn="True" Height="64" TextWrapping="Wrap" />
|
||
<Button Content="让视觉模型建议当前帧目标框" Command="{Binding SuggestCommand}" />
|
||
</StackPanel>
|
||
</ScrollViewer>
|
||
</TabItem>
|
||
</TabControl>
|
||
</Grid>
|
||
<Grid Grid.Row="2" Margin="0,12,0,0">
|
||
<Grid.RowDefinitions>
|
||
<RowDefinition Height="Auto" />
|
||
<RowDefinition Height="*" />
|
||
</Grid.RowDefinitions>
|
||
<DockPanel>
|
||
<TextBlock Text="运行日志" Foreground="{StaticResource Dim}" />
|
||
<TextBlock Text="{Binding ProjectPath}" TextTrimming="CharacterEllipsis" HorizontalAlignment="Right" MaxWidth="850" Foreground="{StaticResource Dim}" />
|
||
</DockPanel>
|
||
<TextBox x:Name="LogBox" Grid.Row="1" Text="{Binding Logs, Mode=OneWay}" IsReadOnly="True" TextWrapping="Wrap" ScrollViewer.VerticalScrollBarVisibility="Auto" FontFamily="Consolas, Microsoft YaHei" TextChanged="LogChanged" Margin="0,6,0,0" />
|
||
</Grid>
|
||
<DockPanel Grid.Row="3" Margin="0,10,0,0">
|
||
<ProgressBar DockPanel.Dock="Right" Width="180" Height="5" Value="{Binding Progress}" Foreground="{StaticResource Accent}" Background="{StaticResource Line}" />
|
||
<TextBlock Text="{Binding Status}" TextTrimming="CharacterEllipsis" Margin="0,0,15,0" />
|
||
</DockPanel>
|
||
</Grid>
|
||
</ScrollViewer>
|
||
</UserControl> |