* Extensibility guide with FE extensions and remove OV_FRAMEWORK_MAP from docs * Rework of Extensibility Intro, adopted examples to missing OPENVINO_FRAMEWORK_MAP * Removed OPENVINO_FRAMEWORK_MAP reference * Frontend extension detailed documentation * Fixed distributed snippets * Fixed snippet inclusion in FE extension document and chapter headers * Fixed wrong name in a snippet reference * Fixed test for template extension due to changed number of loaded extensions * Update docs/Extensibility_UG/frontend_extensions.md Co-authored-by: Ivan Tikhonov <ivan.tikhonov@intel.com> * Minor fixes in extension snippets * Small grammar fix Co-authored-by: Ivan Tikhonov <ivan.tikhonov@intel.com> Co-authored-by: Ivan Tikhonov <ivan.tikhonov@intel.com> * DOCS: transition banner (#10973) * transition banner * minor fix * update transition banner * updates * update custom.js * updates * updates * Documentation fixes (#11044) * Benchmark app usage * Fixed link to the devices * More fixes * Update docs/OV_Runtime_UG/multi_device.md Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * Removed several hardcoded links Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * Updated documentation for compile_tool (#11049) * Added deployment guide (#11060) * Added deployment guide * Added local distribution * Updates * Fixed more indentations * Removed obsolete code snippets (#11061) * Removed obsolete code snippets * NCC style * Fixed NCC for BA * Add a troubleshooting issue for PRC installation (#11074) * updates * adding gna to linux * add missing reference * update * Update docs/install_guides/installing-model-dev-tools.md Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * Update docs/install_guides/installing-model-dev-tools.md Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * Update docs/install_guides/installing-model-dev-tools.md Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * Update docs/install_guides/installing-model-dev-tools.md Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * Update docs/install_guides/installing-model-dev-tools.md Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * update * minor updates * add gna item to yum and apt * add gna to get started page * update reference formatting * merge commit * add a troubleshooting issue * update * update * fix CVS-71846 Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> * DOCS: fixed hardcoded links (#11100) * Fixes * Use links * applying reviewers comments to the Opt Guide (#11093) * applying reviewrs comments * fixed refs, more structuring (bold, bullets, etc) * refactoring tput/latency sections * next iteration (mostly latency), also brushed the auto-batching and other sections * updates sync/async images * common opts brushed * WIP tput redesigned * minor brushing of common and auto-batching * Tput fully refactored * fixed doc name in the link * moved int8 perf counters to the right section * fixed links * fixed broken quotes * fixed more links * add ref to the internals to the TOC * Added a note on the batch size Co-authored-by: Andrey Zaytsev <andrey.zaytsev@intel.com> * [80085] New images for docs (#11114) * change doc structure * fix manager tools * fix manager tools 3 step * fix manager tools 3 step * new img * new img for OV Runtime * fix steps * steps * fix intendents * change list * fix space * fix space * code snippets fix * change display * Benchmarks 2022 1 (#11130) * Minor fixes * Updates for 2022.1 * Edits according to the review * Edits according to review comments * Edits according to review comments * Edits according to review comments * Fixed table * Edits according to review comments * Removed config for Intel® Core™ i7-11850HE * Removed forward-tacotron-duration-prediction-241 graph * Added resnet-18-pytorch * Add info about Docker images in Deployment guide (#11136) * Renamed user guides (#11137) * fix screenshot (#11140) * More conservative recommendations on dynamic shapes usage in docs (#11161) * More conservative recommendations about using dynamic shapes * Duplicated statement from C++ part to Python part of reshape doc (no semantical changes) * Update ShapeInference.md (#11168) * Benchmarks 2022 1 updates (#11180) * Updated graphs * Quick fix for TODO in Dynamic Shapes article * Anchor link fixes * Fixed DM config (#11199) * DOCS: doxy sphinxtabs (#11027) * initial implementation of doxy sphinxtabs * fixes * fixes * fixes * fixes * fixes * WA for ignored visibility attribute * Fixes Co-authored-by: Sergey Lyalin <sergey.lyalin@intel.com> Co-authored-by: Ivan Tikhonov <ivan.tikhonov@intel.com> Co-authored-by: Nikolay Tyukaev <nikolay.tyukaev@intel.com> Co-authored-by: Sergey Lyubimtsev <sergey.lyubimtsev@intel.com> Co-authored-by: Yuan Xu <yuan1.xu@intel.com> Co-authored-by: Maxim Shevtsov <maxim.y.shevtsov@intel.com> Co-authored-by: Andrey Zaytsev <andrey.zaytsev@intel.com> Co-authored-by: Tatiana Savina <tatiana.savina@intel.com> Co-authored-by: Ilya Naumov <ilya.naumov@intel.com> Co-authored-by: Evgenya Stepyreva <evgenya.stepyreva@intel.com>
6.1 KiB
Optimize Preprocessing
@sphinxdirective
.. toctree:: :maxdepth: 1 :hidden:
openvino_docs_OV_Runtime_UG_Preprocessing_Details openvino_docs_OV_Runtime_UG_Layout_Overview openvino_docs_OV_Runtime_UG_Preprocess_Usecase_save
@endsphinxdirective
Introduction
When your input data don't perfectly fit to Neural Network model input tensor - this means that additional operations/steps are needed to transform your data to format expected by model. These operations are known as "preprocessing".
Example
Consider the following standard example: deep learning model expects input with shape {1, 3, 224, 224}, FP32 precision, RGB color channels order, and requires data normalization (subtract mean and divide by scale factor). But you have just a 640x480 BGR image (data is {480, 640, 3}). This means that we need some operations which will:
- Convert U8 buffer to FP32
- Transform to
planarformat: from{1, 480, 640, 3}to{1, 3, 480, 640} - Resize image from 640x480 to 224x224
- Make
BGR->RGBconversion as model expectsRGB - For each pixel, subtract mean values and divide by scale factor
Even though all these steps can be relatively easy implemented manually in application's code before actual inference, it is possible to do it with Preprocessing API. Reasons to use this API are:
- Preprocessing API is easy to use
- Preprocessing steps will be integrated into execution graph and will be performed on selected device (CPU/GPU/VPU/etc.) rather than always being executed on CPU. This will improve selected device utilization which is always good.
Preprocessing API
Intuitively, Preprocessing API consists of the following parts:
-
**Tensor:** Declare user's data format, like shape, [layout](./layout_overview.md), precision, color format of actual user's data -
**Steps:** Describe sequence of preprocessing steps which need to be applied to user's data -
**Model:** Specify Model's data format. Usually, precision and shape are already known for model, only additional information, like [layout](./layout_overview.md) can be specified
Note: All model's graph modification shall be performed after model is read from disk and before it is being loaded on actual device.
PrePostProcessor object
ov::preprocess::PrePostProcessor class allows specifying preprocessing and postprocessing steps for model read from disk.
@sphinxtabset
@sphinxtab{C++}
@snippet docs/snippets/ov_preprocessing.cpp ov:preprocess:create
@endsphinxtab
@sphinxtab{Python}
@snippet docs/snippets/ov_preprocessing.py ov:preprocess:create
@endsphinxtab
@endsphinxtabset
Declare user's data format
To address particular input of model/preprocessor, use ov::preprocess::PrePostProcessor::input(input_name) method
@sphinxtabset
@sphinxtab{C++}
@snippet docs/snippets/ov_preprocessing.cpp ov:preprocess:tensor
@endsphinxtab
@sphinxtab{Python}
@snippet docs/snippets/ov_preprocessing.py ov:preprocess:tensor
@endsphinxtab
@endsphinxtabset
Here we've specified all information about user's input:
- Precision is U8 (unsigned 8-bit integer)
- Data represents tensor with {1,480,640,3} shape
- Layout is "NHWC". It means that 'height=480, width=640, channels=3'
- Color format is
BGR
Declare model's layout
Model's input already has information about precision and shape. Preprocessing API is not intended to modify this. The only thing that may be specified is input's data layout
@sphinxtabset
@sphinxtab{C++}
@snippet docs/snippets/ov_preprocessing.cpp ov:preprocess:model
@endsphinxtab
@sphinxtab{Python}
@snippet docs/snippets/ov_preprocessing.py ov:preprocess:model
@endsphinxtab
@endsphinxtabset
Now, if model's input has {1,3,224,224} shape, preprocessing will be able to identify that model's height=224, width=224, channels=3. Height/width information is necessary for 'resize', and channels is needed for mean/scale normalization
Preprocessing steps
Now we can define sequence of preprocessing steps:
@sphinxtabset
@sphinxtab{C++}
@snippet docs/snippets/ov_preprocessing.cpp ov:preprocess:steps
@endsphinxtab
@sphinxtab{Python}
@snippet docs/snippets/ov_preprocessing.py ov:preprocess:steps
@endsphinxtab
@endsphinxtabset
Here:
- Convert U8 to FP32 precision
- Convert current color format (BGR) to RGB
- Resize to model's height/width. Note that if model accepts dynamic size, e.g. {?, 3, ?, ?},
resizewill not know how to resize the picture, so in this case you should specify target height/width on this step. See alsoov::preprocess::PreProcessSteps::resize() - Subtract mean from each channel. On this step, color format is RGB already, so
100.5will be subtracted from each Red component, and101.5will be subtracted fromBlueone. - Divide each pixel data to appropriate scale value. In this example each
Redcomponent will be divided by 50,Greenby 51,Blueby 52 respectively - Note: last
convert_layoutstep is commented out as it is not necessary to specify last layout conversion. PrePostProcessor will do such conversion automatically
Integrate steps into model
We've finished with preprocessing steps declaration, now it is time to build it. For debugging purposes it is possible to print PrePostProcessor configuration on screen:
@sphinxtabset
@sphinxtab{C++}
@snippet docs/snippets/ov_preprocessing.cpp ov:preprocess:build
@endsphinxtab
@sphinxtab{Python}
@snippet docs/snippets/ov_preprocessing.py ov:preprocess:build
@endsphinxtab
@endsphinxtabset
After this, model will accept U8 input with {1, 480, 640, 3} shape, with BGR channels order. All conversion steps will be integrated into execution graph. Now you can load model on device and pass your image to model as is, without any data manipulation on application's side
See Also
- Preprocessing Details
- Layout API overview
ov::preprocess::PrePostProcessorC++ class documentation
