Skip to content

dnn(opencl, cuda): wrong weights are used after power fusion, eltwise power fusion is mathematically wrong #17964

@YashasSamaga

Description

@YashasSamaga
System information (version)
  • OpenCV => 4.4.0, 3.4
Detailed description

if (!activ_power.empty())
{
if (activ_power->scale != 1.f || activ_power->shift != 0.f)
{
const int outCh = blobs[0].size[0];
fuseWeights(Mat(1, outCh, CV_32F, Scalar(activ_power->scale)),
Mat(1, outCh, CV_32F, Scalar(activ_power->shift)));
}
power = activ_power->power;
activType = OCL4DNN_CONV_FUSED_ACTIV_POWER;
}

fusedWeights and fusedBias are not updated after fusion. Same with CUDA. Here is tryFuse for reference on how it should have been:

if (!w.empty() || !b.empty())
{
fuseWeights(w, b);
fusedWeights = fusedWeights || !w.empty();
fusedBias = fusedBias || (hasBias() && !w.empty()) || !b.empty();
return true;
}

Steps to reproduce

Disabled tests from #17976 can reproduce this bug. Relevant tests have // bug: https://github.com/opencv/opencv/issues/17964 comment just before applying the skip test tag.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions