Skip to content

Commit 62cce40

Browse files
committedFeb 13, 2025
Change clamp function to accept double parameters for improved precision
1 parent 1e11650 commit 62cce40

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed
 

‎src/core/include/openvino/core/preprocess/preprocess_steps.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OPENVINO_API PreProcessSteps final {
3636
/// \brief Default destructor
3737
~PreProcessSteps();
3838

39-
PreProcessSteps& clamp(float min_value, float max_value);
39+
PreProcessSteps& clamp(double min_value, double max_value);
4040

4141
/// \brief Add convert element type preprocess operation
4242
///

‎src/core/src/preprocess/pre_post_process.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
#include "function_guard.hpp"
99
#include "layout_utils.hpp"
1010
#include "openvino/core/model.hpp"
11+
#include "openvino/opsets/opset1.hpp"
1112
#include "preprocess_impls.hpp"
12-
#include "openvino/opsets/opset1.hpp"
13-
#include "preprocess_steps.hpp"
1413

1514
namespace ov {
1615
namespace preprocess {
@@ -269,7 +268,7 @@ InputTensorInfo& InputTensorInfo::set_from(const ov::Tensor& runtime_tensor) {
269268
PreProcessSteps::PreProcessSteps() : m_impl(std::unique_ptr<PreProcessStepsImpl>(new PreProcessStepsImpl())) {}
270269
PreProcessSteps::~PreProcessSteps() = default;
271270

272-
PreProcessSteps& PreProcessSteps::clamp(float min_value, float max_value) {
271+
PreProcessSteps& PreProcessSteps::clamp(double min_value, double max_value) {
273272
m_impl->add_clamp(min_value, max_value);
274273
return *this;
275274
}

‎src/core/src/preprocess/preprocess_steps_impl.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "openvino/opsets/opset8.hpp"
1414
#include "openvino/util/common_util.hpp"
1515
#include "transformations/rt_info/preprocessing_attribute.hpp"
16-
#include "openvino/opsets/opset1.hpp"
1716

1817
namespace ov {
1918
namespace preprocess {
@@ -100,9 +99,9 @@ void PreStepsList::add_scale_impl(const std::vector<float>& values) {
10099
"scale " + vector_to_string(values));
101100
}
102101

103-
void PreStepsList::add_clamp(float min_value, float max_value) {
102+
void PreStepsList::add_clamp(double min_value, double max_value) {
104103
std::string name = "clamp(min " + std::to_string(min_value) + ", max " + std::to_string(max_value) + ")";
105-
104+
106105
m_actions.emplace_back(
107106
[min_value, max_value](const std::vector<Output<Node>>& nodes,
108107
const std::shared_ptr<Model>& function,
@@ -111,10 +110,11 @@ void PreStepsList::add_clamp(float min_value, float max_value) {
111110
"Can't apply clamp to multi-plane input. Suggesting to convert current image to "
112111
"RGB/BGR color format using 'PreProcessSteps::convert_color'");
113112

114-
const auto& node = nodes[0];
113+
const auto& node = nodes.front();
115114
auto element_type = node.get_element_type();
116115
OPENVINO_ASSERT(element_type.is_real(),
117-
"Clamp preprocessing can be applied to 'float' inputs. Consider using 'convert_element_type' before clamping. Current type is: ",
116+
"Clamp preprocessing can be applied to 'double' inputs. Consider using "
117+
"'convert_element_type' before clamping. Current type is: ",
118118
element_type);
119119

120120
auto clamp_op = std::make_shared<ov::op::v0::Clamp>(node, min_value, max_value);
@@ -123,7 +123,6 @@ void PreStepsList::add_clamp(float min_value, float max_value) {
123123
name);
124124
}
125125

126-
127126
void PreStepsList::add_mean_impl(const std::vector<float>& values) {
128127
m_actions.emplace_back(
129128
[values](const std::vector<Output<Node>>& nodes,

‎src/core/src/preprocess/preprocess_steps_impl.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct InternalPreprocessAction {
157157
class PreStepsList {
158158
public:
159159
void add_scale_impl(const std::vector<float>& values);
160-
void add_clamp(float min_value, float max_value);
160+
void add_clamp(double min_value, double max_value);
161161
void add_mean_impl(const std::vector<float>& values);
162162
void add_pad_impl(const std::vector<int>& pads_begin,
163163
const std::vector<int>& pads_end,

0 commit comments

Comments
 (0)
Please sign in to comment.