ONNX opset version 9, the Upsample operator and ONNX opset version 11

Situation: I am trying to implement a Convolutional Text Binarizer, a CNN which accepts as inputs RGB images with superimposed text and returns as outputs a map F which is (after some more processing) its corresponding black and white binary image, with the text in black and the backround in white. After the training and validation of the network I am trying to export it to ONNX so I can use it with the openCV’s dnn.module.

Problem #1: In my architecture I use one Upsample layer, which results in this warning after the export to ONNX finishes:

UserWarning: You are trying to export the model with onnx:Upsample for ONNX opset version 9. This operator might cause results to not match the expected results by PyTorch.
ONNX's Upsample/Resize operator did not match Pytorch's Interpolation until opset 11. Attributes to determine how to transform the input were added in onnx:Resize in opset 11 to support Pytorch's behavior (like coordinate_transformation_mode and nearest_mode).
We recommend using opset 11 and above for models using this operator. 
  "" + str(_export_onnx_opset_version) + ". "

I tried to use my network anyway, without re-exporting it to opset version 11 and it works pretty good, there is some room for improvments but it’s a satisfacting first attemp. I use the blob method from openCV to perform a forward pass of an image with text and I do have its corresponding binary as output. But still that warning itches my brain a bit.

Problem 2: Naturally the next thing I did, was to try to re-export the model using opset 11 and seemed to workout fine, no UserWarning was raised. Then i tried the exact same thing as before and perform a forward pass for the same image and see if there is any obvious differences between the two versions, but then this error was raised:

error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\dnn\src\layers\padding_layer.cpp:41: error: (-215:Assertion failed) params.has("paddings") in function 'cv::dnn::PaddingLayerImpl::PaddingLayerImpl'

My two main questions:

  1. Is the miss-match between the way that PyTorch and ONNX handles the Upsample operator
    significant enough to cause me trouble, or can I just ignore the warning?
  2. Why openCV’s dnn.module is loading the opset 9 version model whitout any trouble but it raises an error for the exact same model but in opset 11 version?

PS: I know thats not a forum for openCV users, so I don’t expect any answers for my second question, but if by any change somebody happens to think of a reason , I 'd really appreciate to know.

2 Likes