Skip to content

Commit

Permalink
Merge branch 'master' into releases/2024.1
Browse files Browse the repository at this point in the history
  • Loading branch information
suryasidd committed Mar 31, 2024
2 parents f4f0bb3 + 4948d5a commit cad782d
Show file tree
Hide file tree
Showing 21 changed files with 324 additions and 41 deletions.
26 changes: 26 additions & 0 deletions src/bindings/c/include/openvino/c/ov_prepostprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ ov_preprocess_preprocess_steps_resize(ov_preprocess_preprocess_steps_t* preproce
OPENVINO_C_API(ov_status_e)
ov_preprocess_preprocess_steps_scale(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps, float value);

/**
* @brief Add scale preprocess operation. Divide each channel element of input by different specified value.
* @ingroup ov_prepostprocess_c_api
* @param preprocess_input_process_steps A pointer to ov_preprocess_preprocess_steps_t.
* @param values Scaling values array for each channels
* @param value_size Scaling value size
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_preprocess_preprocess_steps_scale_multi_channels(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps,
const float* values,
const int32_t value_size);

/**
* @brief Add mean preprocess operation. Subtract specified value from each element of input.
* @ingroup ov_prepostprocess_c_api
Expand All @@ -225,6 +238,19 @@ ov_preprocess_preprocess_steps_scale(ov_preprocess_preprocess_steps_t* preproces
OPENVINO_C_API(ov_status_e)
ov_preprocess_preprocess_steps_mean(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps, float value);

/**
* @brief Add mean preprocess operation. Subtract each channel element of input by different specified value.
* @ingroup ov_prepostprocess_c_api
* @param preprocess_input_process_steps A pointer to ov_preprocess_preprocess_steps_t.
* @param values Value array to subtract from each element.
* @param value_size Mean value size
* @return Status code of the operation: OK(0) for success.
*/
OPENVINO_C_API(ov_status_e)
ov_preprocess_preprocess_steps_mean_multi_channels(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps,
const float* values,
const int32_t value_size);

/**
* @brief Crop input tensor between begin and end coordinates.
* @ingroup ov_prepostprocess_c_api
Expand Down
32 changes: 32 additions & 0 deletions src/bindings/c/src/ov_prepostprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ ov_status_e ov_preprocess_preprocess_steps_scale(ov_preprocess_preprocess_steps_
return ov_status_e::OK;
}

OPENVINO_C_API(ov_status_e)
ov_preprocess_preprocess_steps_scale_multi_channels(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps,
const float* values,
const int32_t value_size) {
if (!preprocess_input_process_steps || !values || value_size <= 0) {
return ov_status_e::INVALID_C_PARAM;
}
try {
std::vector<float> scale_vec(values, values + value_size);
preprocess_input_process_steps->object->scale(scale_vec);
}
CATCH_OV_EXCEPTIONS

return ov_status_e::OK;
}

ov_status_e ov_preprocess_preprocess_steps_mean(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps,
float value) {
if (!preprocess_input_process_steps) {
Expand All @@ -180,6 +196,22 @@ ov_status_e ov_preprocess_preprocess_steps_mean(ov_preprocess_preprocess_steps_t
return ov_status_e::OK;
}

OPENVINO_C_API(ov_status_e)
ov_preprocess_preprocess_steps_mean_multi_channels(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps,
const float* values,
const int32_t value_size) {
if (!preprocess_input_process_steps || !values || value_size <= 0) {
return ov_status_e::INVALID_C_PARAM;
}
try {
std::vector<float> mean_vec(values, values + value_size);
preprocess_input_process_steps->object->mean(mean_vec);
}
CATCH_OV_EXCEPTIONS

return ov_status_e::OK;
}

ov_status_e ov_preprocess_preprocess_steps_crop(ov_preprocess_preprocess_steps_t* preprocess_input_process_steps,
int32_t* begin,
int32_t begin_size,
Expand Down
125 changes: 109 additions & 16 deletions src/bindings/c/tests/ov_preprocess_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ov_preprocess_test : public ::testing::Test {
void SetUp() override {
core = nullptr;
model = nullptr;
ppp_model = nullptr;
preprocess = nullptr;
input_info = nullptr;
input_tensor_info = nullptr;
Expand Down Expand Up @@ -37,13 +38,15 @@ class ov_preprocess_test : public ::testing::Test {
ov_preprocess_input_info_free(input_info);
ov_preprocess_prepostprocessor_free(preprocess);
ov_model_free(model);
ov_model_free(ppp_model);
ov_core_free(core);
TestDataHelpers::release_test_model();
}

public:
ov_core_t* core;
ov_model_t* model;
ov_model_t* ppp_model;
ov_preprocess_prepostprocessor_t* preprocess;
ov_preprocess_input_info_t* input_info;
ov_preprocess_input_tensor_info_t* input_tensor_info;
Expand Down Expand Up @@ -113,10 +116,19 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_resize) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);

ov_layout_t* layout = nullptr;
const char* layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));
ov_layout_free(layout);

OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);

OV_EXPECT_OK(ov_preprocess_preprocess_steps_resize(input_process, ov_preprocess_resize_algorithm_e::RESIZE_LINEAR));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_scale) {
Expand All @@ -130,6 +142,31 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_scale) {
EXPECT_NE(nullptr, input_process);

OV_EXPECT_OK(ov_preprocess_preprocess_steps_scale(input_process, 2.0f));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_scale_multi_channels) {
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_layout_t* layout = nullptr;
const char* layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));
ov_layout_free(layout);

OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);

float values[3] = {2.0f, 2.0f, 2.0f};
OV_EXPECT_OK(ov_preprocess_preprocess_steps_scale_multi_channels(input_process, values, 3));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_mean) {
Expand All @@ -143,6 +180,31 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_mean) {
EXPECT_NE(nullptr, input_process);

OV_EXPECT_OK(ov_preprocess_preprocess_steps_mean(input_process, 2.0f));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_mean_multi_channels) {
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_layout_t* layout = nullptr;
const char* layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));
ov_layout_free(layout);

OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);

float values[3] = {2.0f, 2.0f, 2.0f};
OV_EXPECT_OK(ov_preprocess_preprocess_steps_mean_multi_channels(input_process, values, 3));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_crop) {
Expand All @@ -152,12 +214,25 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_crop) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);

ov_layout_t* layout = nullptr;
const char* layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));
ov_layout_free(layout);

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_spatial_static_shape(input_tensor_info, 256, 272));

OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);

int32_t begin[] = {0, 0, 5, 10};
int32_t end[] = {1, 3, 15, 20};
int32_t begin[] = {0, 0, 10, 20};
int32_t end[] = {1, 3, 237, 247};
OV_EXPECT_OK(ov_preprocess_preprocess_steps_crop(input_process, begin, 4, end, 4));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_convert_layout) {
Expand All @@ -174,6 +249,8 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_convert_layout) {
const char* input_layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(input_layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_layout(input_process, layout));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);

ov_layout_free(layout);
}
Expand All @@ -185,10 +262,19 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_reverse_channels) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_get_input_info_by_index(preprocess, 0, &input_info));
EXPECT_NE(nullptr, input_info);

ov_layout_t* layout = nullptr;
const char* layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));
ov_layout_free(layout);

OV_EXPECT_OK(ov_preprocess_input_info_get_preprocess_steps(input_info, &input_process));
EXPECT_NE(nullptr, input_process);

OV_EXPECT_OK(ov_preprocess_preprocess_steps_reverse_channels(input_process));
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_input_tensor_info_set_element_type) {
Expand Down Expand Up @@ -287,6 +373,9 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_convert_element_type)

OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_element_type(input_tensor_info, ov_element_type_e::U8));
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_element_type(input_process, ov_element_type_e::F32));

OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_convert_color) {
Expand All @@ -307,7 +396,19 @@ TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_convert_color) {
2,
"y",
"uv"));
OV_EXPECT_OK(ov_preprocess_input_tensor_info_set_spatial_static_shape(input_tensor_info, 320, 320));
OV_EXPECT_OK(ov_preprocess_preprocess_steps_convert_color(input_process, ov_color_format_e::BGR));
OV_EXPECT_OK(ov_preprocess_preprocess_steps_resize(input_process, RESIZE_LINEAR));

ov_layout_t* layout = nullptr;
const char* layout_desc = "NCHW";
OV_EXPECT_OK(ov_layout_create(layout_desc, &layout));
OV_EXPECT_OK(ov_preprocess_input_info_get_model_info(input_info, &input_model));
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));
ov_layout_free(layout);

OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_preprocess_steps_convert_color_rgb_to_gray) {
Expand Down Expand Up @@ -408,11 +509,8 @@ TEST_F(ov_preprocess_test, ov_preprocess_prepostprocessor_build) {
OV_EXPECT_OK(ov_preprocess_prepostprocessor_create(model, &preprocess));
EXPECT_NE(nullptr, preprocess);

ov_model_t* new_model = nullptr;
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &new_model));
EXPECT_NE(nullptr, new_model);

ov_model_free(new_model);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_prepostprocessor_build_apply) {
Expand Down Expand Up @@ -457,12 +555,9 @@ TEST_F(ov_preprocess_test, ov_preprocess_prepostprocessor_build_apply) {
EXPECT_NE(nullptr, output_tensor_info);
OV_EXPECT_OK(ov_preprocess_output_set_element_type(output_tensor_info, ov_element_type_e::F32));

ov_model_t* new_model = nullptr;
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &new_model));
EXPECT_NE(nullptr, new_model);

OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);
ov_shape_free(&shape);
ov_model_free(new_model);
}

TEST_F(ov_preprocess_test, ov_preprocess_prepostprocessor_for_nv12_input) {
Expand Down Expand Up @@ -496,10 +591,8 @@ TEST_F(ov_preprocess_test, ov_preprocess_prepostprocessor_for_nv12_input) {
ov_layout_create("NCHW", &layout);
OV_EXPECT_OK(ov_preprocess_input_model_info_set_layout(input_model, layout));

ov_model_t* new_model = nullptr;
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &new_model));
EXPECT_NE(nullptr, new_model);
OV_EXPECT_OK(ov_preprocess_prepostprocessor_build(preprocess, &ppp_model));
EXPECT_NE(nullptr, ppp_model);

ov_layout_free(layout);
ov_model_free(new_model);
}
2 changes: 1 addition & 1 deletion src/frontends/paddle/docs/operation_mapping_flow.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OpenVINO Paddle Frontend Operator Enabling Flow

1. Declare `CreatorFunction` for the Paddle operator and register it to the map in `src/op_table.cpp`.
* The map is retrived from:
* The map is retrieved from:

https://github.com/openvinotoolkit/openvino/blob/7d5e0abcaa03703de9918ece2115e6ea652c39e0/src/frontends/paddle/src/op_table.cpp#L106

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OpValidationFailure : public ov::frontend::OpValidationFailure {
/// \param cond Condition to check
/// \param ... Additional error message info to be added to the error message via the `<<`
/// stream-insertion operator. Note that the expressions here will be evaluated lazily,
/// i.e., only if the `cond` evalutes to `false`.
/// i.e., only if the `cond` evaluates to `false`.
/// \throws ::ov::OpValidationFailure if `cond` is false.
#define PADDLE_OP_CHECK(node_context, ...) \
OPENVINO_ASSERT_HELPER(::ov::frontend::paddle::OpValidationFailure, (node_context), __VA_ARGS__)
Expand Down
2 changes: 1 addition & 1 deletion src/frontends/paddle/src/internal/op/conditional_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void op::internal::ConditionalBlock::validate_and_infer_types() {
const OutputVector op::internal::ConditionalBlock::get_inputs_from_parent() const {
OutputVector result;
const auto& inputs = this->input_values();
for (size_t i = 0; i < inputs.size() - 1; i++) { // execpt the one at last, which is "cond".
for (size_t i = 0; i < inputs.size() - 1; i++) { // except the one at last, which is "cond".
result.push_back(inputs[i]);
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/frontends/paddle/src/internal/pass/transform_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ using namespace ov;
using namespace ov::pass;
using namespace ov::frontend::paddle::op::default_opset;

// Transform Paddle "conditonal_block" to OpenVINO If op.
// The contional_block only has "then" branch, while If op requires both "then" and "else" branch the same time.
// Transform Paddle "conditional_block" to OpenVINO If op.
// The conditional_block only has "then" branch, while If op requires both "then" and "else" branch the same time.
// Thus a "pass-through" model is built on purpose for "else" branch with the same outputs as "then" branch.
ov::frontend::paddle::pass::TransformIf::TransformIf(std::vector<std::shared_ptr<Model>> funcs) {
const auto cond_label = pattern::wrap_type<ov::op::internal::ConditionalBlock>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from save_model import exportModel

'''
assign w/ ouput
assign w/ output
'''
@paddle.jit.to_static
def test_assign_output(array):
Expand All @@ -24,7 +24,7 @@ def test_assign_output(array):
exportModel('assign_output', test_assign_output, [array], target_dir=sys.argv[1])

'''
assign w/o ouput
assign w/o output
'''
@paddle.jit.to_static
def test_assign_none(data):
Expand Down
Loading

0 comments on commit cad782d

Please sign in to comment.