Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

fengyuentau
Copy link
Member

@fengyuentau fengyuentau commented Oct 16, 2023

Relates #24378 (comment)

TODO:

  • add fastNorm
  • refactor layer norm with fastNorm
  • refactor mvn with fastNorm
  • add onnx mvn in importer (in a new PR?)
  • refactor instance norm with fastNorm (in another PR dnn onnx: add instance norm layer #24378, need to merge this one first though)

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@fengyuentau
Copy link
Member Author

fengyuentau commented Oct 17, 2023

It seems there are a few caffe models using mvn layer. I cannot find one in opencv_extra.


There is one layer test though: testdata/dnn/layers/layer_mvn.prototxt.

@dkurt
Copy link
Member

dkurt commented Oct 17, 2023

@fengyuentau, AlexNet maybe?

@fengyuentau
Copy link
Member Author

@fengyuentau, AlexNet maybe?

Seems like a no, see below:

image

@dkurt
Copy link
Member

dkurt commented Oct 17, 2023

@fengyuentau, sorry, it's LRN.

There are tests which use MVN:

[  FAILED  ] Test_Caffe_layers.MVN/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_Caffe_layers.BatchNorm/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_ONNX_layers.InstanceNorm/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_TensorFlow_layers.batch_norm_10/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_TensorFlow_layers.batch_norm_11/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_TensorFlow_layers.batch_norm_13/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_Torch_layers.run_batch_norm/0, where GetParam() = OCV/CPU
[  FAILED  ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = OCV/CPU

@fengyuentau
Copy link
Member Author

@dkurt fuse_batch_norm seems like turning mvn into batch norm right? It somehow confuses me.

@dkurt
Copy link
Member

dkurt commented Oct 17, 2023

@fengyuentau, exactly. This is for channel-wise scale/bias.

@fengyuentau fengyuentau marked this pull request as ready for review October 17, 2023 10:12
@fengyuentau
Copy link
Member Author

@fengyuentau, exactly. This is for channel-wise scale/bias.

Thank you for the clarification. This PR is all set for review. Most of the tests are green on my mac m1 except for something wrong with Test_Torch_nets.FastNeuralStyle_accuracy.

@fengyuentau
Copy link
Member Author

Should we just tune the threshold?

ubuntu arm64:

[ RUN      ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = OCV/CPU
/home/ci/opencv/modules/dnn/test/test_common.impl.hpp:79: Failure
Expected: (normInf) <= (lInf), actual: 1.14948 vs 1.11
  |ref| = 255
[  FAILED  ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = OCV/CPU (279 ms)

ubuntu x64:

[ RUN      ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = OCV/CPU
/home/ci/opencv/modules/dnn/test/test_common.impl.hpp:79: Failure
Expected: (normInf) <= (lInf), actual: 1.15276 vs 1.11
  |ref| = 255
[  FAILED  ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = OCV/CPU (335 ms)

windows10 x64 vulkan:

[ RUN      ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = VKCOM/VULKAN
C:\GHA-OCV-2\_work\opencv\opencv\opencv\modules\dnn\test\test_common.impl.hpp(79): error: Expected: (normInf) <= (lInf), actual: 1.1487 vs 1.11
  |ref| = 255
[  FAILED  ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = VKCOM/VULKAN (686 ms)
[ RUN      ] Test_Torch_nets.FastNeuralStyle_accuracy/1, where GetParam() = OCV/CPU
C:\GHA-OCV-2\_work\opencv\opencv\opencv\modules\dnn\test\test_common.impl.hpp(79): error: Expected: (normInf) <= (lInf), actual: 1.15276 vs 1.11
  |ref| = 255
[  FAILED  ] Test_Torch_nets.FastNeuralStyle_accuracy/1, where GetParam() = OCV/CPU (572 ms)

macos arm64:

[ RUN      ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = OCV/CPU
/Users/opencv-cn/GHA-OCV-1/_work/opencv/opencv/opencv/modules/dnn/test/test_common.impl.hpp:79: Failure
Expected: (normInf) <= (lInf), actual: 1.15292 vs 1.11
  |ref| = 255
[  FAILED  ] Test_Torch_nets.FastNeuralStyle_accuracy/0, where GetParam() = OCV/CPU (350 ms)
[ RUN      ] Test_Torch_nets.FastNeuralStyle_accuracy/1, where GetParam() = OCV/CPU_FP16
/Users/opencv-cn/GHA-OCV-1/_work/opencv/opencv/opencv/modules/dnn/test/test_common.impl.hpp:76: Failure
Expected: (normL1) <= (l1), actual: 0.633552 vs 0.62
  |ref| = 255
[  FAILED  ] Test_Torch_nets.FastNeuralStyle_accuracy/1, where GetParam() = OCV/CPU_FP16 (336 ms)

@dkurt dkurt mentioned this pull request Oct 30, 2023
12 tasks
class CV_EXPORTS LayerNormLayer : public Layer
{
public:
bool hasBias; // Deprecated, preserve for compatibility
Copy link
Member

Choose a reason for hiding this comment

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

CV_DEPRECATED_EXTERNAL bool hasBias

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you!

@asmorkalov asmorkalov assigned dkurt and unassigned vpisarev Nov 1, 2023
@asmorkalov asmorkalov merged commit c91af16 into opencv:4.x Nov 1, 2023
@asmorkalov asmorkalov mentioned this pull request Nov 3, 2023
@dkurt dkurt mentioned this pull request Nov 30, 2023
12 tasks
IskXCr pushed a commit to Haosonn/opencv that referenced this pull request Dec 20, 2023
dnn: add shared fastNorm kernel for mvn, instance norm and layer norm opencv#24409

Relates opencv#24378 (comment)

TODO:

- [x] add fastNorm
- [x] refactor layer norm with fastNorm
- [x] refactor mvn with fastNorm
- [ ] add onnx mvn in importer (in a new PR?)
- [ ] refactor instance norm with fastNorm (in another PR opencv#24378, need to merge this one first though)

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
dnn: add shared fastNorm kernel for mvn, instance norm and layer norm opencv#24409

Relates opencv#24378 (comment)

TODO:

- [x] add fastNorm
- [x] refactor layer norm with fastNorm
- [x] refactor mvn with fastNorm
- [ ] add onnx mvn in importer (in a new PR?)
- [ ] refactor instance norm with fastNorm (in another PR opencv#24378, need to merge this one first though)

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
dnn: add shared fastNorm kernel for mvn, instance norm and layer norm opencv#24409

Relates opencv#24378 (comment)

TODO:

- [x] add fastNorm
- [x] refactor layer norm with fastNorm
- [x] refactor mvn with fastNorm
- [ ] add onnx mvn in importer (in a new PR?)
- [ ] refactor instance norm with fastNorm (in another PR opencv#24378, need to merge this one first though)

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
@fengyuentau fengyuentau deleted the norm_kernel branch June 28, 2024 09:57
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