mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge pull request #27508 from abhishek-gola:if_layer_add
IfLayer add to new DNN engine #27508 ### 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:
@@ -2816,4 +2816,41 @@ TEST(Layer_LSTM, repeatedInference)
|
||||
EXPECT_EQ(diff2, 0.);
|
||||
}
|
||||
|
||||
TEST(Layer_If, resize)
|
||||
{
|
||||
// Skip this test when the classic DNN engine is explicitly requested. The
|
||||
// "if" layer is supported only by the new engine.
|
||||
auto engine_forced = static_cast<cv::dnn::EngineType>(
|
||||
cv::utils::getConfigurationParameterSizeT("OPENCV_FORCE_DNN_ENGINE", cv::dnn::ENGINE_AUTO));
|
||||
if (engine_forced == cv::dnn::ENGINE_CLASSIC)
|
||||
{
|
||||
// Mark the test as skipped and exit early.
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_PARSER);
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string imgname = findDataFile("cv/shared/lena.png", true);
|
||||
const std::string modelname = findDataFile("dnn/onnx/models/if_layer.onnx", true);
|
||||
|
||||
dnn::Net net = dnn::readNetFromONNX(modelname, ENGINE_NEW);
|
||||
Mat src = imread(imgname), blob;
|
||||
dnn::blobFromImage(src, blob, 1.0, cv::Size(), cv::Scalar(), false, false);
|
||||
|
||||
for (int f = 0; f <= 1; f++) {
|
||||
Mat cond(1, 1, CV_BoolC1, cv::Scalar(f));
|
||||
|
||||
net.setInput(cond, "cond");
|
||||
net.setInput(blob, "image");
|
||||
|
||||
std::vector<Mat> outs;
|
||||
net.forward(outs);
|
||||
|
||||
std::vector<Mat> images;
|
||||
dnn::imagesFromBlob(outs[0], images);
|
||||
EXPECT_EQ(images.size(), 1u);
|
||||
EXPECT_EQ(images[0].rows*(4 >> f), src.rows);
|
||||
EXPECT_EQ(images[0].cols*(4 >> f), src.cols);
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user