Skip to content

dnn: inconsistant input data type for element-wise layers #24385

@fengyuentau

Description

@fengyuentau

System Information

latest opencv

Detailed description

In nary_eltwise_layers.cpp, there is a line dispatching by data type of output mat:

https://github.com/opencv/opencv/blob/590f150d5e032165e27d81294c9b7ac710b77f11/modules/dnn/src/layers/nary_eltwise_layers.cpp#L634C10-L634C10

In the current dnn engine, we basically use either float or float16 for input (x) and output (y) mats; thats not a problem. The problem is for constsant input noes, their type can be something else, such as CV_32S in the following model:

image

In this case, the input x and output y has data type CV_32F, but the constant input B has data type CV_32S. However, the dispatcher calls the template with float because of data type of y, then B values are parsed in a wrong type, leading to incorrect results.

Steps to reproduce

Run the attached model with opencv dnn and check with reference input and output.

greater.zip

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