Skip to content

Commit

Permalink
[Tmpl test] ExperimentalDetectronPriorGridGenerator: Drop legacy comp…
Browse files Browse the repository at this point in the history
…arison (#24592)

### Details:
- Removed 'actual comparison size' parameter from base template test
class `CommonReferenceTest`.
- Moved partial comparison logic to
`ReferenceExperimentalPGGLayerTest::Validate()` - it's needed only in
this test.

### Tickets:
 - CVS-137159
  • Loading branch information
t-jankowski committed May 22, 2024
1 parent 0eab4ef commit 6f7cf28
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ void CommonReferenceTest::Validate() {

ASSERT_EQ(refOutData.size(), actualOutData.size());
for (size_t i = 0; i < refOutData.size(); i++) {
ValidateBlobs(refOutData[i],
actualOutData[i],
i,
threshold,
abs_threshold,
legacy_compare,
actual_comparision_size);
ValidateBlobs(refOutData[i], actualOutData[i], i, threshold, abs_threshold, legacy_compare);
}
}

Expand All @@ -91,15 +85,12 @@ void CommonReferenceTest::ValidateBlobs(const ov::Tensor& refBlob,
const size_t blob_idx,
float threshold,
float abs_threshold,
bool legacy_compare,
size_t actual_comparision_size) {
bool legacy_compare) {
ASSERT_EQ(refBlob.get_element_type(), outBlob.get_element_type())
<< "Incompatible element type for blob with index " << blob_idx;
ASSERT_EQ(refBlob.get_byte_size(), outBlob.get_byte_size())
<< "Incorrect byte size for blob with index " << blob_idx;

if (actual_comparision_size == 0)
actual_comparision_size = refBlob.get_size();
// compare() get fundamental element type with element_type_traits firstly and cast data to relative ov type with
// 'from' types listed below have a fundamental analogue as int8_t, but int8_t is converted only to i8 with from
std::vector<ov::element::Type> raw_data_comp_only =
Expand Down Expand Up @@ -133,6 +124,8 @@ void CommonReferenceTest::ValidateBlobs(const ov::Tensor& refBlob,
}
return;
}

const auto actual_comparision_size = refBlob.get_size();
switch (element_type) {
case ov::element::bf16:
ov::test::utils::compare_raw_data<ov::bfloat16, ov::bfloat16>(refBlob.data<const ov::bfloat16>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class CommonReferenceTest {
const size_t blob_idx,
float threshold,
float abs_threshold,
bool legacy_compare,
size_t actual_comparision_size);
bool legacy_compare);

protected:
bool legacy_compare = false;
Expand All @@ -42,9 +41,8 @@ class CommonReferenceTest {
std::vector<ov::Tensor> inputData;
std::vector<ov::Tensor> refOutData;
std::vector<ov::Tensor> actualOutData;
float threshold = 1e-2f; // Relative diff
float abs_threshold = -1.f; // Absolute diff (not used when negative)
size_t actual_comparision_size = 0; // For ref output data is smaller than output blob size
float threshold = 1e-2f; // Relative diff
float abs_threshold = -1.f; // Absolute diff (not used when negative)
};

template <class T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include "base_reference_test.hpp"
#include "openvino/op/experimental_detectron_prior_grid_generator.hpp"

using namespace reference_tests;
using namespace ov;

using reference_tests::CommonReferenceTest;
using reference_tests::CreateTensor;
using Attrs = op::v6::ExperimentalDetectronPriorGridGenerator::Attributes;

namespace {
Expand All @@ -30,7 +31,6 @@ struct ExperimentalPGGParams {
imageSizeInfoShape(imageSizeInfoShape),
outRefShape(outRefShape),
inType(iType),
outType(iType),
priorsData(CreateTensor(iType, priorsValues)),
refData(CreateTensor(outRefShape, iType, refValues)),
testcaseName(testcaseName) {
Expand All @@ -54,36 +54,30 @@ struct ExperimentalPGGParams {
PartialShape imageSizeInfoShape;
Shape outRefShape;
size_t actualComparisonSize;
ov::element::Type inType;
ov::element::Type outType;
ov::Tensor priorsData;
ov::Tensor featureMapData;
ov::Tensor imageSizeInfoData;
ov::Tensor refData;
element::Type inType;
Tensor priorsData;
Tensor featureMapData;
Tensor imageSizeInfoData;
Tensor refData;
std::string testcaseName;
};

class ReferenceExperimentalPGGLayerTest : public testing::TestWithParam<ExperimentalPGGParams>,
public CommonReferenceTest {
public:
void SetUp() override {
legacy_compare = true;
auto params = GetParam();
const auto& params = GetParam();
function = CreateFunction(params);
inputData = {params.priorsData, params.featureMapData, params.imageSizeInfoData};
refOutData = {params.refData};

if (params.actualComparisonSize > 0)
actual_comparision_size = params.actualComparisonSize;
}
static std::string getTestCaseName(const testing::TestParamInfo<ExperimentalPGGParams>& obj) {
auto param = obj.param;
const auto& param = obj.param;
std::ostringstream result;
result << "priorsShape=" << param.priorsShape << "_";
result << "featureMapShape=" << param.featureMapShape << "_";
result << "imageSizeInfoShape=" << param.imageSizeInfoShape << "_";
result << "iType=" << param.inType << "_";
result << "oType=" << param.outType << "_";
result << "flatten=" << param.attrs.flatten << "_";
result << "h=" << param.attrs.h << "_";
result << "w=" << param.attrs.w << "_";
Expand All @@ -94,6 +88,26 @@ class ReferenceExperimentalPGGLayerTest : public testing::TestWithParam<Experime
return result.str();
}

virtual void Validate() override {
if (const auto comparison_size = GetParam().actualComparisonSize) {
ASSERT_EQ(executableNetwork.outputs().size(), refOutData.size());

actualOutData.clear();
actualOutData.emplace_back(inferRequest.get_tensor(executableNetwork.output(0)));

// Shape matters: the trick is that hard-coded expected data is "shorter" than runtime inferred data. This
// is due to huge size of the tensor and in such case the test provides a part of reference values for
// comparison to avoid huge file size.
ASSERT_EQ(refOutData[0].get_shape(), actualOutData[0].get_shape());
const auto shape = Shape{comparison_size};
const auto expected = Tensor{refOutData[0].get_element_type(), shape, refOutData[0].data()};
const auto inferred = Tensor{actualOutData[0].get_element_type(), shape, actualOutData[0].data()};
ValidateBlobs(expected, inferred, 0, threshold, abs_threshold, false);
} else {
CommonReferenceTest::Validate();
}
}

private:
static std::shared_ptr<Model> CreateFunction(const ExperimentalPGGParams& params) {
const auto priors = std::make_shared<op::v0::Parameter>(params.inType, params.priorsShape);
Expand All @@ -103,7 +117,7 @@ class ReferenceExperimentalPGGLayerTest : public testing::TestWithParam<Experime
featureMap,
im_info,
params.attrs);
return std::make_shared<ov::Model>(NodeVector{ExperimentalPGG}, ParameterVector{priors, featureMap, im_info});
return std::make_shared<Model>(NodeVector{ExperimentalPGG}, ParameterVector{priors, featureMap, im_info});
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ class ReferenceMemoryTest : public testing::TestWithParam<MemoryTestParams> {
i,
1e-2f,
-1.f,
true,
0);
true);
}
}

Expand Down

0 comments on commit 6f7cf28

Please sign in to comment.