Skip to content

Assertion failed (inputs.size()) in cv::dnn::dnn4_v20190122::Layer::getMemoryShapes #14713

Closed

Description

@Aeroxander
System information (version)
  • OpenCV => 4.1.0 C++
  • Operating System / Platform => Mac OS High Sierra (also had this issue on Windows 10)
  • Compiler => XCode
Detailed description

So I have 3 PyTorch models where 2 of them give me trouble when loading in ONNX, the inference works fine in PyTorch and the conversion is all ok too.

So in the first model I get this error when reading the ONNX model in OpenCV:

Assertion failed (inputs.size()) in cv::dnn::dnn4_v20190122::Layer::getMemoryShapese

With the other model I get this error:

Blob 64 not found in const blobs

This has all something to do with the input where in the first error the inputs.size() is 0 and in the second model the blob isn't big enough somehow.
I don't know which framework or action I did I can pinpoint the error to..

Steps to reproduce

Read the decoder ONNX model

Standalone project

https://github.com/Aeroxander/decodererror

Activity

  1. alalek commented on Jun 4, 2019

    @alalek
    Member

    keep them both as a global variable

    Due static initialization order fiasco it is a bad practice in general.

    Please provide:

    • complete standalone reproducer (without extra dependencies outside of OpenCV)
    • and stack trace of your crashes (to ensure that problem is the same)
  2. changed the title [-]Crash on reading second dnn::readNetFromONNX file[/-] [+]Crash on reading specific dnn::readNetFromONNX file[/+] on Jun 5, 2019
  3. Aeroxander commented on Jun 5, 2019

    @Aeroxander
    Author

    @alalek My mistake, I actually get an error just for that 1 wrong ONNX model, it just can't parse it and gives an "Can't read ONNX model file" error.

    As the first one works fine, I suppose the conversion to my ONNX model went fine, although something may have not converted properly. Here is some info of the model:

    format: ONNX v4
    producer: pytorch 1.1
    imports: ai.onnx v9
    name: torch-jit-export

    Should I try out ONNX v5 that may be more compatible with converting from PyTorch to ONNX, or how can I discover what's wrong with my model?

    Could still something be wrong with OpenCV? According to the ONNX valid model check code the model is fine:

    import onnx
    model = onnx.load("decoder.onnx")
    
    print(onnx.checker.check_model(model))
    
    print(onnx.helper.printable_graph(model.graph))
    
    

    Output:

    None
    graph torch-jit-export (
      %input.1[FLOAT, 1x256x64x64]
    ) initializers (
      %conv7.weight[FLOAT, 128x256x3x3]
      %conv7.bias[FLOAT, 128]
      %conv8.weight[FLOAT, 128x128x3x3]
      %conv8.bias[FLOAT, 128]
      %conv9.weight[FLOAT, 64x128x3x3]
      %conv9.bias[FLOAT, 64]
      %conv10.weight[FLOAT, 64x64x3x3]
      %conv10.bias[FLOAT, 64]
      %conv11.weight[FLOAT, 3x64x3x3]
      %conv11.bias[FLOAT, 3]
    ) {
      %11 = Pad[mode = 'reflect', pads = [0, 0, 1, 1, 0, 0, 1, 1]](%input.1)
      %12 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [0, 0, 0, 0], strides = [1, 1]](%11, %conv7.weight, %conv7.bias)
      %13 = Relu(%12)
      %14 = Constant[value = <Scalar Tensor []>]()
      %15 = Shape(%13)
      %16 = Gather[axis = 0](%15, %14)
      %17 = Constant[value = <Scalar Tensor []>]()
      %18 = Mul(%16, %17)
      %19 = Floor(%18)
      %20 = Constant[value = <Scalar Tensor []>]()
      %21 = Shape(%13)
      %22 = Gather[axis = 0](%21, %20)
      %23 = Constant[value = <Scalar Tensor []>]()
      %24 = Mul(%22, %23)
      %25 = Floor(%24)
      %26 = Unsqueeze[axes = [0]](%19)
      %27 = Unsqueeze[axes = [0]](%25)
      %28 = Concat[axis = 0](%26, %27)
      %29 = Constant[value = <Tensor>]()
      %30 = Cast[to = 1](%28)
      %31 = Shape(%13)
      %32 = Slice[axes = [0], ends = [4], starts = [2]](%31)
      %33 = Cast[to = 1](%32)
      %34 = Div(%30, %33)
      %35 = Concat[axis = 0](%29, %34)
      %36 = Upsample[mode = 'nearest'](%13, %35)
      %37 = Pad[mode = 'reflect', pads = [0, 0, 1, 1, 0, 0, 1, 1]](%36)
      %38 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [0, 0, 0, 0], strides = [1, 1]](%37, %conv8.weight, %conv8.bias)
      %39 = Relu(%38)
      %40 = Pad[mode = 'reflect', pads = [0, 0, 1, 1, 0, 0, 1, 1]](%39)
      %41 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [0, 0, 0, 0], strides = [1, 1]](%40, %conv9.weight, %conv9.bias)
      %42 = Relu(%41)
      %43 = Constant[value = <Scalar Tensor []>]()
      %44 = Shape(%42)
      %45 = Gather[axis = 0](%44, %43)
      %46 = Constant[value = <Scalar Tensor []>]()
      %47 = Mul(%45, %46)
      %48 = Floor(%47)
      %49 = Constant[value = <Scalar Tensor []>]()
      %50 = Shape(%42)
      %51 = Gather[axis = 0](%50, %49)
      %52 = Constant[value = <Scalar Tensor []>]()
      %53 = Mul(%51, %52)
      %54 = Floor(%53)
      %55 = Unsqueeze[axes = [0]](%48)
      %56 = Unsqueeze[axes = [0]](%54)
      %57 = Concat[axis = 0](%55, %56)
      %58 = Constant[value = <Tensor>]()
      %59 = Cast[to = 1](%57)
      %60 = Shape(%42)
      %61 = Slice[axes = [0], ends = [4], starts = [2]](%60)
      %62 = Cast[to = 1](%61)
      %63 = Div(%59, %62)
      %64 = Concat[axis = 0](%58, %63)
      %65 = Upsample[mode = 'nearest'](%42, %64)
      %66 = Pad[mode = 'reflect', pads = [0, 0, 1, 1, 0, 0, 1, 1]](%65)
      %67 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [0, 0, 0, 0], strides = [1, 1]](%66, %conv10.weight, %conv10.bias)
      %68 = Relu(%67)
      %69 = Pad[mode = 'reflect', pads = [0, 0, 1, 1, 0, 0, 1, 1]](%68)
      %70 = Conv[dilations = [1, 1], group = 1, kernel_shape = [3, 3], pads = [0, 0, 0, 0], strides = [1, 1]](%69, %conv11.weight, %conv11.bias)
      return %70
    }
    

    I'd think if ONNX missed converting something at least the output of the forward pass would give something faulty..

  4. changed the title [-]Crash on reading specific dnn::readNetFromONNX file[/-] [+]Assertion failed (inputs.size()) in cv::dnn::dnn4_v20190122::Layer::getMemoryShapes[/+] on Jun 7, 2019
  5. Aeroxander commented on Jun 7, 2019

    @Aeroxander
    Author

    So I get this error now:
    OpenCV(4.1.0) Error: Assertion failed (inputs.size()) in cv::dnn::dnn4_v20190122::Layer::getMemoryShapes, file c:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\dnn.cpp, line 3616

    @alalek as requested, here is the standalone project:
    https://github.com/Aeroxander/decodererror

    Just unzip the lib+include.zip file in the same folder and the opencv_world410.7z in /x64/Debug, then it should work out of the box!

  6. Aeroxander commented on Jun 7, 2019

    @Aeroxander
    Author

    I suppose OpenCV is unable to generate a tensor to test the model out?
    @dkurt Could you possibly remove the incomplete/needs reproducer labels? Thanks! Also, is this issue the same as #14290 ? Sadly I haven't been able to convert the ONNX model to TensorFlow as the ONNX -> Tensorflow converter doesn't seem to like INT64's and only wants Floats...

  7. added and removed
    needs reproducer
    on Jun 8, 2019
  8. Aeroxander commented on Jun 11, 2019

    @Aeroxander
    Author

    It looks like it's referencing to the Mul layer with ID 18;

    %18 = Mul(%16, %17)

    Have no idea why there isn't an input..

    I also get this error in another model:

    Blob 64 not found in const blobs

    And this seems to be in the MatMul layer, so there must be something wrong with the PyTorch -> ONNX conversion right?

  9. ashishkrshrivastava commented on Feb 24, 2020

    @ashishkrshrivastava
    Contributor

    Hii @Aeroxander , are you still working with this model ?

  10. dkurt commented on Mar 3, 2020

    @dkurt
    Member

    @ashishkrshrivastava, Please check if we can close this issue because it's resolved by #16709 or not (if we can run a model).

  11. ashishkrshrivastava commented on Mar 5, 2020

    @ashishkrshrivastava
    Contributor

    @dkurt It is resolved. I am able to load it successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions