PaddlePaddle / PaddlePaddle/FastDeploy

运行编译出来的Csharp示例代码./FastDeploy/examples/vision/ocr/PP-OCR/cpu-gpu/csharp/build/infer_demo.sln,出现推理报错闪退问题

Open
#2,486 4 comments 0 reactions 1 assignee View on GitHub

@juncaipeng is already working on this.

Since Jul 5, 2024.

Dominant language
Python
Stars
3.7k
Forks
756
Avg merge
19h 28m
Merged PRs (30d)
4

Description


温馨提示:根据社区不完全统计,按照模板提问,可以加快回复和解决问题的速度


环境

  • 【FastDeploy版本】: 自行编译FastDeploy SDK 的Csharp API接口
  • 【编译命令】
  • C++ SDK编译安装(Windows)
    cd E:\Work\OurDevelop\OCR\FastDeploy\build
    cmake .. -G "Visual Studio 16 2019" -A x64 -DENABLE_ORT_BACKEND=ON
    -DENABLE_PADDLE_BACKEND=ON -DENABLE_OPENVINO_BACKEND=ON
    -DENABLE_TRT_BACKEND=ON -DENABLE_VISION=ON
    -DENABLE_TEXT=ON -DWITH_GPU=ON
    -DWITH_CAPI=ON -DWITH_CSHARPAPI=ON
    -DTRT_DIRECTORY="E:\Work\Dependency_Library\TensorRT-8.6.1.6" -DCUDA_DIRECTORY="D:\SoftWare\CUDA\v11.3"
    -DCMAKE_INSTALL_PREFIX="E:\Work\OurDevelop\OCR\compiled_fastdeploy"
  • 编译Csharp示例代码
    cd E:\Work\OurDevelop\OCR\FastDeploy\examples\vision\ocr\PP-OCR\cpu-gpu\csharp\build
    cmake .. -G "Visual Studio 16 2019" -A x64 -DFASTDEPLOY_INSTALL_DIR=E:\Work\OurDevelop\OCR\compiled_fastdeploy -DCUDA_DIRECTORY="D:/SoftWare/CUDA/v11.3"
    nuget restore
    msbuild infer_demo.sln /m:4 /p:Configuration=Release /p:Platform=x64
  • FastDeploy依赖的库拷贝至可执行程序所在目录
    ./fastdeploy_init.bat install %cd% E:\Work\OurDevelop\OCR\FastDeploy\examples\vision\ocr\PP-OCR\cpu-gpu\csharp\build\Release
  • 【系统平台】: Windows x64(Windows10)
  • 【硬件】: Nvidia GPU 4060, CUDA 11.3 CUDNN 8.2
  • 【编译语言】:Csharp

问题日志及出现问题的操作流程

运行Csharp示例代码./FastDeploy/examples/vision/ocr/PP-OCR/cpu-gpu/csharp/build/infer_demo.sln项目
Csharp运行代码如下

using System;
using System.IO;
using System.Runtime.InteropServices;
using OpenCvSharp;
using fastdeploy;

namespace Test
{
    public class TestPPOCRv3
    {
        public static void Main(string[] args)
        {
            string det_model_dir = "E:\\model_en\\en_PP-OCRv3_det_infer";
            string cls_model_dir = "E:\\model_en\\ch_ppocr_mobile_v2.0_cls_infer";
            string rec_model_dir = "E:\\model_en\\en_PP-OCRv3_rec_infer";
            string rec_label_file = "E:\\model_en\\en_dict.txt";
            string image_path = "E:\\model\\img_12.jpg";
            RuntimeOption runtimeoption = new RuntimeOption();
            int device_option = 1;
            if(device_option==0){
                runtimeoption.UseCpu();
            }else{
                runtimeoption.UseGpu();
            }
            string sep = "\\";
            string det_model_file = det_model_dir + sep + "inference.pdmodel";
            string det_params_file = det_model_dir + sep + "inference.pdiparams";

            string cls_model_file = cls_model_dir + sep + "inference.pdmodel";
            string cls_params_file = cls_model_dir + sep + "inference.pdiparams";

            string rec_model_file = rec_model_dir + sep + "inference.pdmodel";
            string rec_params_file = rec_model_dir + sep + "inference.pdiparams";

            fastdeploy.vision.ocr.DBDetector dbdetector = new fastdeploy.vision.ocr.DBDetector(det_model_file, det_params_file, runtimeoption, ModelFormat.PADDLE);
            fastdeploy.vision.ocr.Classifier classifier = new fastdeploy.vision.ocr.Classifier(cls_model_file, cls_params_file, runtimeoption, ModelFormat.PADDLE);
            fastdeploy.vision.ocr.Recognizer recognizer = new fastdeploy.vision.ocr.Recognizer(rec_model_file, rec_params_file, rec_label_file, runtimeoption, ModelFormat.PADDLE);
            fastdeploy.pipeline.PPOCRv3 model = new fastdeploy.pipeline.PPOCRv3(dbdetector, classifier, recognizer);
            if(!model.Initialized()){
                Console.WriteLine("Failed to initialize.\n");
            }
            Mat image = Cv2.ImRead(image_path);
            fastdeploy.vision.OCRResult res = model.Predict(image);
            Console.WriteLine(res.ToString());
            Mat res_img = fastdeploy.vision.Visualize.VisOcr(image, res);
            Cv2.ImShow("result.png", res_img);
            Cv2.ImWrite("result.png", res_img);
            Cv2.WaitKey(0);
        }
    }
}

在这行fastdeploy.vision.OCRResult res = model.Predict(image);出现报错
System.ArgumentOutOfRangeException:“在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。 (异常来自 HRESULT:0x80070459)”
在我的电脑上是一直都会报这个问题,或者直接闪退./FastDeploy/examples/vision/ocr/PP-OCR/cpu-gpu/csharp/build/Debug/infer_demo.exe (进程 31404)已退 出,代码为 -1073740940。
在我伙伴的电脑上有时图片正常计算(偶尔出现中文乱码问题),有时也报这个错误
如下图(偶尔出现中文乱码问题)
微信图片_20240705161958
如下图(计算报错闪退)
微信图片_20240705160728

所以想请问各位这是由于什么原因导致这两个问题,特在此求助大家!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.