Skip to content

Onnx cannot run with cuda #19929

@Noobly0715

Description

@Noobly0715

Hi, I'm trying to use onnx with opencv
I can use the CPU but not the GPU
it said
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.1) /home/ubuntu/opencv-4.5.1/modules/dnn/src/layers/../cuda4dnn/csl/tensor.hpp:210: error: (-215:Assertion failed) start != end in function 'resize'

Here's the code

Init
net_= readNetFromONNX(this->module_path_);
if (use_gpu_ == true) {
    net_.setPreferableTarget(DNN_TARGET_CUDA);
    net_.setPreferableBackend(DNN_BACKEND_CUDA);
}
recognize
cv::Mat out;
out = Mat(1, 2048, CV_32FC1);
out = 0;
Mat img = origin.clone();
Mat inputBlob = blobFromImage(img, 1, Size(256, 256), Scalar(0, 0, 0), true, false);
net_.setInput(inputBlob);
auto feature_mat = reid_net_.forward();
feature_mat.copyTo(out);

When the use_gpu_ equal false, it can run.
What should I do next,
thx :-)

System information
  • OpenCV => 4.5.1
  • Operating System / Platform => ubuntu1~18.04 / x86_64
  • Compiler => g++ 7.5.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions