Skip to content

Commit

Permalink
Correct input generation for ROI pooling in func tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorDuplensky committed Apr 26, 2021
1 parent 62cbd30 commit 6fff6e7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ struct jit_uni_roi_pooling_kernel_f32 : public jit_uni_roi_pooling_kernel, publi

for (int i = 0; i < c_blocks; i++) {
int src_c_off = i * jpp_.ih * jpp_.iw * jpp_.c_block * jpp_.src_data_size;
auto load_context = std::make_shared<load_emitter_context>(jpp_.src_prc, Precision::FP32, step, false, "zero", src_c_off);
const auto load_context = std::make_shared<load_emitter_context>(jpp_.src_prc, Precision::FP32, step, false, "zero", src_c_off);

mov(aux_reg_input, reg_input);

Expand Down Expand Up @@ -555,7 +555,7 @@ void MKLDNNROIPoolingNode::execute() {
} else {
for (int h = hstart; h < hend; ++h) {
for (int w = wstart; w < wend; ++w) {
T batch_data = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
float batch_data = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
h * src_strides[2] + w * src_strides[3] + c];

if (batch_data > dst[pool_index]) {
Expand All @@ -567,17 +567,17 @@ void MKLDNNROIPoolingNode::execute() {
}
}
} else {
T roi_start_w_ = src_roi_ptr[1];
T roi_start_h_ = src_roi_ptr[2];
T roi_end_w_ = src_roi_ptr[3];
T roi_end_h_ = src_roi_ptr[4];
float roi_start_w_ = src_roi_ptr[1];
float roi_start_h_ = src_roi_ptr[2];
float roi_end_w_ = src_roi_ptr[3];
float roi_end_h_ = src_roi_ptr[4];

T height_scale = (jpp.pooled_h > 1 ? ((roi_end_h_ - roi_start_h_) * (jpp.ih - 1)) / (jpp.pooled_h - 1) : 0);
T width_scale = (jpp.pooled_w > 1 ? ((roi_end_w_ - roi_start_w_) * (jpp.iw - 1)) / (jpp.pooled_w - 1) : 0);
float height_scale = (jpp.pooled_h > 1 ? ((roi_end_h_ - roi_start_h_) * (jpp.ih - 1)) / (jpp.pooled_h - 1) : 0);
float width_scale = (jpp.pooled_w > 1 ? ((roi_end_w_ - roi_start_w_) * (jpp.iw - 1)) / (jpp.pooled_w - 1) : 0);

T in_y = (jpp.pooled_h > 1 ? (oh * height_scale + roi_start_h_ * (jpp.ih - 1)) :
float in_y = (jpp.pooled_h > 1 ? (oh * height_scale + roi_start_h_ * (jpp.ih - 1)) :
0.5 * (roi_start_h_ + roi_end_h_) * (jpp.ih - 1));
T in_x = (jpp.pooled_w > 1 ? (ow * width_scale + roi_start_w_ * (jpp.iw - 1)) :
float in_x = (jpp.pooled_w > 1 ? (ow * width_scale + roi_start_w_ * (jpp.iw - 1)) :
0.5 * (roi_start_w_ + roi_end_w_) * (jpp.iw - 1));

if (in_y < 0 || in_y > jpp.ih - 1 || in_x < 0 || in_x > jpp.iw - 1) {
Expand Down Expand Up @@ -616,20 +616,20 @@ void MKLDNNROIPoolingNode::execute() {
arg.bin_area = 1;
} else {
for (int c = 0; c < 1; c++) {
const T top_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
const float top_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
top_y_index * src_strides[2] + left_x_index * src_strides[3] + c];
const T top_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
const float top_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
top_y_index * src_strides[2] + right_x_index * src_strides[3] + c];
const T bottom_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
const float bottom_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
bottom_y_index * src_strides[2] + left_x_index * src_strides[3] + c];
const T bottom_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
const float bottom_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] +
bottom_y_index * src_strides[2] + right_x_index * src_strides[3] + c];

const T top = top_left + (top_right - top_left) * (in_x - left_x_index);
const T bottom = bottom_left + (bottom_right - bottom_left) * (in_x - left_x_index);
const float top = top_left + (top_right - top_left) * (in_x - left_x_index);
const float bottom = bottom_left + (bottom_right - bottom_left) * (in_x - left_x_index);

dst[n * dst_strides[0] + cb * dst_strides[1] + oh * dst_strides[2] + ow * dst_strides[3] + c] =
top + (bottom - top) * (in_y - top_y_index);
top + (bottom - top) * (in_y - top_y_index);
}
}
}
Expand All @@ -650,8 +650,6 @@ struct ROIPoolingContext {

template<typename T>
struct MKLDNNROIPoolingNode::ROIPoolingExecute {
// using dataT = typename T::type;

void operator()(ROIPoolingContext & ctx) {
ctx.node.execute<T>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ class MKLDNNROIPoolingNode : public MKLDNNNode {
void createPrimitive() override;
void execute(mkldnn::stream strm) override;
bool created() const override;

private:
template<typename T> void execute();
template<typename T> struct ROIPoolingExecute;

private:
InferenceEngine::Precision runtimePrecision;

size_t src_data_size;
size_t dst_data_size;

InferenceEngine::Precision runtimePrecision;

int pooled_h = 0;
int pooled_w = 0;
float spatial_scale = 0;
ROIPoolingOpType opType = Max;

jit_roi_pooling_params jpp = {};

std::shared_ptr<jit_uni_roi_pooling_kernel> roi_pooling_kernel = nullptr;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
//
#include <shared_test_classes/single_layer/roi_pooling.hpp>
#include "ie_common.h"
#include "test_utils/cpu_test_utils.hpp"
#include "utils/bfloat16.hpp"

using namespace InferenceEngine;
using namespace CPUTestUtils;
Expand Down Expand Up @@ -67,7 +69,21 @@ class ROIPoolingCPULayerTest : public testing::WithParamInterface<ROIPoolingCPUT
if (it == 1) {
blob = make_blob_with_precision(info->getTensorDesc());
blob->allocate();
CommonTestUtils::fill_data_roi(blob->buffer(), blob->size(), feat_map_shape[0] - 1, height, width, 1.0f, is_roi_max_mode);
switch (inPrc) {
case Precision::FP32: {
CommonTestUtils::fill_data_roi<float>
(blob->buffer(), blob->size(), feat_map_shape[0] - 1, height, width, 1.0f, is_roi_max_mode);
break;
}
case Precision::BF16: {
CommonTestUtils::fill_data_roi<MKLDNNPlugin::bfloat16_t>
(blob->buffer(), blob->size(), feat_map_shape[0] - 1, height, width, 1.0f, is_roi_max_mode);
break;
}
default:
IE_THROW() << "roi_pooling. Unsupported precision";
break;
}
} else {
blob = GenerateInput(*info);
}
Expand All @@ -86,8 +102,6 @@ class ROIPoolingCPULayerTest : public testing::WithParamInterface<ROIPoolingCPUT
InferenceEngine::SizeVector poolShape;
InferenceEngine::Precision netPrecision;

// threshold = 0.08f;

std::tie(basicParamsSet, cpuParams, additionalConfig) = this->GetParam();
std::tie(inFmts, outFmts, priority, selectedType) = cpuParams;
std::tie(inputShape, coordsShape, poolShape, spatial_scale, pool_method, netPrecision, targetDevice) = basicParamsSet;
Expand All @@ -106,7 +120,8 @@ class ROIPoolingCPULayerTest : public testing::WithParamInterface<ROIPoolingCPUT

function = makeNgraphFunction(ngPrc, params, roi_pooling, "roi_pooling");

selectedType = getPrimitiveType() + "_" + netPrecision.name();
selectedType += "_";
selectedType += netPrecision.name();
}

private:
Expand Down Expand Up @@ -141,17 +156,24 @@ std::vector<CPUSpecificParams> filterCPUInfoForDevice() {
return resCPUParams;
}

const std::vector<std::vector<size_t>> inShapes = {{1, 3, 8, 8}, {3, 4, 50, 50}};
const std::vector<std::vector<size_t>> inShapes = {{1, 3, 8, 8},
{3, 4, 50, 50}};

const std::vector<std::vector<size_t>> pooledShapes_max = {{1, 1}, {2, 2}, {3, 3}, {6, 6}};
const std::vector<std::vector<size_t>> pooledShapes_max = {{1, 1},
{2, 2},
{3, 3},
{6, 6}};

const std::vector<std::vector<size_t>> pooledShapes_bilinear = {{1, 1}, {2, 2}, {3, 3}, {6, 6}};
const std::vector<std::vector<size_t>> pooledShapes_bilinear = {{1, 1},
{2, 2},
{3, 3},
{6, 6}};

const std::vector<std::vector<size_t>> coordShapes = {{1, 5}};
// {3, 5},
// {5, 5}};
const std::vector<std::vector<size_t>> coordShapes = {{1, 5},
{3, 5},
{5, 5}};

const std::vector<InferenceEngine::Precision> netPRCs = {InferenceEngine::Precision::BF16, InferenceEngine::Precision::FP32};
const std::vector<InferenceEngine::Precision> netPRCs = {InferenceEngine::Precision::FP32, InferenceEngine::Precision::BF16};

const std::vector<float> spatial_scales = {0.625f, 1.f};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ InferenceEngine::Blob::Ptr generate(const std::shared_ptr<ngraph::op::v0::ROIPoo
blob = make_blob_with_precision(info.getTensorDesc());
blob->allocate();

CommonTestUtils::fill_data_roi(blob->buffer(),
blob->size(),
node->get_input_shape(0).front() - 1,
inputShape[2],
inputShape[3],
1.0f,
node->get_method() == "max");
CommonTestUtils::fill_data_roi<float>(blob->buffer(),
blob->size(),
node->get_input_shape(0).front() - 1,
inputShape[2],
inputShape[3],
1.0f,
node->get_method() == "max");
return blob;
}
return FuncTestUtils::createAndFillBlob(info.getTensorDesc());
Expand Down Expand Up @@ -582,4 +582,4 @@ InputsMap getInputMap() {
return inputsMap;
}

} // namespace LayerTestsDefinitions
} // namespace LayerTestsDefinitions
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ namespace LayerTestsDefinitions {
if (it == 1) {
blob = make_blob_with_precision(info->getTensorDesc());
blob->allocate();
CommonTestUtils::fill_data_roi(blob->buffer(), blob->size(), feat_map_shape[0] - 1,
height, width, 1.0f, is_roi_max_mode);
CommonTestUtils::fill_data_roi<float>(blob->buffer(), blob->size(), feat_map_shape[0] - 1,
height, width, 1.0f, is_roi_max_mode);
} else {
blob = GenerateInput(*info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ inline void fill_data_bbox(float *data, size_t size, int height, int width, floa
}
}

template <typename T>
inline void
fill_data_roi(float *data, size_t size, const uint32_t range, const int height, const int width, const float omega,
fill_data_roi(T *data, size_t size, const uint32_t range, const int height, const int width, const float omega,
const bool is_roi_max_mode, const int seed = 1) {
std::default_random_engine random(seed);
std::uniform_int_distribution<int32_t> distribution(0, range);
Expand Down

0 comments on commit 6fff6e7

Please sign in to comment.