RGB->Gray C and Py API2.0 (#15050)
* Add RGB to GRAY to C API 2.0 * Add RGB to GRAY to Py API 2.0 * ClangFormat + PyFlake8
This commit is contained in:
parent
74d571de1e
commit
d5f3bfa43e
@ -207,6 +207,8 @@ enum colorformat_e {
|
|||||||
|
|
||||||
BGR, ///< BGR color format, default in OpenVINO
|
BGR, ///< BGR color format, default in OpenVINO
|
||||||
|
|
||||||
|
GRAY, ///< GRAY color format
|
||||||
|
|
||||||
RGBX, ///< RGBX color format with X ignored during inference
|
RGBX, ///< RGBX color format with X ignored during inference
|
||||||
|
|
||||||
BGRX, ///< BGRX color format with X ignored during inference
|
BGRX, ///< BGRX color format with X ignored during inference
|
||||||
|
@ -77,6 +77,7 @@ typedef enum {
|
|||||||
I420_THREE_PLANES, //!< Image in I420 format represented as separate tensors for Y, U and V planes.
|
I420_THREE_PLANES, //!< Image in I420 format represented as separate tensors for Y, U and V planes.
|
||||||
RGB, //!< Image in RGB interleaved format (3 channels)
|
RGB, //!< Image in RGB interleaved format (3 channels)
|
||||||
BGR, //!< Image in BGR interleaved format (3 channels)
|
BGR, //!< Image in BGR interleaved format (3 channels)
|
||||||
|
GRAY, //!< Image in GRAY format (1 channel)
|
||||||
RGBX, //!< Image in RGBX interleaved format (4 channels)
|
RGBX, //!< Image in RGBX interleaved format (4 channels)
|
||||||
BGRX //!< Image in BGRX interleaved format (4 channels)
|
BGRX //!< Image in BGRX interleaved format (4 channels)
|
||||||
} ov_color_format_e;
|
} ov_color_format_e;
|
||||||
|
@ -18,6 +18,7 @@ const std::map<ov_color_format_e, ov::preprocess::ColorFormat> color_format_map
|
|||||||
{ov_color_format_e::I420_THREE_PLANES, ov::preprocess::ColorFormat::I420_THREE_PLANES},
|
{ov_color_format_e::I420_THREE_PLANES, ov::preprocess::ColorFormat::I420_THREE_PLANES},
|
||||||
{ov_color_format_e::RGB, ov::preprocess::ColorFormat::RGB},
|
{ov_color_format_e::RGB, ov::preprocess::ColorFormat::RGB},
|
||||||
{ov_color_format_e::BGR, ov::preprocess::ColorFormat::BGR},
|
{ov_color_format_e::BGR, ov::preprocess::ColorFormat::BGR},
|
||||||
|
{ov_color_format_e::GRAY, ov::preprocess::ColorFormat::GRAY},
|
||||||
{ov_color_format_e::RGBX, ov::preprocess::ColorFormat::RGBX},
|
{ov_color_format_e::RGBX, ov::preprocess::ColorFormat::RGBX},
|
||||||
{ov_color_format_e::BGRX, ov::preprocess::ColorFormat::BGRX}};
|
{ov_color_format_e::BGRX, ov::preprocess::ColorFormat::BGRX}};
|
||||||
|
|
||||||
|
@ -301,6 +301,23 @@ TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_convert_color) {
|
|||||||
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_color(input_process, ov_color_format_e::BGR));
|
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_color(input_process, ov_color_format_e::BGR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ov_preprocess, ov_preprocess_preprocess_steps_convert_color_rgb_to_gray) {
|
||||||
|
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
|
||||||
|
EXPECT_NE(nullptr, preprocess);
|
||||||
|
|
||||||
|
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
|
||||||
|
EXPECT_NE(nullptr, input_info);
|
||||||
|
|
||||||
|
OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
|
||||||
|
EXPECT_NE(nullptr, input_process);
|
||||||
|
|
||||||
|
OV_EXPECT_OK(ov_preprocess_input_info_get_tensor_info(input_info, &input_tensor_info));
|
||||||
|
EXPECT_NE(nullptr, input_tensor_info);
|
||||||
|
|
||||||
|
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_color_format(input_tensor_info, ov_color_format_e::RGB));
|
||||||
|
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_color(input_process, ov_color_format_e::GRAY));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_output_info) {
|
TEST_F(ov_preprocess, ov_preprocess_prepostprocessor_get_output_info) {
|
||||||
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
|
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
|
||||||
EXPECT_NE(nullptr, preprocess);
|
EXPECT_NE(nullptr, preprocess);
|
||||||
|
@ -453,6 +453,7 @@ static void regenum_graph_ColorFormat(py::module m) {
|
|||||||
.value("I420_THREE_PLANES", ov::preprocess::ColorFormat::I420_THREE_PLANES)
|
.value("I420_THREE_PLANES", ov::preprocess::ColorFormat::I420_THREE_PLANES)
|
||||||
.value("RGB", ov::preprocess::ColorFormat::RGB)
|
.value("RGB", ov::preprocess::ColorFormat::RGB)
|
||||||
.value("BGR", ov::preprocess::ColorFormat::BGR)
|
.value("BGR", ov::preprocess::ColorFormat::BGR)
|
||||||
|
.value("GRAY", ov::preprocess::ColorFormat::GRAY)
|
||||||
.value("RGBX", ov::preprocess::ColorFormat::RGBX)
|
.value("RGBX", ov::preprocess::ColorFormat::RGBX)
|
||||||
.value("BGRX", ov::preprocess::ColorFormat::BGRX)
|
.value("BGRX", ov::preprocess::ColorFormat::BGRX)
|
||||||
.export_values();
|
.export_values();
|
||||||
|
@ -401,6 +401,28 @@ def test_graph_preprocess_steps(algorithm, color_format1, color_format2, is_fail
|
|||||||
assert op in model_operators
|
assert op in model_operators
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("color_format1", "color_format2", "tensor_in_shape", "model_in_shape"),
|
||||||
|
[(ColorFormat.RGB, ColorFormat.GRAY, [1, 3, 3, 3], [1, 3, 3, 1]),
|
||||||
|
(ColorFormat.BGR, ColorFormat.GRAY, [1, 3, 3, 3], [1, 3, 3, 1]),
|
||||||
|
])
|
||||||
|
def test_graph_preprocess_convert_color(color_format1, color_format2, tensor_in_shape, model_in_shape):
|
||||||
|
parameter_a = ops.parameter(model_in_shape, dtype=np.float32, name="A")
|
||||||
|
model = parameter_a
|
||||||
|
function = Model(model, [parameter_a], "TestFunction")
|
||||||
|
|
||||||
|
custom_processor = PrePostProcessor(function)
|
||||||
|
inp = custom_processor.input()
|
||||||
|
inp.tensor().set_color_format(color_format1)
|
||||||
|
inp.preprocess().convert_color(color_format2)
|
||||||
|
function = custom_processor.build()
|
||||||
|
|
||||||
|
assert function.get_output_size() == 1
|
||||||
|
assert list(function.inputs[0].shape) == tensor_in_shape
|
||||||
|
assert list(function.get_output_shape(0)) == model_in_shape
|
||||||
|
assert function.get_output_element_type(0) == Type.f32
|
||||||
|
|
||||||
|
|
||||||
def test_graph_preprocess_postprocess_layout():
|
def test_graph_preprocess_postprocess_layout():
|
||||||
shape = [1, 1, 3, 3]
|
shape = [1, 1, 3, 3]
|
||||||
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
|
parameter_a = ops.parameter(shape, dtype=np.float32, name="A")
|
||||||
|
Loading…
Reference in New Issue
Block a user