-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[I420 color conversion] I420toRGB/I420toBGR reference implementation #8605
Merged
ilyachur
merged 10 commits into
openvinotoolkit:master
from
nosovmik:ov20/i420_ref_impl
Nov 18, 2021
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dce26cd
ngraph part
nosovmik bbab6b5
Template reference tests
nosovmik 9cabe18
Merge remote-tracking branch 'upstream/master' into ov20/i420_ref_impl
nosovmik 59ef8cd
Clang format fixes
nosovmik 6072cc9
Remove reference implementation for f16, bf16, f64 types
nosovmik 0670f74
Fix ninja build
nosovmik ca8f27d
Fix opset8_dump test
nosovmik 1be7cb8
Fix opset8_dump test
nosovmik e60b07a
Fix CentOS build
nosovmik a604791
Removed Myriad preprocessing tests (to be added by separate PR)
nosovmik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
171 changes: 171 additions & 0 deletions
171
docs/template_plugin/tests/functional/op_reference/convert_color_i420.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <openvino/core/function.hpp> | ||
#include <tuple> | ||
#include <openvino/op/i420_to_rgb.hpp> | ||
#include <openvino/op/i420_to_bgr.hpp> | ||
|
||
#include "base_reference_test.hpp" | ||
#include "functional_test_utils/skip_tests_config.hpp" | ||
|
||
using namespace ov; | ||
using namespace InferenceEngine; | ||
using namespace reference_tests; | ||
|
||
class ReferenceConvertColorI420LayerTest : public testing::Test, public CommonReferenceTest { | ||
public: | ||
void SetUp() override { | ||
SKIP_IF_CURRENT_TEST_IS_DISABLED() | ||
abs_threshold = 1.f; // allow R, G, B absolute deviation to 1 (of max 255) | ||
threshold = 1.f; // Ignore relative comparison (100%) | ||
} | ||
|
||
public: | ||
template <typename T> | ||
static std::shared_ptr<Function> CreateFunction(const Tensor& input) { | ||
const auto in = std::make_shared<op::v0::Parameter>(input.type, input.shape); | ||
std::shared_ptr<Node> conv; | ||
conv = std::make_shared<T>(in); | ||
auto res = std::make_shared<op::v0::Result>(conv); | ||
return std::make_shared<Function>(ResultVector{res}, ParameterVector {in}); | ||
} | ||
|
||
template <typename T> | ||
static std::shared_ptr<Function> CreateFunction3(const Tensor& input1, const Tensor& input2, const Tensor& input3) { | ||
const auto in1 = std::make_shared<op::v0::Parameter>(input1.type, input1.shape); | ||
const auto in2 = std::make_shared<op::v0::Parameter>(input2.type, input2.shape); | ||
const auto in3 = std::make_shared<op::v0::Parameter>(input3.type, input3.shape); | ||
std::shared_ptr<Node> conv; | ||
conv = std::make_shared<T>(in1, in2, in3); | ||
auto res = std::make_shared<op::v0::Result>(conv); | ||
return std::make_shared<Function>(ResultVector{res}, ParameterVector {in1, in2, in3}); | ||
} | ||
}; | ||
|
||
TEST_F(ReferenceConvertColorI420LayerTest, CompareWithHardcodedRefs_r_u8_single_rgb) { | ||
auto input = std::vector<uint8_t> {0x51, 0x51, 0x51, 0x51, | ||
0x51, 0x51, 0x51, 0x51, | ||
0x5a, 0x5a, 0xf0, 0xf0}; | ||
auto input_shape = Shape{1, 3, 4, 1}; | ||
auto exp_out = std::vector<uint8_t> {0xff, 0, 0, 0xff, 0, 0, 0xff, 0, 0, 0xff, 0, 0, | ||
0xff, 0, 0, 0xff, 0, 0, 0xff, 0, 0, 0xff, 0, 0}; | ||
auto out_shape = Shape{1, 2, 4, 3}; | ||
Tensor inp_tensor(input_shape, element::u8, input); | ||
inputData = {inp_tensor.data}; | ||
function = CreateFunction<op::v8::I420toRGB>(inp_tensor); | ||
Tensor exp_tensor_u8(out_shape, element::u8, exp_out); | ||
refOutData = {exp_tensor_u8.data}; | ||
Exec(); | ||
} | ||
|
||
TEST_F(ReferenceConvertColorI420LayerTest, CompareWithHardcodedRefs_color_u8_single_bgr) { | ||
auto input = std::vector<uint8_t> {0x51, 0xeb, 0x51, 0xeb, | ||
0x51, 0xeb, 0x51, 0xeb, | ||
0x6d, 0x6d, 0xb8, 0xb8}; | ||
auto input_shape = Shape{1, 6, 2, 1}; | ||
auto exp_out = std::vector<uint8_t> {37, 37, 164, 217, 216, 255, 37, 37, 164, 217, 216, 255, | ||
37, 37, 164, 217, 216, 255, 37, 37, 164, 217, 216, 255}; | ||
auto out_shape = Shape{1, 4, 2, 3}; | ||
|
||
Tensor inp_tensor(input_shape, element::u8, input); | ||
inputData = {inp_tensor.data}; | ||
|
||
Tensor exp_tensor_u8(out_shape, element::u8, exp_out); | ||
refOutData = {exp_tensor_u8.data}; | ||
|
||
function = CreateFunction<op::v8::I420toBGR>(inp_tensor); | ||
|
||
Exec(); | ||
} | ||
|
||
TEST_F(ReferenceConvertColorI420LayerTest, CompareWithHardcodedRefs_g_fp32_single_rgb) { | ||
auto input = std::vector<float> {145.f, 145.f, 145.f, 145.f, | ||
145.f, 145.f, 145.f, 145.f, | ||
54.f, 54.f, 34.f, 34.f}; | ||
auto input_shape = Shape{1, 3, 4, 1}; | ||
auto exp_out = std::vector<float> {0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, | ||
0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0}; | ||
auto out_shape = Shape{1, 2, 4, 3}; | ||
|
||
Tensor inp_tensor(input_shape, element::f32, input); | ||
inputData = {inp_tensor.data}; | ||
|
||
Tensor exp_tensor(out_shape, element::f32, exp_out); | ||
refOutData = {exp_tensor.data}; | ||
|
||
function = CreateFunction<op::v8::I420toRGB>(inp_tensor); | ||
|
||
Exec(); | ||
} | ||
|
||
TEST_F(ReferenceConvertColorI420LayerTest, CompareWithHardcodedRefs_batch_fp32_three_bgr) { | ||
auto input_y = std::vector<float> {81.f, 81.f, 81.f, 81.f, | ||
145.f, 145.f, 145.f, 145.f, | ||
41.f, 41.f, 41.f, 41.f}; | ||
auto input_shape_y = Shape{3, 2, 2, 1}; | ||
|
||
auto input_u = std::vector<float> {90., | ||
54., | ||
240.}; | ||
auto input_shape_u = Shape{3, 1, 1, 1}; | ||
|
||
auto input_v = std::vector<float> {240., | ||
34., | ||
110.}; | ||
auto input_shape_v = Shape{3, 1, 1, 1}; | ||
auto exp_out = std::vector<float> {0, 0, 255., 0, 0, 255., 0, 0, 255., 0, 0, 255., | ||
0, 255., 0, 0, 255., 0, 0, 255., 0, 0, 255., 0, | ||
255., 0, 0, 255., 0, 0, 255., 0, 0, 255., 0, 0}; | ||
auto out_shape = Shape{3, 2, 2, 3}; | ||
|
||
Tensor inp_tensor_y(input_shape_y, element::f32, input_y); | ||
Tensor inp_tensor_u(input_shape_u, element::f32, input_u); | ||
Tensor inp_tensor_v(input_shape_v, element::f32, input_v); | ||
inputData = {inp_tensor_y.data, inp_tensor_u.data, inp_tensor_v.data}; | ||
|
||
Tensor exp_tensor(out_shape, element::f32, exp_out); | ||
refOutData = {exp_tensor.data}; | ||
|
||
function = CreateFunction3<op::v8::I420toBGR>(inp_tensor_y, inp_tensor_u, inp_tensor_v); | ||
|
||
Exec(); | ||
} | ||
|
||
TEST_F(ReferenceConvertColorI420LayerTest, CompareWithHardcodedRefs_color4x4_f32_three_rgb) { | ||
auto input_y = std::vector<float> {81, 235, | ||
81, 235, | ||
81, 81, | ||
81, 81, | ||
145, 145, | ||
145, 145, | ||
41, 41, | ||
41, 41}; | ||
auto input_shape_y = Shape{1, 8, 2, 1}; | ||
|
||
auto input_u = std::vector<float> {109, 90, 54, 240}; | ||
auto input_shape_u = Shape{1, 4, 1, 1}; | ||
auto input_v = std::vector<float> {184, 240, 34, 110}; | ||
auto input_shape_v = Shape{1, 4, 1, 1}; | ||
|
||
auto exp_out = std::vector<float> {165, 37, 37, 255, 216, 217, 165, 37, 37, 255, 216, 217, | ||
255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, | ||
0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, | ||
0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255}; | ||
auto out_shape = Shape{1, 2, 2, 3}; | ||
|
||
Tensor inp_tensor_y(input_shape_y, element::f32, input_y); | ||
Tensor inp_tensor_u(input_shape_u, element::f32, input_u); | ||
Tensor inp_tensor_v(input_shape_v, element::f32, input_v); | ||
inputData = {inp_tensor_y.data, inp_tensor_u.data, inp_tensor_v.data}; | ||
|
||
Tensor exp_tensor(out_shape, element::f32, exp_out); | ||
refOutData = {exp_tensor.data}; | ||
|
||
function = CreateFunction3<op::v8::I420toRGB>(inp_tensor_y, inp_tensor_u, inp_tensor_v); | ||
|
||
Exec(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ngine/tests/functional/inference_engine/serialization/single_layer/convert_color_i420.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "shared_test_classes/single_layer/convert_color_i420.hpp" | ||
|
||
using namespace LayerTestsDefinitions; | ||
|
||
namespace { | ||
|
||
TEST_P(ConvertColorI420LayerTest, Serialize) { | ||
Serialize(); | ||
} | ||
|
||
const std::vector<ov::Shape> inShapes_nhwc = { | ||
{1, 10, 10, 1} | ||
}; | ||
|
||
const std::vector<ov::element::Type> inTypes = { | ||
ov::element::u8, ov::element::f32 | ||
}; | ||
|
||
const auto testCase_values = ::testing::Combine( | ||
::testing::ValuesIn(inShapes_nhwc), | ||
::testing::ValuesIn(inTypes), | ||
::testing::Bool(), | ||
::testing::Bool(), | ||
::testing::Values(CommonTestUtils::DEVICE_CPU) | ||
); | ||
|
||
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ConvertColorI420LayerTest, testCase_values, ConvertColorI420LayerTest::getTestCaseName); | ||
|
||
} // namespace |
59 changes: 59 additions & 0 deletions
59
...ts/functional/plugin/cpu/shared_tests_instances/single_layer_tests/convert_color_i420.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <vector> | ||
|
||
#include "single_layer_tests/convert_color_i420.hpp" | ||
#include "common_test_utils/test_constants.hpp" | ||
|
||
using namespace LayerTestsDefinitions; | ||
|
||
namespace { | ||
|
||
const std::vector<ov::Shape> inShapes_nhwc = { | ||
{1, 10, 10, 1} | ||
}; | ||
|
||
const std::vector<ov::element::Type> inTypes = { | ||
ov::element::u8, ov::element::f32 | ||
}; | ||
|
||
const auto testCase_values = ::testing::Combine( | ||
::testing::ValuesIn(inShapes_nhwc), | ||
::testing::ValuesIn(inTypes), | ||
::testing::Bool(), | ||
::testing::Bool(), | ||
::testing::Values(CommonTestUtils::DEVICE_CPU) | ||
); | ||
|
||
|
||
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420, ConvertColorI420LayerTest, testCase_values, ConvertColorI420LayerTest::getTestCaseName); | ||
|
||
const auto testCase_accuracy_values = ::testing::Combine( | ||
::testing::Values(ov::Shape{1, 16*6, 16, 1}), | ||
::testing::Values(ov::element::u8), | ||
::testing::Values(false), | ||
::testing::Values(true), | ||
::testing::Values(CommonTestUtils::DEVICE_CPU) | ||
); | ||
|
||
INSTANTIATE_TEST_SUITE_P(smoke_TestsConvertColorI420_acc, | ||
ConvertColorI420AccuracyTest, | ||
testCase_accuracy_values, | ||
ConvertColorI420LayerTest::getTestCaseName); | ||
|
||
const auto testCase_accuracy_values_nightly = ::testing::Combine( | ||
::testing::Values(ov::Shape{1, 256*256, 256, 1}), | ||
::testing::Values(ov::element::u8), | ||
::testing::Values(false), | ||
::testing::Values(true), | ||
::testing::Values(CommonTestUtils::DEVICE_CPU) | ||
); | ||
|
||
INSTANTIATE_TEST_SUITE_P(nightly_TestsConvertColorI420_acc, | ||
ConvertColorI420AccuracyTest, | ||
testCase_accuracy_values_nightly, | ||
ConvertColorI420LayerTest::getTestCaseName); | ||
|
||
} // namespace |
30 changes: 30 additions & 0 deletions
30
...ngine/tests/functional/plugin/myriad/shared_tests_instances/subgraph_tests/preprocess.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <vector> | ||
|
||
#include "shared_test_classes/subgraph/preprocess.hpp" | ||
|
||
using namespace SubgraphTestsDefinitions; | ||
|
||
namespace { | ||
|
||
using namespace ov::builder::preprocess; | ||
|
||
inline std::vector<preprocess_func> myriad_smoke_preprocess_functions() { | ||
return std::vector<preprocess_func>{ | ||
preprocess_func(convert_element_type_and_mean, "convert_element_type_and_mean", 0.01f), | ||
preprocess_func(tensor_element_type_and_mean, "tensor_element_type_and_mean", 0.01f), | ||
preprocess_func(mean_only, "mean_only", 0.01f), | ||
preprocess_func(scale_only, "scale_only", 0.01f), | ||
}; | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(smoke_PrePostProcess_Myriad, PrePostProcessTest, | ||
::testing::Combine( | ||
::testing::ValuesIn(myriad_smoke_preprocess_functions()), | ||
::testing::Values(CommonTestUtils::DEVICE_MYRIAD)), | ||
PrePostProcessTest::getTestCaseName); | ||
|
||
} // namespace |
19 changes: 19 additions & 0 deletions
19
...e-engine/tests/functional/plugin/shared/include/single_layer_tests/convert_color_i420.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (C) 2018-2021 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "shared_test_classes/single_layer/convert_color_i420.hpp" | ||
|
||
namespace LayerTestsDefinitions { | ||
|
||
TEST_P(ConvertColorI420LayerTest, CompareWithRefs) { | ||
Run(); | ||
} | ||
|
||
TEST_P(ConvertColorI420AccuracyTest, CompareWithRefs) { | ||
Run(); | ||
} | ||
|
||
} // namespace LayerTestsDefinitions |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you can use parametrized tests