Skip to content

Commit cf95887

Browse files
committed
Add clamp functionality to PostProcessSteps for value range control
1 parent c101c0e commit cf95887

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/core/include/openvino/core/preprocess/postprocess_steps.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class OPENVINO_API PostProcessSteps final {
3333
/// \brief Default destructor
3434
~PostProcessSteps();
3535

36+
PostProcessSteps& clamp(double min_value, double max_value);
37+
3638
/// \brief Add convert element type post-process operation
3739
///
3840
/// \param type Desired type of output. If not specified, type will be obtained from 'tensor' output information

src/core/src/preprocess/pre_post_process.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ OutputModelInfo& OutputModelInfo::set_color_format(const ov::preprocess::ColorFo
402402
PostProcessSteps::PostProcessSteps() : m_impl(std::unique_ptr<PostProcessStepsImpl>(new PostProcessStepsImpl())) {}
403403
PostProcessSteps::~PostProcessSteps() = default;
404404

405+
PostProcessSteps& PostProcessSteps::clamp(double min_value, double max_value) {
406+
m_impl->add_clamp(min_value, max_value);
407+
return *this;
408+
}
409+
405410
PostProcessSteps& PostProcessSteps::convert_element_type(const element::Type& type) {
406411
m_impl->add_convert_impl(type);
407412
return *this;

src/core/src/preprocess/preprocess_steps_impl.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,23 @@ std::tuple<std::vector<Output<Node>>, bool> PreStepsList::cut_last_channel(const
712712
}
713713

714714
//------------- Post processing ------
715+
void PostStepsList::add_clamp(double min_value, double max_value) {
716+
std::string name = "clamp(min " + std::to_string(min_value) + ", max " + std::to_string(max_value) + ")";
717+
718+
m_actions.emplace_back(
719+
[min_value, max_value](const Output<Node>& node, PostprocessingContext& ctxt) {
720+
auto element_type = node.get_element_type();
721+
OPENVINO_ASSERT(element_type.is_real(),
722+
"Clamp postprocessing can be applied to 'double' inputs. Consider using "
723+
"'convert_element_type' before clamping. Current type is: ",
724+
element_type);
725+
726+
auto clamp_op = std::make_shared<ov::op::v0::Clamp>(node, min_value, max_value);
727+
return std::make_tuple(Output<Node>{clamp_op}, true);
728+
},
729+
name);
730+
}
731+
715732
void PostStepsList::add_convert_impl(const element::Type& type) {
716733
m_actions.emplace_back(
717734
[type](const Output<Node>& node, PostprocessingContext& ctxt) {

src/core/src/preprocess/preprocess_steps_impl.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ struct InternalPostprocessAction {
221221
/// \brief PostProcessStepsImpl - internal data structure
222222
class PostStepsList {
223223
public:
224+
void add_clamp(double min_value, double max_value);
224225
void add_convert_impl(const element::Type& type);
225226
void add_convert_layout_impl(const Layout& layout);
226227
void add_convert_layout_impl(const std::vector<uint64_t>& dims);

0 commit comments

Comments
 (0)