From 94c8c6a842876532594b1fae04bf3431381a0f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89=E9=B8=AD=E8=9B=8B?= Date: Tue, 28 May 2024 19:08:28 +0800 Subject: [PATCH] modify device name --- BetterGenshinImpact/BetterGenshinImpact.csproj | 3 +-- .../Core/Recognition/OCR/PaddleOcrService.cs | 14 +++++++------- .../Core/Recognition/ONNX/BgiSessionOption.cs | 14 +++++++++++++- BetterGenshinImpact/GameTask/GameTaskManager.cs | 13 +++---------- BetterGenshinImpact/Model/Singleton.cs | 3 +-- BetterGenshinImpact/View/Pages/HomePage.xaml | 12 +++++++++--- .../ViewModel/Pages/HomePageViewModel.cs | 9 ++++++++- 7 files changed, 42 insertions(+), 26 deletions(-) diff --git a/BetterGenshinImpact/BetterGenshinImpact.csproj b/BetterGenshinImpact/BetterGenshinImpact.csproj index bb4ce89e..085b48d8 100644 --- a/BetterGenshinImpact/BetterGenshinImpact.csproj +++ b/BetterGenshinImpact/BetterGenshinImpact.csproj @@ -43,7 +43,6 @@ - @@ -55,7 +54,7 @@ - + diff --git a/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs b/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs index 9d9843b9..cbf49957 100644 --- a/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs +++ b/BetterGenshinImpact/Core/Recognition/OCR/PaddleOcrService.cs @@ -30,13 +30,13 @@ public class PaddleOcrService : IOcrService var localClsModel = ClassificationModel.FromDirectory(Path.Combine(path, "ch_ppocr_mobile_v2.0_cls")); var localRecModel = RecognizationModel.FromDirectory(Path.Combine(path, "ch_PP-OCRv4_rec"), Path.Combine(path, "ppocr_keys_v1.txt"), ModelVersion.V4); var model = new FullOcrModel(localDetModel, localClsModel, localRecModel); - Action device = TaskContext.Instance().Config.InferenceDevice switch - { - "CPU" => PaddleDevice.Onnx(), - "GPU" => PaddleDevice.Onnx(), - _ => throw new InvalidEnumArgumentException("无效的推理设备") - }; - _paddleOcrAll = new PaddleOcrAll(model, device) + // Action device = TaskContext.Instance().Config.InferenceDevice switch + // { + // "CPU" => PaddleDevice.Onnx(), + // "GPU_DirectML" => PaddleDevice.Onnx(), + // _ => throw new InvalidEnumArgumentException("无效的推理设备") + // }; + _paddleOcrAll = new PaddleOcrAll(model, PaddleDevice.Onnx()) { AllowRotateDetection = false, /* 允许识别有角度的文字 */ Enable180Classification = false /* 允许识别旋转角度大于90度的文字 */ diff --git a/BetterGenshinImpact/Core/Recognition/ONNX/BgiSessionOption.cs b/BetterGenshinImpact/Core/Recognition/ONNX/BgiSessionOption.cs index a0677414..6bd02057 100644 --- a/BetterGenshinImpact/Core/Recognition/ONNX/BgiSessionOption.cs +++ b/BetterGenshinImpact/Core/Recognition/ONNX/BgiSessionOption.cs @@ -7,10 +7,12 @@ namespace BetterGenshinImpact.Core.Recognition.ONNX; public class BgiSessionOption : Singleton { + public static string[] InferenceDeviceTypes { get; } = ["CPU", "GPU_DirectML"]; + public SessionOptions Options { get; set; } = TaskContext.Instance().Config.InferenceDevice switch { "CPU" => new SessionOptions(), - "GPU" => MakeSessionOptionWithDirectMlProvider(), + "GPU_DirectML" => MakeSessionOptionWithDirectMlProvider(), _ => throw new InvalidEnumArgumentException("无效的推理设备") }; @@ -20,4 +22,14 @@ public class BgiSessionOption : Singleton sessionOptions.AppendExecutionProvider_DML(0); return sessionOptions; } + + // /// + // /// 重新加载每个推理器(测试没用,只能重启) + // /// + // public void RefreshInference() + // { + // // 自动秘境每次都会NEW不用管 + // // Yap、自动钓鱼 + // GameTaskManager.RefreshTriggerConfigs(); + // } } diff --git a/BetterGenshinImpact/GameTask/GameTaskManager.cs b/BetterGenshinImpact/GameTask/GameTaskManager.cs index a3ff761b..6713a13e 100644 --- a/BetterGenshinImpact/GameTask/GameTaskManager.cs +++ b/BetterGenshinImpact/GameTask/GameTaskManager.cs @@ -56,17 +56,10 @@ internal class GameTaskManager { if (TriggerDictionary is { Count: > 0 }) { - TriggerDictionary["AutoPick"].IsEnabled = TaskContext.Instance().Config.AutoPickConfig.Enabled; - // 用于刷新AutoPick的黑白名单 TriggerDictionary["AutoPick"].Init(); - TriggerDictionary["AutoSkip"].IsEnabled = TaskContext.Instance().Config.AutoSkipConfig.Enabled; - TriggerDictionary["AutoFishing"].IsEnabled = TaskContext.Instance().Config.AutoFishingConfig.Enabled; - // 钓鱼有很多变量要初始化,直接重新newZA - if (TriggerDictionary["AutoFishing"].IsEnabled == false) - { - TriggerDictionary["AutoFishing"].Init(); - } - TriggerDictionary["QuickTeleport"].IsEnabled = TaskContext.Instance().Config.QuickTeleportConfig.Enabled; + TriggerDictionary["AutoSkip"].Init(); + TriggerDictionary["AutoFishing"].Init(); + TriggerDictionary["QuickTeleport"].Init(); TriggerDictionary["GameLoading"].Init(); TriggerDictionary["AutoCook"].Init(); // 清理画布 diff --git a/BetterGenshinImpact/Model/Singleton.cs b/BetterGenshinImpact/Model/Singleton.cs index 21db3d98..a0d11a14 100644 --- a/BetterGenshinImpact/Model/Singleton.cs +++ b/BetterGenshinImpact/Model/Singleton.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using System; +using System; using System.Threading; namespace BetterGenshinImpact.Model; diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml b/BetterGenshinImpact/View/Pages/HomePage.xaml index 520fccbb..5d114f75 100644 --- a/BetterGenshinImpact/View/Pages/HomePage.xaml +++ b/BetterGenshinImpact/View/Pages/HomePage.xaml @@ -211,14 +211,20 @@ + ItemsSource="{Binding InferenceDeviceTypes}" + SelectedItem="{Binding Config.InferenceDevice, Mode=TwoWay}"> + + + + + + diff --git a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs index a37f1793..f9dca898 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs @@ -1,5 +1,6 @@ using BetterGenshinImpact.Core; using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Recognition.ONNX; using BetterGenshinImpact.GameTask; using BetterGenshinImpact.Genshin.Paths; using BetterGenshinImpact.Helpers; @@ -48,7 +49,8 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware, IVi // 记录上次使用原神的句柄 private IntPtr _hWnd; - [ObservableProperty] private string[] _inferenceDevices = ["CPU", "GPU"]; + [ObservableProperty] + private string[] _inferenceDeviceTypes = BgiSessionOption.InferenceDeviceTypes; public HomePageViewModel(IConfigService configService, TaskTriggerDispatcher taskTriggerDispatcher) { @@ -117,6 +119,11 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware, IVi } } + [RelayCommand] + private void OnInferenceDeviceTypeDropDownChanged(string value) + { + } + [RelayCommand] private void OnStartCaptureTest() {