Class ov::preprocess::PreProcessSteps¶
-
class PreProcessSteps¶
Preprocessing steps. Each step typically intends adding of some operation to input parameter User application can specify sequence of preprocessing steps in a builder-like manner.
auto proc = PrePostProcessor(function); proc.input().preprocess() .mean(0.2f) // Subtract 0.2 from each element .scale(2.3f)); // then divide each element to 2.3
Public Types
-
using CustomPreprocessOp = std::function<Output<Node>(const Output<Node> &node)>¶
Signature for custom preprocessing operation. Custom preprocessing operation takes one input node and produces one output node. For more advanced cases, client’s code can use transformation passes over ov::Model directly.
- Param node
Input node for custom preprocessing operation (output of previous preprocessing operation)
- Return
New node after applying custom preprocessing operation
Public Functions
-
~PreProcessSteps()¶
Default destructor.
-
PreProcessSteps &convert_element_type(const ov::element::Type &type = {})¶
Add convert element type preprocess operation.
- Parameters
type – Desired type of input.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner
-
PreProcessSteps &convert_color(const ov::preprocess::ColorFormat &dst_format)¶
Converts color format for user’s input tensor. Requires source color format to be specified by InputTensorInfo::set_color_format.
- Parameters
dst_format – Destination color format of input image
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner
-
PreProcessSteps &scale(float value)¶
Add scale preprocess operation Divide each element of input by specified value.
- Parameters
value – Scaling value.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner
-
PreProcessSteps &scale(const std::vector<float> &values)¶
Add scale preprocess operation by specified array of scale values for each channel.
- Parameters
values – Scaling values. Layout runtime info with channels dimension must be specified for input tensor
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner
-
PreProcessSteps &mean(float value)¶
Add mean preprocess operation Subtract specified value from each element of input.
- Parameters
value – Value to subtract from each element.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner
-
PreProcessSteps &mean(const std::vector<float> &values)¶
Add mean preprocess operation by specified array of mean values for each channel.
- Parameters
values – Mean values. Layout runtime info with channels dimension must be specified for input tensor
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner
-
PreProcessSteps &custom(const CustomPreprocessOp &preprocess_cb)¶
Add custom preprocess operation Client application can specify callback function for custom action.
- Parameters
preprocess_cb – Client’s custom preprocess operation.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner
-
PreProcessSteps &resize(ResizeAlgorithm alg, size_t dst_height, size_t dst_width)¶
Add resize operation to known dimensions - Lvalue version.
- Parameters
alg – Resize algorithm.
dst_height – Desired height of resized image.
dst_width – Desired width of resized image.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner.
-
PreProcessSteps &resize(ResizeAlgorithm alg)¶
Add resize operation to model’s dimensions.
- Parameters
alg – Resize algorithm.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner.
-
PreProcessSteps &crop(const std::vector<int> &begin, const std::vector<int> &end)¶
Crop input tensor between begin and end coordinates. Under the hood, inserts
opset8::Slice
operation to execution graph. It is recommended to use to together withov::preprocess::InputTensorInfo::set_shape
to set original input shape before cropping.- Parameters
begin – Begin indexes for input tensor cropping. Negative values represent counting elements from the end of input tensor
end – End indexes for input tensor cropping. End indexes are exclusive, which means values including end edge are not included in the output slice. Negative values represent counting elements from the end of input tensor
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner.
-
PreProcessSteps &convert_layout(const Layout &dst_layout = {})¶
Add ‘convert layout’ operation to specified layout.
Adds appropriate ‘transpose’ operation between user layout and target layout. Current implementation requires source and destination layout to have same number of dimensions
Example: when user data has ‘NHWC’ layout (example is RGB image, [1, 224, 224, 3]) but model expects planar input image (‘NCHW’, [1, 3, 224, 224]). Preprocessing may look like this:
auto proc = PrePostProcessor(model); proc.input().tensor().set_layout("NHWC"); // User data is NHWC proc.input().preprocess().convert_layout("NCHW")) // model expects input as NCHW
- Parameters
dst_layout – New layout after conversion. If not specified - destination layout is obtained from appropriate model input properties.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner.
-
PreProcessSteps &convert_layout(const std::vector<uint64_t> &dims)¶
Add convert layout operation by direct specification of transposed dimensions.
Example: when user data has input RGB image {1x480x640x3} but model expects planar input image (‘NCHW’, [1, 3, 480, 640]). Preprocessing may look like this:
auto proc = PrePostProcessor(function); proc.input().preprocess().convert_layout({0, 3, 1, 2});
- Parameters
dims – Dimensions array specifying places for new axis. If not empty, array size (N) must match to input shape rank. Array values shall contain all values from 0 to N-1. If empty, no actual conversion will be added.
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner.
-
PreProcessSteps &reverse_channels()¶
Reverse channels operation.
Adds appropriate operation which reverses channels layout. Operation requires layout having ‘C’ dimension Operation convert_color (RGB<->BGR) does reversing of channels also, but only for NHWC layout
Example: when user data has ‘NCHW’ layout (example is [1, 3, 224, 224] RGB order) but model expects BGR planes order. Preprocessing may look like this:
auto proc = PrePostProcessor(function); proc.input().tensor().set_layout("NCHW"); // User data is NCHW proc.input().preprocess().reverse_channels();
- Returns
Reference to ‘this’ to allow chaining with other calls in a builder-like manner.
-
using CustomPreprocessOp = std::function<Output<Node>(const Output<Node> &node)>¶