Added PreprocessConversionTest tests (#4946)

* Added PreprocessConversionTest tests

* Disabled tests on GPU: CVS-51764

* Disabled some tests on VPU and TEMPLATE

* Support for input layout conversions in TEMPLATE plugin
This commit is contained in:
Ilya Lavrenov
2021-03-25 16:31:33 +03:00
committed by GitHub
parent 2a52747b03
commit 8e261de0a8
15 changed files with 396 additions and 66 deletions
@@ -69,43 +69,48 @@ void TemplateInferRequest::allocateDeviceBuffers() {
}
template<typename BlobDataMap, typename GetNetworkPrecisionF>
static void AllocateImpl(const BlobDataMap& blobDataMap,
BlobMap& blobMap,
BlobMap& networkBlobMap,
static void AllocateImpl(const BlobDataMap& userDataMap,
BlobMap& userBlobMap,
BlobMap& deviceBlobMap,
GetNetworkPrecisionF&& GetNetworkPrecision) {
for (auto&& blobData : blobDataMap) {
auto& dims = blobData.second->getTensorDesc().getDims();
auto& precision = blobData.second->getTensorDesc().getPrecision();
auto layout = blobData.second->getTensorDesc().getLayout();
Blob::Ptr blob;
switch (precision) {
case Precision::U8: {
blob = InferenceEngine::make_shared_blob<std::uint8_t>({precision, dims, layout});
} break;
case Precision::FP32 : {
blob = InferenceEngine::make_shared_blob<float>({precision, dims, layout});
} break;
default: IE_THROW() << "Template Plugin: Unsupported Input/Output Presision";
}
blob->allocate();
blobMap[blobData.first] = blob;
for (auto&& userData : userDataMap) {
auto& dims = userData.second->getTensorDesc().getDims();
const auto devicePrecision = Precision::FP32;
const auto deviceLayout = TensorDesc::getLayoutByDims(dims);
auto userPrecision = userData.second->getTensorDesc().getPrecision();
auto userLayout = userData.second->getTensorDesc().getLayout();
auto networkPresion = GetNetworkPrecision(blobData.first);
Blob::Ptr networkBlob;
switch (networkPresion) {
case ngraph::element::Type_t::f32 : {
if (precision == Precision::FP32) {
networkBlob = blob;
} else {
networkBlob = InferenceEngine::make_shared_blob<float>({Precision::FP32, dims, layout});
}
} break;
default: IE_THROW() << "Template Plugin: Unsupported network Input/Output Presision";
Blob::Ptr userBlob;
switch (userPrecision) {
case Precision::U8: {
userBlob = InferenceEngine::make_shared_blob<std::uint8_t>({userPrecision, dims, userLayout});
} break;
case Precision::FP32 : {
userBlob = InferenceEngine::make_shared_blob<float>({userPrecision, dims, userLayout});
} break;
default: IE_THROW() << "Template Plugin: Unsupported Input/Output Precision";
}
if (blob != networkBlob) {
networkBlob->allocate();
userBlob->allocate();
userBlobMap[userData.first] = userBlob;
auto networkPrecision = GetNetworkPrecision(userData.first);
Blob::Ptr deviceBlob;
switch (networkPrecision) {
case ngraph::element::Type_t::f32 : {
if (userPrecision == devicePrecision && userLayout == deviceLayout) {
deviceBlob = userBlob;
} else {
deviceBlob = InferenceEngine::make_shared_blob<float>({devicePrecision, dims, deviceLayout});
}
} break;
default: IE_THROW() << "Template Plugin: Unsupported network Input/Output Presision";
}
networkBlobMap[blobData.first] = networkBlob;
// preprocessing converts user input blob to desired device input blob automatically
// NOTE: this is not supported for output user blobs yet
if (userBlob != deviceBlob) {
deviceBlob->allocate();
}
deviceBlobMap[userData.first] = deviceBlob;
}
}
@@ -14,6 +14,7 @@
#include <ngraph/opsets/opset.hpp>
#include <transformations/common_optimizations/common_optimizations.hpp>
#include <transformations/rt_info/fused_names_attribute.hpp>
#include <transformations/convert_precision.hpp>
#include "template/template_config.hpp"
#include "template_itt.hpp"
@@ -58,6 +59,8 @@ std::shared_ptr<ngraph::Function> TransformNetwork(const std::shared_ptr<const n
ngraph::pass::Manager passManager;
// Example: register CommonOptimizations transformation from transformations library
passManager.register_pass<ngraph::pass::CommonOptimizations>();
// Template plugin handles only FP32 networks
passManager.register_pass<ngraph::pass::ConvertPrecision>(ngraph::element::f16, ngraph::element::f32);
// Example: register plugin specific transformation
passManager.register_pass<ngraph::pass::DecomposeDivideMatcher>();
passManager.register_pass<ngraph::pass::ReluReluFusionMatcher>();
@@ -26,4 +26,32 @@ INSTANTIATE_TEST_CASE_P(smoke_BehaviorTests, PreprocessTest,
::testing::ValuesIn(configs)),
PreprocessTest::getTestCaseName);
const std::vector<InferenceEngine::Precision> ioPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::U8
};
const std::vector<InferenceEngine::Layout> netLayouts = {
InferenceEngine::Layout::NCHW,
// InferenceEngine::Layout::NHWC
};
const std::vector<InferenceEngine::Layout> ioLayouts = {
InferenceEngine::Layout::NCHW,
InferenceEngine::Layout::NHWC
};
INSTANTIATE_TEST_CASE_P(smoke_BehaviorTests, PreprocessConversionTest,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(netLayouts),
::testing::ValuesIn(ioLayouts),
::testing::ValuesIn(ioLayouts),
::testing::Bool(),
::testing::Bool(),
::testing::Values(CommonTestUtils::DEVICE_TEMPLATE),
::testing::ValuesIn(configs)),
PreprocessConversionTest::getTestCaseName);
} // namespace
@@ -14,6 +14,7 @@ namespace {
// ! [test_convolution:declare_parameters]
const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
};
/* ============= 2D Convolution ============= */
@@ -112,7 +113,7 @@ const auto conv3DParams_AutoPadValid = ::testing::Combine(
::testing::Values(ngraph::op::PadType::VALID)
);
INSTANTIATE_TEST_CASE_P(Convolution3D_ExplicitPadding, ConvolutionLayerTest,
INSTANTIATE_TEST_CASE_P(smoke_Convolution3D_ExplicitPadding, ConvolutionLayerTest,
::testing::Combine(
conv3DParams_ExplicitPadding,
::testing::ValuesIn(netPrecisions),
@@ -124,7 +125,7 @@ INSTANTIATE_TEST_CASE_P(Convolution3D_ExplicitPadding, ConvolutionLayerTest,
::testing::Values(CommonTestUtils::DEVICE_TEMPLATE)),
ConvolutionLayerTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(Convolution3D_AutoPadValid, ConvolutionLayerTest,
INSTANTIATE_TEST_CASE_P(nightly_Convolution3D_AutoPadValid, ConvolutionLayerTest,
::testing::Combine(
conv3DParams_AutoPadValid,
::testing::ValuesIn(netPrecisions),
@@ -14,7 +14,7 @@ const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
};
INSTANTIATE_TEST_CASE_P(ReshapeCheckDynBatch, ReshapeLayerTest,
INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheckDynBatch, ReshapeLayerTest,
::testing::Combine(
::testing::Values(true),
::testing::ValuesIn(netPrecisions),
@@ -28,7 +28,7 @@ INSTANTIATE_TEST_CASE_P(ReshapeCheckDynBatch, ReshapeLayerTest,
::testing::Values(std::map<std::string, std::string>({}))),
ReshapeLayerTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(ReshapeCheck, ReshapeLayerTest,
INSTANTIATE_TEST_CASE_P(smoke_ReshapeCheck, ReshapeLayerTest,
::testing::Combine(
::testing::Values(true),
::testing::ValuesIn(netPrecisions),
@@ -42,7 +42,7 @@ const auto params2D = testing::Combine(
);
INSTANTIATE_TEST_CASE_P(
SoftMax2D,
smoke_SoftMax2D,
SoftMaxLayerTest,
params2D,
SoftMaxLayerTest::getTestCaseName
@@ -69,7 +69,7 @@ const auto params4D = testing::Combine(
);
INSTANTIATE_TEST_CASE_P(
SoftMax4D,
smoke_SoftMax4D,
SoftMaxLayerTest,
params4D,
SoftMaxLayerTest::getTestCaseName
@@ -11,7 +11,7 @@ using namespace LayerTestsDefinitions;
namespace {
INSTANTIATE_TEST_CASE_P(NumSplitsCheck, SplitLayerTest,
INSTANTIATE_TEST_CASE_P(smoke_NumSplitsCheck, SplitLayerTest,
::testing::Combine(
::testing::Values(1, 2, 3, 5, 6, 10, 30),
::testing::Values(0, 1, 2, 3),
@@ -14,5 +14,8 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*SplitLayerTest.*numSplits\=30.*)",
// CVS-44774
".*PreprocessTest.*",
// CVS-51758
".*PreprocessConversionTest.*oPRC=U8.*",
".*PreprocessConversionTest.*oLT=NHWC.*"
};
}
@@ -37,4 +37,59 @@ namespace {
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multiConfigs)),
PreprocessTest::getTestCaseName);
const std::vector<InferenceEngine::Precision> ioPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::U8
};
const std::vector<InferenceEngine::Layout> netLayouts = {
InferenceEngine::Layout::NCHW,
// InferenceEngine::Layout::NHWC
};
const std::vector<InferenceEngine::Layout> ioLayouts = {
InferenceEngine::Layout::NCHW,
InferenceEngine::Layout::NHWC
};
const std::vector<std::map<std::string, std::string>> heteroConfigs = {
{{ "TARGET_FALLBACK" , CommonTestUtils::DEVICE_CPU}}
};
INSTANTIATE_TEST_CASE_P(smoke_Hetero_BehaviorTests, PreprocessTest,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_HETERO),
::testing::ValuesIn(heteroConfigs)),
PreprocessTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(smoke_Hetero_BehaviorTests, PreprocessConversionTest,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(netLayouts),
::testing::ValuesIn(ioLayouts),
::testing::ValuesIn(ioLayouts),
::testing::Bool(),
::testing::Bool(),
::testing::Values(CommonTestUtils::DEVICE_HETERO),
::testing::ValuesIn(heteroConfigs)),
PreprocessConversionTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(smoke_Multi_BehaviorTests, PreprocessConversionTest,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(netLayouts),
::testing::ValuesIn(ioLayouts),
::testing::ValuesIn(ioLayouts),
::testing::Bool(),
::testing::Bool(),
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multiConfigs)),
PreprocessConversionTest::getTestCaseName);
} // namespace
@@ -37,6 +37,8 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*(PreprocessTest).*(SetMeanValuePreProcessSetBlob).*)",
R"(.*(PreprocessTest).*(SetMeanImagePreProcessSetBlob).*)",
R"(.*(PreprocessTest).*(ReverseInputChannelsPreProcessGetBlob).*)",
// TODO: Issue :51757
R"(.*(smoke_Hetero_BehaviorTests/PreprocessConversionTest).*)",
// TODO: Issue: 34348
R"(.*IEClassGetAvailableDevices.*)",
// TODO: Issue: 25533
@@ -36,4 +36,34 @@ namespace {
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multiConfigs)),
PreprocessTest::getTestCaseName);
const std::vector<InferenceEngine::Precision> ioPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::U8
};
const std::vector<InferenceEngine::Layout> netLayouts = {
InferenceEngine::Layout::NCHW,
// InferenceEngine::Layout::NHWC
};
const std::vector<InferenceEngine::Layout> ioLayouts = {
InferenceEngine::Layout::NCHW,
InferenceEngine::Layout::NHWC
};
INSTANTIATE_TEST_CASE_P(smoke_BehaviorTests, PreprocessConversionTest,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(netLayouts),
::testing::ValuesIn(ioLayouts),
::testing::ValuesIn(ioLayouts),
::testing::Bool(),
::testing::Bool(),
::testing::Values(CommonTestUtils::DEVICE_GPU),
::testing::ValuesIn(configs)),
PreprocessConversionTest::getTestCaseName);
} // namespace
@@ -24,6 +24,8 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*(PreprocessTest).*(SetMeanValuePreProcessSetBlob).*)",
R"(.*(PreprocessTest).*(SetMeanImagePreProcessSetBlob).*)",
R"(.*(PreprocessTest).*(ReverseInputChannelsPreProcessGetBlob).*)",
// TODO: Issue: 51764
".*PreprocessConversionTest.*",
// TODO: Issue: 41467 -- "unsupported element type f16 op Convert"
R"(.*(ConvertLayerTest).*targetPRC=FP16.*)",
// TODO: Issue: 41462
@@ -34,4 +34,33 @@ namespace {
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multiConfigs)),
PreprocessTest::getTestCaseName);
const std::vector<InferenceEngine::Precision> ioPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::U8
};
const std::vector<InferenceEngine::Layout> netLayouts = {
InferenceEngine::Layout::NCHW,
// InferenceEngine::Layout::NHWC
};
const std::vector<InferenceEngine::Layout> ioLayouts = {
InferenceEngine::Layout::NCHW,
InferenceEngine::Layout::NHWC
};
INSTANTIATE_TEST_CASE_P(smoke_BehaviorTests, PreprocessConversionTest,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(ioPrecisions),
::testing::ValuesIn(netLayouts),
::testing::ValuesIn(ioLayouts),
::testing::ValuesIn(ioLayouts),
::testing::Bool(),
::testing::Bool(),
::testing::Values(CommonTestUtils::DEVICE_MYRIAD),
::testing::ValuesIn(configs)),
PreprocessConversionTest::getTestCaseName);
} // namespace
@@ -37,5 +37,7 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*CTCGreedyDecoderSeqLen.*?\(1.1.1\).*)",
// TODO: Issue 51472
".*CachingSupportCase.*_batch2_.*",
// TODO: Issue 51804
".*PreprocessConversionTest.*oPRC=U8.*",
};
}
@@ -20,7 +20,7 @@ using PreprocessTest = BehaviorTestsUtils::BehaviorTestsBasic;
TEST_P(PreprocessTest, SetPreProcessToInputInfo) {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(function);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -41,7 +41,7 @@ TEST_P(PreprocessTest, SetPreProcessToInputInfo) {
TEST_P(PreprocessTest, SetPreProcessToInferRequest) {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(function);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -82,7 +82,7 @@ TEST_P(PreprocessTest, SetMeanImagePreProcessGetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -108,8 +108,8 @@ TEST_P(PreprocessTest, SetMeanImagePreProcessGetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -149,7 +149,7 @@ TEST_P(PreprocessTest, SetMeanImagePreProcessSetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -178,8 +178,8 @@ TEST_P(PreprocessTest, SetMeanImagePreProcessSetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -219,7 +219,7 @@ TEST_P(PreprocessTest, SetMeanValuePreProcessGetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -239,8 +239,8 @@ TEST_P(PreprocessTest, SetMeanValuePreProcessGetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -280,7 +280,7 @@ TEST_P(PreprocessTest, SetMeanValuePreProcessSetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -303,8 +303,8 @@ TEST_P(PreprocessTest, SetMeanValuePreProcessSetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -345,7 +345,7 @@ TEST_P(PreprocessTest, ReverseInputChannelsPreProcessGetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -358,8 +358,8 @@ TEST_P(PreprocessTest, ReverseInputChannelsPreProcessGetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -409,7 +409,7 @@ TEST_P(PreprocessTest, ReverseInputChannelsPreProcessSetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -425,8 +425,8 @@ TEST_P(PreprocessTest, ReverseInputChannelsPreProcessSetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -475,7 +475,7 @@ TEST_P(PreprocessTest, SetScalePreProcessGetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -495,8 +495,8 @@ TEST_P(PreprocessTest, SetScalePreProcessGetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -537,7 +537,7 @@ TEST_P(PreprocessTest, SetScalePreProcessSetBlob) {
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngrpah::Function
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
auto &preProcess = cnnNet.getInputsInfo().begin()->second->getPreProcess();
@@ -560,8 +560,8 @@ TEST_P(PreprocessTest, SetScalePreProcessSetBlob) {
// Fill input
{
auto locketMem = inBlob->buffer();
auto *inData = locketMem.as<float*>();
auto lockedMem = inBlob->buffer();
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[i] = i;
}
@@ -581,4 +581,174 @@ TEST_P(PreprocessTest, SetScalePreProcessSetBlob) {
}
}
typedef std::tuple<
InferenceEngine::Precision, // Network precision
InferenceEngine::Precision, // Set input precision
InferenceEngine::Precision, // Set output precision
InferenceEngine::Layout, // Network layout - always NCHW
InferenceEngine::Layout, // Set input layout
InferenceEngine::Layout, // Set output layout
bool, // SetBlob or GetBlob for input blob
bool, // SetBlob or GetBlob for output blob
std::string, // Device name
std::map<std::string, std::string> // Config
> PreprocessConversionParams;
class PreprocessConversionTest : public testing::WithParamInterface<PreprocessConversionParams>,
public CommonTestUtils::TestsCommon {
public:
static std::string getTestCaseName(testing::TestParamInfo<PreprocessConversionParams> obj) {
InferenceEngine::Precision netPrecision, iPrecision, oPrecision;
InferenceEngine::Layout netLayout, iLayout, oLayout;
bool setInputBlob, setOutputBlob;
std::string targetDevice;
std::map<std::string, std::string> configuration;
std::tie(netPrecision, iPrecision, oPrecision,
netLayout, iLayout, oLayout,
setInputBlob, setOutputBlob,
targetDevice, configuration) = obj.param;
std::ostringstream result;
result << "netPRC=" << netPrecision.name() << "_";
result << "iPRC=" << iPrecision.name() << "_";
result << "oPRC=" << oPrecision.name() << "_";
result << "netLT=" << netLayout << "_";
result << "iLT=" << iLayout << "_";
result << "oLT=" << oLayout << "_";
result << "setIBlob=" << setInputBlob << "_";
result << "setOBlob=" << setOutputBlob << "_";
result << "targetDevice=" << targetDevice;
if (!configuration.empty()) {
for (auto& configItem : configuration) {
result << "configItem=" << configItem.first << "_" << configItem.second << "_";
}
}
return result.str();
}
void SetUp() override {
std::tie(netPrecision, iPrecision, oPrecision,
netLayout, iLayout, oLayout,
setInputBlob, setOutputBlob,
targetDevice, configuration) = this->GetParam();
}
void TearDown() override {
if (!configuration.empty()) {
PluginCache::get().reset();
}
}
std::shared_ptr<InferenceEngine::Core> ie = PluginCache::get().ie();
InferenceEngine::Precision netPrecision, iPrecision, oPrecision;
InferenceEngine::Layout netLayout, iLayout, oLayout;
bool setInputBlob, setOutputBlob;
std::string targetDevice;
std::map<std::string, std::string> configuration;
};
TEST_P(PreprocessConversionTest, Infer) {
// Skip test according to plugin specific disabledTestPatterns() (if any)
SKIP_IF_CURRENT_TEST_IS_DISABLED()
std::shared_ptr<ngraph::Function> ngraph;
unsigned int shape_size = 9, channels = 3, batch = 1, offset = 0;
{
ngraph::PartialShape shape({batch, channels, shape_size, shape_size});
ngraph::element::Type type(ngraph::element::Type_t::f32);
auto param = std::make_shared<ngraph::op::Parameter>(type, shape);
param->set_friendly_name("param");
auto relu = std::make_shared<ngraph::op::Relu>(param);
relu->set_friendly_name("relu");
auto result = std::make_shared<ngraph::op::Result>(relu);
result->set_friendly_name("result");
ngraph::ParameterVector params = {param};
ngraph::ResultVector results = {result};
ngraph = std::make_shared<ngraph::Function>(results, params);
}
// Create CNNNetwork from ngraph::Function
InferenceEngine::CNNNetwork cnnNet(ngraph);
cnnNet.getInputsInfo().begin()->second->setPrecision(iPrecision);
cnnNet.getInputsInfo().begin()->second->setLayout(iLayout);
cnnNet.getOutputsInfo().begin()->second->setPrecision(oPrecision);
cnnNet.getOutputsInfo().begin()->second->setLayout(oLayout);
// Load CNNNetwork to target plugins
auto execNet = ie->LoadNetwork(cnnNet, targetDevice, configuration);
// Create InferRequest
auto req = execNet.CreateInferRequest();
// unsigned int stride = shape_size + offset;
// std::vector<float> blobData(batch * channels * stride * stride, 0);
// InferenceEngine::BlockingDesc blockDesc({ batch, shape_size, shape_size, channels },
// { 0, 2, 3, 1 },
// 0,
// { 0, 0, 0, 0 },
// { channels * stride * stride, channels * stride, channels, 1 });
// InferenceEngine::TensorDesc desc(
// InferenceEngine::Precision::FP32,
// { batch, channels, shape_size, shape_size }, blockDesc);
(void)offset;
InferenceEngine::Blob::Ptr inBlob = nullptr, outBlob = nullptr;
if (setInputBlob) {
inBlob = make_blob_with_precision(cnnNet.getInputsInfo().begin()->second->getTensorDesc());
inBlob->allocate();
req.SetBlob("param", inBlob);
} else {
inBlob = req.GetBlob("param");
}
if (setOutputBlob) {
outBlob = make_blob_with_precision(cnnNet.getOutputsInfo().begin()->second->getTensorDesc());
outBlob->allocate();
req.SetBlob(cnnNet.getOutputsInfo().begin()->first, outBlob);
} else {
outBlob = req.GetBlob(cnnNet.getOutputsInfo().begin()->first);
}
// Fill input
{
auto lockedMem = inBlob->buffer();
auto desc = inBlob->getTensorDesc();
if (iPrecision == InferenceEngine::Precision::FP32) {
auto *inData = lockedMem.as<float*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[desc.offset(i)] = i;
} else if (iPrecision == InferenceEngine::Precision::U8) {
auto *inData = lockedMem.as<std::uint8_t*>();
for (size_t i = 0; i < inBlob->size(); i++)
inData[desc.offset(i)] = i;
} else {
ASSERT_TRUE(false);
}
}
req.Infer();
// Check output
{
auto outMem = outBlob->cbuffer();
auto desc = outBlob->getTensorDesc();
if (oPrecision == InferenceEngine::Precision::FP32) {
const auto* outData = outMem.as<const float *>();
ASSERT_EQ(inBlob->size(), outBlob->size());
for (size_t i = 0; i < inBlob->size(); i++)
ASSERT_EQ(i, outData[desc.offset(i)]) << i;
} else if (oPrecision == InferenceEngine::Precision::U8) {
const auto* outData = outMem.as<const std::uint8_t *>();
ASSERT_EQ(inBlob->size(), outBlob->size());
for (size_t i = 0; i < inBlob->size(); i++)
ASSERT_EQ(i, outData[desc.offset(i)]) << i;
} else {
ASSERT_TRUE(false);
}
}
}
} // namespace BehaviorTestsDefinitions