Skip to content

dnn: wrong internal results in expand_neg_batch in Test_ONNX_layers.Expand #24308

@fengyuentau

Description

@fengyuentau

System Information

lastest opencv and lastest onnxruntime (1.16.0, released just now)

Detailed description

The model expand_neg_batch.onnx is as follows (Note that I manually added output "8".),

image

For output "8", onnxruntime produces value [2, 1, 1, 1]; dnn produces value [2, -1, -1, -1]. My own calculation is the same as onnxruntime's.

Model is attached here: expand_neg_batch.new.onnx.zip


@asmorkalov

Should we run every single onnx model in test_onnx_importer.cpp with onnxruntime and verify with our input and output data to see whether the model is correctly built and dnn can produce correct results?

Steps to reproduce

  1. Download the model and run inference to get outputs with onnxruntime
import numpy as np

import onnxruntime as ort
import cv2 as cv

x = np.random.randn(1, 2, 2).astype(np.float32)

def ort_inference(model_path):
    net = ort.InferenceSession(model_path, providers=['CPUExecutionProvider'])
    out = net.run(["8"], {})[0]
    print("ort result=", out)

def ocv_inference(model_path):
    net = cv.dnn.readNet(model_path)
    net.setInput(x)

    out = net.forward("8")
    print("ocv result=", out)

ort_inference("./expand_neg_batch.new.onnx")
# forget this, small 3d tensor is parsed incorrectly because of opencv python binding
#ocv_inference("./expand_neg_batch.new.onnx")
  1. Clone my Expand refactor PR dnn: expand refactor with cv::broadcast for onnx models #24295, add the following code to print shape in onnx_importer.cpp::parseExpand (about line 2318):
for (int i = 0; i < mat_input_shape.total(); ++i) {
    std::cout << *(mat_input_shape.ptr<int>() + i) << " ";
    // CV_Check(i, *(mat_input_shape.ptr<int>() + i) >= 0, "DNN/ONNXImporter-Expand: invalid shape dimension");
}

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions