mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 21:22:43 -06:00
dnn: return all false in IsInf when both detect flags are 0 (#31171)
Problem IsInf threw "Unsupported mode" when detect_positive and detect_negative were both 0. ONNX expects an all-false output in that case. Fix Fill the output with zeros in that branch instead of calling CV_Error.
This commit is contained in:
@@ -56,7 +56,7 @@ static inline void computeIsInfMask(const T* src, uchar* dst, const size_t count
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_Error_(Error::StsError, ("IsInf: Unsupported mode"));
|
||||
std::fill(dst, dst + count, (uchar)0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6224,4 +6224,24 @@ INSTANTIATE_TEST_CASE_P(/**/, Layer_Test_Reduce_Unsigned, Values(
|
||||
CV_64U
|
||||
));
|
||||
|
||||
TEST(Layer_Test_IsInf, NoDetection)
|
||||
{
|
||||
LayerParams lp;
|
||||
lp.type = "IsInf";
|
||||
lp.name = "testIsInf";
|
||||
lp.set("detect_positive", 0);
|
||||
lp.set("detect_negative", 0);
|
||||
Ptr<Layer> layer = LayerFactory::createLayerInstance("IsInf", lp);
|
||||
|
||||
const float inf = std::numeric_limits<float>::infinity();
|
||||
float data[] = {1.f, inf, -inf, 0.f};
|
||||
Mat input(1, 4, CV_32F, data);
|
||||
std::vector<Mat> inputs = {input}, outputs;
|
||||
runLayer(layer, inputs, outputs);
|
||||
|
||||
ASSERT_EQ(outputs.size(), (size_t)1);
|
||||
for (int i = 0; i < 4; i++)
|
||||
EXPECT_EQ(outputs[0].ptr<uchar>()[i], 0) << "index " << i;
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user