InvalidArgumentError: Each axis in Attr(axes) should be in the range of [0, -1]But current axis is:2

在C#程序中调用目标检测算法(C++、TensorRT),且每次只可以调用一次检测算法接口,多次调用时出现如下报错:

[12/16/2022-16:45:35] [E] [TRT] 3: [executionContext.cpp::nvinfer1::rt::ExecutionContext::setOptimizationProfileInternal::753] Error Code 3: Internal Error (Parameter check failed at: executionContext.cpp::nvinfer1::rt::ExecutionContext::setOptimizationProfileInternal::753, condition: profileIndex >= 0 && profileIndex < mEngine.getNbOptimizationProfiles()
)
[12/16/2022-16:45:35] [E] [TRT] 3: [executionContext.cpp::nvinfer1::rt::ExecutionContext::setBindingDimensions::949] Error Code 3: Internal Error (Parameter check failed at: executionContext.cpp::nvinfer1::rt::ExecutionContext::setBindingDimensions::949, condition: mOptimizationProfile >= 0 && mOptimizationProfile < mEngine.getNbOptimizationProfiles()
)
[12/16/2022-16:45:35] [E] [TRT] 3: [executionContext.cpp::nvinfer1::rt::ExecutionContext::getBindingDimensions::1001] Error Code 3: Internal Error (Parameter check failed at: executionContext.cpp::nvinfer1::rt::ExecutionContext::getBindingDimensions::1001, condition: mOptimizationProfile >= 0 && mOptimizationProfile < mEngine.getNbOptimizationProfiles()
)
[12/16/2022-16:45:35] [E] [TRT] 3: [executionContext.cpp::nvinfer1::rt::ExecutionContext::enqueueInternal::310] Error Code 3: Internal Error (Parameter check failed at: executionContext.cpp::nvinfer1::rt::ExecutionContext::enqueueInternal::310, condition: mOptimizationProfile >= 0 && mOptimizationProfile < mEngine.getNbOptimizationProfiles()
)


--------------------------------------
C++ Traceback (most recent call last):
--------------------------------------
Not support stack backtrace yet.

----------------------
Error Message Summary:
----------------------
InvalidArgumentError: Each axis in Attr(axes) should be in the range of [0, -1]But current axis is:2, input tensor's shape = [].
  [Hint: Expected current < in_dims.size(), but received current:2 >= in_dims.size():0.] (at ..\paddle/phi/kernels/funcs/unsqueeze.h:61)

在接收数据时发生错误:System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
   at YJ_Intelligent_OCR_Service.HttpOCRResults.API_OCR_system_path(String imgPath, Int32& results_size, Char[] results, Single[] scores)
   at YJ_Intelligent_OCR_Service.HttpOCRResults.ocr_system_AbsolutePath(String imageUrl) in E:\workspace\VS2017Projects\YJ-Intelligent-OCR\YJ-Intelligent-OCR-Service\YJ-Intelligent-OCR-Service\HttpOCRResults.cs:line 342
   at YJ_Intelligent_OCR_Service.HttpOCRResults.HandleRequest(HttpListenerRequest request, HttpListenerResponse response) in E:\workspace\VS2017Projects\YJ-Intelligent-OCR\YJ-Intelligent-OCR-Service\YJ-Intelligent-OCR-Service\HttpOCRResults.cs:line 189

从错误中观察,是TensorRT中出现的错误。

但是经过检查、调试,未找到是TensorRT内部什么问题导致的。

最终锁定问题在调用处,即每次调用算法接口的线程都是不相同的,导致已初始化的算法部件在不同的线程中使用而出错。

只要保证调用算法接口的线程始终在同一线程中,即可多次识别无问题。

你可能感兴趣的:(深度学习,TensorRT,C#,人工智能,深度学习,多线程,TensorRT)