Skip to content

dnn module problems: InnerProductLayer #17516

@wenqingzhang-gordon

Description

@wenqingzhang-gordon
System information (version)
  • OpenCV => 4.3.0
  • Operating System / Platform => Ubuntu 18.04
  • Compiler => Qt5
Detailed description

When I imported an ONNX model, I found that it failed at modules/dnn/src/layers/fully_connected_layer.cpp Line 122

CV_CheckEQ(numOutput, inputs[0][cAxis - 1], "");

I have checked it, and I think it may be not right.
For example,

class Decoder(nn.Module):
    def __init__(self, inPlanes=512, sDim=512, attDim=512):
        super(Decoder, self).__init__()
        self.inPlanes = inPlanes
        self.sDim = sDim
        self.attDim = attDim

        self.sEmbed = nn.Linear(sDim, attDim)
        self.xEmbed = nn.Linear(inPlanes, attDim)
        self.wEmbed = nn.Linear(attDim, 1)

    def forward(self, x):
        x = x.reshape(-1, self.inPlanes)
        xProj = self.xEmbed(x)
        state = torch.zeros(1, self.sDim)
        sProj = self.sEmbed(state)
        sProj = sProj.expand(25, self.attDim)
        sumTanh = torch.tanh(sProj + xProj)
        sumTanh = sumTanh.reshape(-1, self.attDim)
        vProj = self.wEmbed(sumTanh)
        vProj = vProj.reshape(1, 25)
        alpha = F.softmax(vProj, dim=1)
        context = torch.matmul(alpha, x)  # HERE
        return context

Set the shape of the input x to (1, 25, 512), then at 'HERE'

        context = torch.matmul(alpha, x)  # HERE

The shape of alpha is (1, 25), and the shape of x is (25, 125), and both of them are not the constBlobs in OpenCV.
When I import it in OpenCV, in fully_connected_layer.cpp Line 122, we can find that:

  • numOutput is 512
  • inputs[0][cAxis - 1] is 1

Obviously, numOutput != inputs[0][cAxis - 1], and it throw an exception.

So I deleted the CV_CheckEQ, and loaded it successfully.

Steps to reproduce

It is described above.

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions