Skip to content

Commit

Permalink
Avoid misleading comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
t-jankowski committed Jul 12, 2024
1 parent a6bc763 commit 319a448
Showing 1 changed file with 3 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,11 @@ class PreprocessOpenCVReferenceTest : public testing::Test, public CommonReferen
/// between pixels is expected
class PreprocessOpenCVReferenceTest_8U : public PreprocessOpenCVReferenceTest {
public:
void Validate() override {
PreprocessOpenCVReferenceTest_8U() {
threshold = 1.f;
abs_threshold = 1.f;
// No pixels with deviation of more than 1 color step
CommonReferenceTest::Validate();
// Less than 2% of deviations with 1 color step. 2% is experimental value
// For very precise (acceptable) float calculations - 1.4% deviation with G-API/OpenCV is observed
ValidateColors(refOutData[0].data<uint8_t>(), actualOutData[0].data<uint8_t>(), refOutData[0].get_size(), 0.02);
}

private:
void ValidateColors(const uint8_t* expected,
const uint8_t* actual,
size_t size,
float dev_threshold,
float abs_threshold = 0.01f) {
size_t mismatches = 0;
for (size_t i = 0; i < size; i++) {
if (std::abs(static_cast<float>(expected[i]) - static_cast<float>(actual[i])) > abs_threshold) {
mismatches++;
}
}
ASSERT_LT(static_cast<float>(mismatches) / size, dev_threshold)
<< mismatches << " out of " << size << " color mismatches found which exceeds allowed threshold "
<< dev_threshold;
}
};

} // namespace

static std::shared_ptr<Model> create_simple_function(element::Type type, const PartialShape& shape) {
Expand Down Expand Up @@ -332,7 +309,7 @@ TEST_F(PreprocessOpenCVReferenceTest, resize_u8_simple_linear) {
}

// [CVS-132878]
TEST_F(PreprocessOpenCVReferenceTest_8U, DISABLED_resize_u8_large_picture_linear) {
TEST_F(PreprocessOpenCVReferenceTest_8U, resize_u8_large_picture_linear) {
const size_t input_height = 50;
const size_t input_width = 50;
const size_t func_height = 37;
Expand Down Expand Up @@ -432,4 +409,4 @@ TEST_F(PreprocessOpenCVReferenceTest, resize_f32_large_picture_cubic_small) {
Exec();
}

#endif // OPENCV_TEMPLATE_TESTS
#endif // OPENCV_TEMPLATE_TESTS

0 comments on commit 319a448

Please sign in to comment.