opencv读取onnx模型出错


void Resnet::recognition(cv::Mat& srcImg, cv::dnn::Net& net) {


    cv::Mat blob;
    cv::Mat netInPutImage = srcImg.clone();
    netInPutImage.resize(netWidth, netHeight);
    cv::dnn::blobFromImage(netInPutImage, blob, 1 / 255.0, cv::Size(256,256), cv::Scalar(0, 0, 0), true, false);
    net.setInput(netInPutImage);

    cv::Mat prob = net.forward();
    cv::Point classIdPoint;
    double confidence;
    minMaxLoc(prob.reshape(1, 1), 0, &confidence, 0, &classIdPoint);
    int classId = classIdPoint.x;

    std::string label = cv::format("Predicted Class : %s, confidence : %.3f", (className[classId].c_str()), confidence);


    cv::putText(srcImg, label, cv::Point(10, 30), cv::FONT_HERSHEY_SIMPLEX, 0.6, cv::Scalar(0, 0, 255), 2, cv::LINE_AA);

    cv::imshow("Classification Output", srcImg);
    cv::waitKey(0);
}
这是识别的代码,

img


这是模型导出的代码。batch是32,分成了19类也就是32*19.

img


这是报错
下面是我的onnx导出代码

import torch
import torch.nn
import onnx
 
model = torch.load('./baocunmoxing/faceall.pt')
device = "cuda" if torch.cuda.is_available() else "cpu"
print("Using {} device".format(device))#使用cuda
model = model.to(device)
model.eval()

input_name = 'input'
output_name = 'output'
batch_size = '32'
x = torch.randn(32,3,256,256,requires_grad=True)
x = x.to(device)
torch.onnx.export(model, 
                      x, 
                      "face.onnx",
                      opset_version=11,
                      input_names=[input_name],
                      output_names=[output_name]
                      )

你把读取过程和报错都发给我看一下