mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #24834 from fengyuentau:cuda_naryeltwise_broadcast
dnn (cuda): support broadcasting if a.rank() != b.rank() #24834 Inspired by https://github.com/opencv/opencv/pull/24786. This PR keeps the fusion of `NaryEltwise` and `Concat` while addressed the data missing problem via supporting broadcasting if a.rank() != b.rank(). Resolves https://github.com/opencv/opencv/issues/23977 Resolves https://github.com/opencv/opencv/issues/24606 Resolves https://github.com/opencv/opencv/issues/24635 Resolves https://github.com/opencv/opencv/issues/24721 ### 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
This commit is contained in:
@@ -102,6 +102,12 @@ public:
|
||||
Net net;
|
||||
};
|
||||
|
||||
TEST_P(DNNTestNetwork, DISABLED_YOLOv8n) {
|
||||
processNet("dnn/onnx/models/yolov8n.onnx", "", Size(640, 640), "output0");
|
||||
expectNoFallbacksFromIE(net);
|
||||
expectNoFallbacksFromCUDA(net);
|
||||
}
|
||||
|
||||
TEST_P(DNNTestNetwork, AlexNet)
|
||||
{
|
||||
applyTestTag(CV_TEST_TAG_MEMORY_1GB);
|
||||
@@ -1518,6 +1524,71 @@ INSTANTIATE_TEST_CASE_P(Layer_Test_Backends, Eltwise, testing::Combine(
|
||||
dnnBackendsAndTargets()
|
||||
));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Element-wise layers
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
using NaryEltwiseConcat = TestWithParam<tuple<std::vector<int>, tuple<Backend, Target>>>;
|
||||
TEST_P(NaryEltwiseConcat, Accuracy) {
|
||||
auto param = GetParam();
|
||||
std::vector<int> input_shape = get<0>(param);
|
||||
auto backend_id = get<0>(get<1>(param));
|
||||
auto target_id = get<1>(get<1>(param));
|
||||
|
||||
/* Build the following net:
|
||||
|
||||
<1x4x84>
|
||||
/
|
||||
[Input] -+-> Mul(B<1x84>) -> Concat(axis=1) -> [Output]
|
||||
| |
|
||||
+-> Sigmoid ----------+
|
||||
|
||||
*/
|
||||
Net net;
|
||||
|
||||
std::vector<int> mul_B_shape(input_shape.size() - 1, 1);
|
||||
mul_B_shape.back() = input_shape.back();
|
||||
Mat mul_B(mul_B_shape, CV_32FC1);
|
||||
randn(mul_B, 0.f, 1.f);
|
||||
LayerParams mul_B_lp;
|
||||
mul_B_lp.name = "mul_B";
|
||||
mul_B_lp.type = "Const";
|
||||
mul_B_lp.blobs.push_back(mul_B);
|
||||
int id_mul_B = net.addLayer(mul_B_lp.name, mul_B_lp.type, mul_B_lp);
|
||||
|
||||
LayerParams mul_lp;
|
||||
mul_lp.name = "mul";
|
||||
mul_lp.type = "NaryEltwise";
|
||||
mul_lp.set("operation", "mul");
|
||||
int id_mul = net.addLayer(mul_lp.name, mul_lp.type, mul_lp);
|
||||
net.connect(0, 0, id_mul, 0);
|
||||
net.connect(id_mul_B, 0, id_mul, 1);
|
||||
|
||||
LayerParams sigmoid_lp;
|
||||
sigmoid_lp.name = "sigmoid";
|
||||
sigmoid_lp.type = "Sigmoid";
|
||||
int id_sigmoid = net.addLayer(sigmoid_lp.name, sigmoid_lp.type, sigmoid_lp);
|
||||
net.connect(0, 0, id_sigmoid, 0);
|
||||
|
||||
LayerParams concat_lp;
|
||||
concat_lp.name = "concat";
|
||||
concat_lp.type = "Concat";
|
||||
concat_lp.set("axis", 1);
|
||||
int id_concat = net.addLayer(concat_lp.name, concat_lp.type, concat_lp);
|
||||
net.connect(id_mul, 0, id_concat, 0);
|
||||
net.connect(id_sigmoid, 0, id_concat, 1);
|
||||
|
||||
// Run test
|
||||
Mat input(input_shape, CV_32FC1);
|
||||
testLayer(input, net, backend_id, target_id, false);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Layer_Test_Backends, NaryEltwiseConcat, testing::Combine(
|
||||
testing::Values(std::vector<int>{1, 4, 84}),
|
||||
dnnBackendsAndTargets())
|
||||
);
|
||||
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Test_layers_backends, dnnBackendsAndTargets());
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user