Skip to content

Make use of explicit output shape for the de-convolution layer. - #13989

Merged
opencv-pushbot merged 2 commits into
opencv:3.4from
kohei-us:onnx-conv-transpose-output-shape
Mar 26, 2019
Merged

opencv-pushbot merged 2 commits into
opencv:3.4from
kohei-us:onnx-conv-transpose-output-shape

Conversation

@kohei-us

@kohei-us kohei-us commented Mar 6, 2019 •

Copy link
Copy Markdown

Merge with extra: opencv/opencv_extra#582

This is relevant to cases where the net is loaded from an ONNX model
containing ConvTranspose layers, which may include the output_shape
attribute.

c.f. https://github.com/onnx/onnx/blob/master/docs/Operators.md#ConvTranspose

allow_multiple_commits=1

@dkurt

dkurt commented Mar 6, 2019

Copy link
Copy Markdown
Member

@kohei-us, Can you add a test?

@dkurt dkurt added pr: needs test New functionality requires minimal tests set category: dnn labels Mar 6, 2019
@kohei-us

kohei-us commented Mar 6, 2019

Copy link
Copy Markdown
Author

@dkurt Sure, I can look into that. Any suggestion as to where to add a new test?

@kohei-us

kohei-us commented Mar 6, 2019

Copy link
Copy Markdown
Author

I guess modules/dnn/test/test_onnx_importer.cpp may be a good place for this (?)

@dkurt

dkurt commented Mar 6, 2019

Copy link
Copy Markdown
Member

@kohei-us, Yeah.

@kohei-us

kohei-us commented Mar 7, 2019

Copy link
Copy Markdown
Author

I have another pull request on opencv_extra to add test case files.

opencv/opencv_extra#582

@kohei-us

kohei-us commented Mar 7, 2019

Copy link
Copy Markdown
Author

I also pushed a one-line change to run the test case. Obviously it will depend on the change I made to the above referenced pull request...

@dkurt

dkurt commented Mar 24, 2019

Copy link
Copy Markdown
Member

@kohei-us, May I ask you about the state of this PR? Have your tried to simplify it considering my comment from opencv/opencv_extra#582 (comment)?

@kohei-us

Copy link
Copy Markdown
Author

@dkurt Sorry I got caught up with something else. I will take a look at this and try your suggestion early next week.

@kohei-us
kohei-us force-pushed the onnx-conv-transpose-output-shape branch from 469b8c8 to 3c2f38d Compare March 25, 2019 13:58
@kohei-us

Copy link
Copy Markdown
Author

@dkurt Ok. I've made changes per your suggestion, and tested it locally to make sure it still addresses my issue.

Comment thread modules/dnn/src/onnx/onnx_importer.cpp Outdated
layerParams.set("bias_term", node_proto.input_size() == 3);

const DictValue* outShape = layerParams.ptr("output_shape");
if (outShape && outShape->size() == 4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please check if there is "output_shape" parameter by layerParams.has("output_shape");
  • It's more convenient to use DictValue outShape = layerParams.get("output_shape");
  • If outShape.size() != 4 it's better to throw a StsNotImplemented exception because we don't know how to manage it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread modules/dnn/src/onnx/onnx_importer.cpp Outdated
if (outShape && outShape->size() == 4)
{
const int strideY = layerParams.get<int>("stride_h");
const int strideX = layerParams.get<int>("stride_w");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use default values because strides might be optional:

const int strideY = layerParams.get<int>("stride_h", 1);
const int strideX = layerParams.get<int>("stride_w", 1);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done as well.

{
layerParams.set("adj_w", (outW - 1) % strideX);
layerParams.set("adj_h", (outH - 1) % strideY);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done too.

@kohei-us
kohei-us force-pushed the onnx-conv-transpose-output-shape branch from 3c2f38d to 77e2a08 Compare March 26, 2019 11:34
@kohei-us

Copy link
Copy Markdown
Author

@dkurt Let me know if my recent change addresses all of your comments. Thanks!

Comment thread modules/dnn/src/onnx/onnx_importer.cpp Outdated
CV_Error(Error::StsNotImplemented,
"Kernel shape attribute is required for VALID pad mode.");

const DictValue& kernelShape = layerParams.get("kernel_shape");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use kernel_h and kernel_w (please also check that they are presented):

                    if (!layerParams.has("kernel_h") || !layerParams.has("kernel_w"))
                        CV_Error(Error::StsNotImplemented, "...");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and pushed.

@kohei-us
kohei-us force-pushed the onnx-conv-transpose-output-shape branch from 77e2a08 to 96210fc Compare March 26, 2019 13:36
@dkurt

dkurt commented Mar 26, 2019

Copy link
Copy Markdown
Member

@kohei-us, The last thing I wanted to ask you is to change the base branch from master to 3.4. You can do it without closing this PR. See https://github.com/opencv/opencv/wiki/How_to_contribute#q2-i-was-asked-to-change-the-target-branch-for-my-pull-request-how-can-i-do-that for details.

Kohei Yoshida added 2 commits March 26, 2019 10:46
@kohei-us
kohei-us force-pushed the onnx-conv-transpose-output-shape branch from 96210fc to 2124205 Compare March 26, 2019 14:47
@kohei-us
kohei-us changed the base branch from master to 3.4 March 26, 2019 14:48
kohei-us pushed a commit to kohei-us/opencv_extra that referenced this pull request Mar 26, 2019
@kohei-us

Copy link
Copy Markdown
Author

Done. Hopefully I've done this correctly. I've done the same with opencv/opencv_extra#582 as well.

@dkurt dkurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @kohei-us, Thank you! Looks good to merge!

@dkurt dkurt self-assigned this Mar 26, 2019
@opencv-pushbot
opencv-pushbot merged commit 2124205 into opencv:3.4 Mar 26, 2019
@alalek alalek mentioned this pull request Mar 26, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants