Skip to content

Commit

Permalink
refine matrixnms testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
luo-cheng2021 committed Jul 14, 2021
1 parent 32d6b9e commit 38b42dc
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,3 @@ void MKLDNNMatrixNmsNode::checkOutput(const SizeVector& dims, const std::vector<
}

REG_MKLDNN_PRIM_FOR(MKLDNNMatrixNmsNode, MatrixNms);

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace {
InferenceEngine::Precision::FP16
};

/* ============= NO MAX SUPPRESSION ============= */

const std::vector<InputShapeParams> inShapeParams = {
InputShapeParams{3, 100, 5},
InputShapeParams{1, 10, 50},
Expand All @@ -30,24 +28,31 @@ namespace {
const std::vector<op::v8::MatrixNms::SortResultType> sortResultType = {op::v8::MatrixNms::SortResultType::CLASSID,
op::v8::MatrixNms::SortResultType::SCORE,
op::v8::MatrixNms::SortResultType::NONE};
const std::vector<bool> sortResultAcrossBatch = {true, false};
const std::vector<element::Type> outType = {element::i32, element::i64};
const std::vector<int> nmsTopK = {10, 100};
const std::vector<int> keepTopK = {10, 5};
const std::vector<TopKParams> topKParams = {
{-1, 5},
{100, -1}
};
const std::vector<ThresholdParams> thresholdParams = {
{0.0f, 2.0f, 0.0f},
{0.1f, 1.5f, 0.2f}
};
const std::vector<int> nmsTopK = {-1, 100};
const std::vector<int> keepTopK = {-1, 5};
const std::vector<int> backgroudClass = {-1, 0};
const std::vector<bool> normalized = {true, false};
const std::vector<op::v8::MatrixNms::DecayFunction> decayFunction = {op::v8::MatrixNms::DecayFunction::GAUSSIAN,
op::v8::MatrixNms::DecayFunction::LINEAR};

const auto nmsParams = ::testing::Combine(::testing::ValuesIn(inShapeParams),
::testing::Combine(::testing::Values(InferenceEngine::Precision::FP32),
::testing::Values(InferenceEngine::Precision::I32),
::testing::Values(InferenceEngine::Precision::FP32)),
::testing::ValuesIn(sortResultType),
::testing::ValuesIn(sortResultAcrossBatch),
::testing::ValuesIn(outType),
::testing::ValuesIn(nmsTopK),
::testing::ValuesIn(keepTopK),
::testing::ValuesIn(topKParams),
::testing::ValuesIn(thresholdParams),
::testing::ValuesIn(backgroudClass),
::testing::ValuesIn(normalized),
::testing::ValuesIn(decayFunction),
::testing::Values(CommonTestUtils::DEVICE_CPU));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ const std::vector<InputShapeParams> inShapeParams = {
const std::vector<op::v8::MatrixNms::SortResultType> sortResultType = {op::v8::MatrixNms::SortResultType::CLASSID,
op::v8::MatrixNms::SortResultType::SCORE,
op::v8::MatrixNms::SortResultType::NONE};
const std::vector<bool> sortResultAcrossBatch = {true, false};
const std::vector<element::Type> outType = {element::i32, element::i64};
const std::vector<TopKParams> topKParams = {
{-1, 5},
{100, -1}
};
const std::vector<ThresholdParams> thresholdParams = {
{0.0f, 2.0f, 0.0f},
{0.1f, 1.5f, 0.2f}
};
const std::vector<int> nmsTopK = {-1, 100};
const std::vector<int> keepTopK = {-1, 5};
const std::vector<int> backgroudClass = {-1, 0};
const std::vector<bool> normalized = {true, false};
const std::vector<op::v8::MatrixNms::DecayFunction> decayFunction = {op::v8::MatrixNms::DecayFunction::GAUSSIAN,
op::v8::MatrixNms::DecayFunction::LINEAR};

Expand All @@ -34,11 +42,11 @@ const auto nmsParams = ::testing::Combine(::testing::ValuesIn(inShapeParams),
::testing::Values(Precision::I32),
::testing::Values(Precision::FP32)),
::testing::ValuesIn(sortResultType),
::testing::ValuesIn(sortResultAcrossBatch),
::testing::ValuesIn(outType),
::testing::ValuesIn(nmsTopK),
::testing::ValuesIn(keepTopK),
::testing::ValuesIn(topKParams),
::testing::ValuesIn(thresholdParams),
::testing::ValuesIn(backgroudClass),
::testing::ValuesIn(normalized),
::testing::ValuesIn(decayFunction),
::testing::Values(CommonTestUtils::DEVICE_CPU)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ using InputPrecisions = std::tuple<InferenceEngine::Precision, // boxes and sco
InferenceEngine::Precision, // max_output_boxes_per_class precision
InferenceEngine::Precision>; // iou_threshold, score_threshold, soft_nms_sigma precisions

using TopKParams = std::tuple<int, // Maximum number of boxes to be selected per class
int>; // Maximum number of boxes to be selected per batch element

using ThresholdParams = std::tuple<float, // minimum score to consider box for the processing
float, // gaussian_sigma parameter for gaussian decay_function
float>; // filter out boxes with low confidence score after decaying

using NmsParams = std::tuple<InputShapeParams, // Params using to create 1st and 2nd inputs
InputPrecisions, // Input precisions
ngraph::op::v8::MatrixNms::SortResultType, // Order of output elements
bool, // Sort selected boxes across batches or not
ngraph::element::Type, // Output type
int, // Maximum number of boxes to be selected per class
int, // Maximum number of boxes to be selected per batch element
TopKParams, // Maximum number of boxes topk params
ThresholdParams, // Thresholds: score_threshold, gaussian_sigma, post_threshold
int, // Background class id
bool, // If boxes are normalized
ngraph::op::v8::MatrixNms::DecayFunction, // Decay function
std::string>; // Device name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,36 @@ std::string MatrixNmsLayerTest::getTestCaseName(testing::TestParamInfo<NmsParams
InputShapeParams inShapeParams;
InputPrecisions inPrecisions;
op::v8::MatrixNms::SortResultType sortResultType;
bool sortResultAcrossBatch;
element::Type outType;
int nmsTopK, keepTopK, backgroudClass;
int backgroudClass;
op::v8::MatrixNms::DecayFunction decayFunction;
TopKParams topKParams;
ThresholdParams thresholdParams;
bool normalized;
std::string targetDevice;
std::tie(inShapeParams, inPrecisions, sortResultType, sortResultAcrossBatch, outType, nmsTopK, keepTopK,
backgroudClass, decayFunction, targetDevice) = obj.param;
std::tie(inShapeParams, inPrecisions, sortResultType, outType, topKParams, thresholdParams,
backgroudClass, normalized, decayFunction, targetDevice) = obj.param;

size_t numBatches, numBoxes, numClasses;
std::tie(numBatches, numBoxes, numClasses) = inShapeParams;

Precision paramsPrec, maxBoxPrec, thrPrec;
std::tie(paramsPrec, maxBoxPrec, thrPrec) = inPrecisions;

int nmsTopK, keepTopK;
std::tie(nmsTopK, keepTopK) = topKParams;

float score_threshold, gaussian_sigma, post_threshold;
std::tie(score_threshold, gaussian_sigma, post_threshold) = thresholdParams;

std::ostringstream result;
result << "numBatches=" << numBatches << "_numBoxes=" << numBoxes << "_numClasses=" << numClasses << "_";
result << "paramsPrec=" << paramsPrec << "_maxBoxPrec=" << maxBoxPrec << "_thrPrec=" << thrPrec << "_";
result << "sortResultType=" << sortResultType << "_sortResultAcrossBatch=" << sortResultAcrossBatch << "_";
result << "sortResultType=" << sortResultType << "_normalized=" << normalized << "_";
result << "outType=" << outType << "_nmsTopK=" << nmsTopK << "_keepTopK=" << keepTopK << "_";
result << "backgroudClass=" << backgroudClass << "_decayFunction=" << decayFunction << "_";
result << "TargetDevice=" << targetDevice;
result << "score_threshold=" << score_threshold << "_gaussian_sigma=" << gaussian_sigma << "_";
result << "post_threshold=" << post_threshold << "_TargetDevice=" << targetDevice;
return result.str();
}

Expand Down Expand Up @@ -187,11 +196,6 @@ void MatrixNmsLayerTest::Compare(const std::vector<std::pair<ngraph::element::Ty
default:
break;
}
// TODO: test usage only, dynamic shape do not need check the tail value
//const auto iBuffer = lockedMemory.as<const int *>();
//for (int i = size; i < actual->size(); i++) {
// ASSERT_TRUE(iBuffer[i] == -1) << "Invalid default value: " << iBuffer[i] << " at index: " << i;
//}
break;
}
default:
Expand All @@ -205,13 +209,14 @@ void MatrixNmsLayerTest::SetUp() {
InputShapeParams inShapeParams;
InputPrecisions inPrecisions;
op::v8::MatrixNms::Attributes attrs;
attrs.score_threshold = 0.5f;

std::tie(inShapeParams, inPrecisions, attrs.sort_result_type, attrs.sort_result_across_batch,
attrs.output_type, attrs.nms_top_k, attrs.keep_top_k,
attrs.background_class, attrs.decay_function, targetDevice) = this->GetParam();
TopKParams topKParams;
ThresholdParams thresholdParams;

std::tie(inShapeParams, inPrecisions, attrs.sort_result_type, attrs.output_type, topKParams, thresholdParams,
attrs.background_class, attrs.normalized, attrs.decay_function, targetDevice) = this->GetParam();

std::tie(attrs.nms_top_k, attrs.keep_top_k) = topKParams;
std::tie(attrs.score_threshold, attrs.gaussian_sigma, attrs.post_threshold) = thresholdParams;
std::tie(numBatches, numBoxes, numClasses) = inShapeParams;
auto realClasses = numClasses;
if (attrs.background_class >=0 && attrs.background_class <= numClasses) {
Expand Down

0 comments on commit 38b42dc

Please sign in to comment.