Skip to content

Support FlowNet2 model#16575

Merged
alalek merged 28 commits intoopencv:3.4from
l-bat:flownet2
May 19, 2020
Merged

Support FlowNet2 model#16575
alalek merged 28 commits intoopencv:3.4from
l-bat:flownet2

Conversation

@l-bat
Copy link
Copy Markdown
Contributor

@l-bat l-bat commented Feb 13, 2020

Merge with extra: opencv/opencv_extra#708
relates #16319

Supported layers:

  • DataAugmentation (1 input, 3 blobs)
  • Resample (Bilinear antialias, Nearest inputs > 1)
  • Convolution (intputs > 1)
  • Correlation
  • Accum
  • ChannelNorm
  • FlowWarp

Added tests:

  • DataAugmentation (1 input, 3 blobs)
  • Resample (Bilinear antialias, Nearest inputs > 1)
  • Convolution (intputs > 1)
  • Correlation
  • Accum
  • ChannelNorm
  • FlowWarp
force_builders=Custom,Custom Win,Custom Mac
build_image:Custom=ubuntu-openvino-2020.1.0:16.04
Xbuild_image:Custom=ubuntu-openvino-2020.2.0:16.04
build_image:Custom Win=openvino-2020.1.0
build_image:Custom Mac=openvino-2020.1.0

test_modules:Custom=dnn,python2,python3,java
test_modules:Custom Win=dnn,python2,python3,java
test_modules:Custom Mac=dnn,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*
Example

Inputs

Output

@l-bat l-bat added this to the 3.4.10 milestone Feb 13, 2020
}


class ChannelNormLayerImpl CV_FINAL : public ChannelNormLayer
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.

What do you think if instead of adding this custom layer we can modify .ptototxt replacing it to series of layers that give the sample result? In example,

x*x -> reshape (1, 1, C, -1) -> ave pool by H -> multiply by C -> reshape back

Copy link
Copy Markdown
Member

@dkurt dkurt Apr 9, 2020

Choose a reason for hiding this comment

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

Or, which is better, to do the same in the importer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case, we need to store outShapes in importer. Maybe we will have problems with nets without .caffemodel.

Copy link
Copy Markdown
Member

@dkurt dkurt Apr 10, 2020

Choose a reason for hiding this comment

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

Maybe we will have problems with nets without .caffemodel.

Why so?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have already tried to calculate outShapes in caffe_importer. Some tests failed in getMemoryShapes method if we don't use .caffemodel for nets with weighted layers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I modified channel_norm.prototxt to a series of layers.

@asmorkalov
Copy link
Copy Markdown
Contributor

@dkurt Friendly reminder.

outputs[0][3] = inputs[1][3];
if ((interpolation == "linear" && (factor_w != 1.0 || factor_h != 1.0)) ||
(interpolation == "nearest" && (factor_w < 1.0 || factor_h < 1.0)))
CV_Error(Error::StsNotImplemented, "Unsupported Resize mode");
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.

Why they are not supported?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Caffe result with these factors is not equal to OpenCV resize

@asmorkalov
Copy link
Copy Markdown
Contributor

@dkurt Friendly reminder.

@asmorkalov
Copy link
Copy Markdown
Contributor

@dkurt @l-bat Friendly reminder.

@l-bat l-bat force-pushed the flownet2 branch 2 times, most recently from 50af357 to afc2e4b Compare May 15, 2020 11:56

To run model in OpenCV modify Flownetv2.prototxt.

change ChannelNorm layers to series of layers:
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.

How many ChannelNorm layers inside? Maybe it make sense to put modified .prototxt to opencv_extra?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I put modified .prototxt and .caffemodel to cloud.

You can download the converted .caffemodel model from https://drive.google.com/open?id=16qvE9VNmU39NttpZwZs81Ga8VYQJDaWZ
or convert .h5 model to .caffemodel yourself.
Download .prototxt from https://drive.google.com/open?id=19bo6SWU2p8ZKvjXqMKiCPdK8mghwDy9b
or modify original Flownetv2.prototxt - change ChannelNorm layers to series of layers as in link above.
Copy link
Copy Markdown
Member

@dkurt dkurt May 18, 2020

Choose a reason for hiding this comment

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

Please rephrase so user can understand which are required steps and that are optional. Otherwise one can download .caffemodel then "To get original model". I'd like to put everything in one place and say "Download this and that. Otherwise download original model from here".

Changes required in prototxt file I'd like to recommend to write right in the prototxt file as a reference to origin prototxt file.

@dkurt dkurt linked an issue May 18, 2020 that may be closed by this pull request
Copy link
Copy Markdown
Member

@dkurt dkurt left a comment

Choose a reason for hiding this comment

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

👍 Well done!

@alalek alalek merged commit d991c22 into opencv:3.4 May 19, 2020
@alalek alalek mentioned this pull request May 22, 2020
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.

DNN: Exception "inputs.size() >= 2" on calling Forward

4 participants