{"record":{"id":"e22c92a735f44f57","repo":"babalae/better-genshin-impact","slug":"yap","errorCode":null,"errorMessage":"Yap字典文件不存在","messagePattern":"Yap字典文件不存在","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Recognition/ONNX/SVTR/PickTextInference.cs","lineNumber":31,"sourceCode":"using Newtonsoft.Json;\n\nnamespace BetterGenshinImpact.Core.Recognition.ONNX.SVTR;\n\n/// <summary>\n///     来自于 Yap 的拾取文字识别\n///     https://github.com/Alex-Beng/Yap\n/// </summary>\npublic class PickTextInference : ITextInference\n{\n    private readonly InferenceSession _session;\n    private readonly Dictionary<int, string> _wordDictionary;\n\n    public PickTextInference()\n    {\n        _session = App.ServiceProvider.GetRequiredService<BgiOnnxFactory>().CreateInferenceSession(BgiOnnxModel.YapModelTraining,true);\n\n        var wordJsonPath = Global.Absolute(@\"Assets\\Model\\Yap\\index_2_word.json\");\n        if (!File.Exists(wordJsonPath)) throw new FileNotFoundException(\"Yap字典文件不存在\", wordJsonPath);\n\n        var json = File.ReadAllText(wordJsonPath);\n        _wordDictionary = JsonConvert.DeserializeObject<Dictionary<int, string>>(json) ??\n                          throw new Exception(\"index_2_word.json deserialize failed\");\n    }\n\n    public string Inference(Mat mat)\n    {\n        long startTime = Stopwatch.GetTimestamp();\n        // 将输入数据调整为 (1, 1, 32, 384) 形状的张量\n        var reshapedInputData  = OcrUtils.ToTensorYapDnn(mat, out var owner);\n\n        IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results;\n\n        using (owner)\n        {\n            // 创建输入 NamedOnnxValue, 运行模型推理\n            results = _session.Run([NamedOnnxValue.CreateFromTensor(\"input\", reshapedInputData)]);","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Recognition/ONNX/SVTR/PickTextInference.cs#L13-L49","documentation":"PickTextInference (the Yap-based pickup text recognizer) maps ONNX output indices to characters using Assets\\Model\\Yap\\index_2_word.json. The constructor throws FileNotFoundException when that dictionary file is absent, after which the Yap inference engine cannot be created.","triggerScenarios":"Constructing new PickTextInference() when Assets\\Model\\Yap\\index_2_word.json does not exist at Global.Absolute's resolved location.","commonSituations":"Yap model assets not shipped with the build; directory casing mismatch on a case-sensitive filesystem; assets moved without updating the hardcoded path; clean checkout missing the binary asset.","solutions":["Restore index_2_word.json under Assets\\Model\\Yap\\.","Confirm Global.Absolute(@\"Assets\\Model\\Yap\\index_2_word.json\") resolves to the real file location.","Ensure the Yap folder and the YapModelTraining .onnx (registered in BgiOnnxModel) are both deployed together.","Guard construction with a File.Exists check and report the missing asset path."],"exampleFix":"// before\nvar inf = new PickTextInference(); // throws if json missing\n\n// after\nvar dictPath = Global.Absolute(@\"Assets\\Model\\Yap\\index_2_word.json\");\nif (!File.Exists(dictPath)) throw new InvalidOperationException($\"Yap dictionary missing: {dictPath}\");\nvar inf = new PickTextInference();","handlingStrategy":"validation","validationCode":"var dictPath = Global.Absolute(@\"Assets\\Model\\Yap\\index_2_word.json\");\nif (!File.Exists(dictPath))\n    throw new InvalidOperationException($\"Yap dictionary missing: {dictPath}\");\nvar inference = new PickTextInference();","typeGuard":null,"tryCatchPattern":"try\n{\n    _yap = new PickTextInference();\n}\ncatch (FileNotFoundException ex) when (ex.Message.Contains(\"Yap字典文件不存在\"))\n{\n    Logger.LogError(ex, \"Yap dictionary missing; pickup text OCR disabled.\");\n    _yap = null;\n}","preventionTips":["Deploy the Yap folder (model_training.onnx and index_2_word.json) together.","Watch for directory casing issues on case-sensitive filesystems.","Add an asset-integrity check at startup."],"tags":["onnx","yap","ocr","asset-missing","svtr"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}