dnn: add exhaustive fusion tests, enable more eltwise fusions#17976
dnn: add exhaustive fusion tests, enable more eltwise fusions#17976alalek merged 2 commits intoopencv:3.4from
Conversation
| static testing::internal::ParamGenerator<std::string> activationLayersList() | ||
| { | ||
| // TODO: automate list generation | ||
| return Values("ReLU", "ReLU6", "ChannelsPReLU", "TanH", "Swish", "Mish", "Sigmoid", "ELU", "AbsVal", "BNLL", "Power"); |
There was a problem hiding this comment.
I was wondering if it would be possible to automatically generate this list.
modules/dnn/test/test_layers.cpp
Outdated
|
|
||
| static testing::internal::ParamGenerator<tuple<Backend, Target>> dnnBackendsAndTargetsForFusionTests() | ||
| { | ||
| return dnnBackendsAndTargets(false, false, false, false); // only OpenCL |
There was a problem hiding this comment.
The fusion tests are checked for OpenCL only in 3.4. I am not sure if these should be enabled for other backends since they don't fuse activations or eltwise.
Note that this line might require special handling in 3.4 merge PR. The withCUDA appears before withNgraph on master. The tests should be turned on for CUDA.
|
Fusion information for the tests added by this PR after enabling debug printfs: https://gist.github.com/YashasSamaga/70e7fe1fc8c9d670c73eb7ea47ec592d The tests do not ensure that fusions do take place; they just check that the outputs match with the outputs from OCV CPU backend with fusions disabled. If a future PR accidentally stops a fusion, the tests will still pass since the unfused outputs will be corrected. I don't know if there is a way to enforce that fusions do take place. |
|
@dkurt @sl-sergei Could you look at it? |
| nextActivLayer = nextData->layerInstance.dynamicCast<ActivationLayer>(); | ||
|
|
||
| if( !nextActivLayer.empty() && pinsToKeep.count(lpNext) == 0 && | ||
| if( !nextActivLayer.empty() && |
There was a problem hiding this comment.
This change need not be propagated to master. The eltwise fusion logic is divergent. #17939 applies the same fix on master.
|
Can I squash the commits and rebase? Asking because it could break any reviews in progress. |
|
Tests seem to be failing in CI. I am not able to reproduce them locally. This indicates that OCV CPU backend with fusion disabled had a layer timing of And |
|
@YashasSamaga We will take a look on these failures. |
|
@YashasSamaga Please fix copy-parse typo (should fix current red custom builds too) and squash commits onto one. |
c9c8324 to
52f7bf4
Compare
| float conv_init_magnitude = 1.0f / in_channels / kernel_h / kernel_w; | ||
| int weightsShape[] = {num_filters, in_channels, kernel_h, kernel_w}; | ||
| Mat weights(4, &weightsShape[0], CV_32F); | ||
| randu(weights, -conv_init_magnitude, conv_init_magnitude); |
There was a problem hiding this comment.
I am not sure if this is a good initialization. The weights might be too small.
There was a problem hiding this comment.
Why do you think if that's a problem? I think it also good chance to track if we have no regressions with such kind of optimizations: #17295
There was a problem hiding this comment.
It will squeeze all weights to a very small range [-0.007, 0.007]. I don't think there is any serious problem but not sure.
Done. Sorry for the typo. Tests will fail on master if these tests are enabled for CUDA backend. Need to add some code for each test case indicating which layers are fused (the code enforcing the fusions expects no layers to be fused by default). I'll make a PR after this arrives in master to enable these tests for the CUDA backend. |
fixes #17946 for 3.4
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.