From 641a3da19dc7ea8cee4ae6f51727e49a197d597e Mon Sep 17 00:00:00 2001 From: Vladislav Golubev Date: Thu, 30 Jan 2025 11:30:37 +0100 Subject: [PATCH 1/6] [CPU][LPT] Removed legacy PrecisionRestriction limitations for Multiply (#28622) ### Tickets: - *CVS-161061* --- .../src/transformations/transformation_pipeline.cpp | 11 ----------- .../x64/fq_with_dq_not_optimal_transformation.cpp | 6 ++---- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp index bf4270e2a30ab3..e1386ccf79b326 100644 --- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp +++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp @@ -782,10 +782,6 @@ void Transformations::Lpt(const std::vector& defaultPrecision return PrecisionsRestriction::PrecisionsByPorts{{{0}, input0LowPrecisionList}, {{1}, {ov::element::i8}}}; }), - PrecisionsRestriction::create({ - {{0}, {ov::element::u8}}, - {{1}, {ov::element::i8}}, - }), PrecisionsRestriction::create( {{{0}, {ov::element::u8, ov::element::i8}}, {{1}, {ov::element::i8}}}), PrecisionsRestriction::create({{{0, 1}, {ov::element::u8}}}), @@ -803,13 +799,6 @@ void Transformations::Lpt(const std::vector& defaultPrecision quantizationRestrictions, LayerTransformation::Params(true, ov::element::f32, defaultPrecisions)); - CPU_SET_CALLBACK_COMMON( - lptManager, - [](const_node_ptr& node) -> bool { - return ov::is_type(node) && - !MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolution(node); - }, - MarkupPrecisions); CPU_SET_CALLBACK_COMMON( lptManager, [&defaultPrecisions](const_node_ptr& node) -> bool { diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/low_precision_transformations/x64/fq_with_dq_not_optimal_transformation.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/low_precision_transformations/x64/fq_with_dq_not_optimal_transformation.cpp index f58b88c37df72f..7c050e424a409c 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/low_precision_transformations/x64/fq_with_dq_not_optimal_transformation.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/low_precision_transformations/x64/fq_with_dq_not_optimal_transformation.cpp @@ -13,13 +13,11 @@ using namespace ov::pass::low_precision; namespace { const std::vector netPrecisions = { - ov::element::f32, - ov::element::f16 + ov::element::f32 }; const std::vector trasformationParamValues = { LayerTestsUtils::LayerTransformationParamsFactory::createParamsU8I8AndI8(), - // LayerTestsUtils::LayerTransformationParamsFactory::createParamsU8I8AndI8().setUpdatePrecisions(false) }; const std::vector fakeQuantizeOnDataValues = { @@ -97,7 +95,7 @@ const std::vector fakeQuanti { {0.3f}, ov::element::f32, {}, false } }, {}, - "u8" + "i8" } }; From 0e20dc44008c01d3ae80cd1bae3b5679f5315eac Mon Sep 17 00:00:00 2001 From: Karol Blaszczak Date: Thu, 30 Jan 2025 12:57:25 +0100 Subject: [PATCH 2/6] [DOCS] menu restructuring 2025 pass 4 mstr (#28738) Co-authored-by: sgolebiewski-intel --- docs/articles_en/about-openvino.rst | 2 +- .../getting-performance-numbers.rst | 6 +- .../performance-benchmarks-faq.rst | 2 +- .../documentation/openvino-extensibility.rst | 4 +- .../low-precision-transformations.rst | 2 +- .../documentation/openvino-security.rst | 2 +- docs/articles_en/get-started.rst | 7 +- .../install-openvino/configurations.rst | 1 + .../install-openvino/install-openvino-apt.rst | 10 +- .../install-openvino-archive-linux.rst | 12 +- .../install-openvino-archive-macos.rst | 10 +- .../install-openvino-archive-windows.rst | 10 +- .../install-openvino-brew.rst | 2 +- .../install-openvino-conan.rst | 2 +- .../install-openvino-conda.rst | 8 +- .../install-openvino/install-openvino-pip.rst | 2 +- .../install-openvino-vcpkg.rst | 2 +- .../install-openvino/install-openvino-yum.rst | 10 +- .../install-openvino-zypper.rst | 10 +- .../{ => get-started}/learn-openvino.rst | 0 .../interactive-tutorials-python.rst | 4 +- .../notebooks-installation.rst | 0 .../learn-openvino/openvino-samples.rst | 2 +- .../openvino-samples/benchmark-tool.rst | 16 +- .../openvino-samples/bert-benchmark.rst | 6 +- .../openvino-samples/get-started-demos.rst | 14 +- .../openvino-samples/hello-classification.rst | 10 +- .../hello-nv12-input-classification.rst | 10 +- .../openvino-samples/hello-query-device.rst | 4 +- .../openvino-samples/hello-reshape-ssd.rst | 12 +- .../image-classification-async.rst | 10 +- .../openvino-samples/model-creation.rst | 12 +- .../openvino-samples/sync-benchmark.rst | 6 +- .../openvino-samples/throughput-benchmark.rst | 6 +- .../model-preparation/convert-model-onnx.rst | 2 +- .../convert-model-paddle.rst | 2 +- .../convert-model-pytorch.rst | 2 +- .../changing-input-shape.rst | 4 +- .../inference-devices-and-modes.rst | 2 +- .../auto-device-selection.rst | 4 +- .../automatic-batching.rst | 2 +- .../cpu-device.rst | 2 +- .../gpu-device.rst | 4 +- .../query-device-properties.rst | 2 +- ...tegrate-openvino-with-your-application.rst | 8 +- .../inference-request.rst | 2 +- .../general-optimizations.rst | 2 +- .../high-level-performance-hints.rst | 2 +- docs/nbdoc/nbdoc.py | 2 +- ...-segmentation-point-clouds-with-output.rst | 48 ++-- docs/notebooks/async-api-with-output.rst | 52 ++-- docs/notebooks/auto-device-with-output.rst | 144 +++++----- docs/notebooks/catvton-with-output.rst | 72 ++--- ...clip-language-saliency-map-with-output.rst | 146 +++++----- ...p-zero-shot-classification-with-output.rst | 2 +- .../convert-to-openvino-with-output.rst | 80 +++--- ...ss-lingual-books-alignment-with-output.rst | 20 +- ...segmentation-quantize-nncf-with-output.rst | 96 +++---- ...ddcolor-image-colorization-with-output.rst | 2 +- .../depth-anything-v2-with-output.rst | 206 +++++++------- docs/notebooks/depth-anything-with-output.rst | 202 ++++++------- docs/notebooks/efficient-sam-with-output.rst | 258 ++++++++--------- docs/notebooks/florence2-with-output.rst | 44 +-- .../flux.1-image-generation-with-output.rst | 50 ++-- .../freevc-voice-conversion-with-output.rst | 158 +++++------ docs/notebooks/glm-edge-v-with-output.rst | 4 +- docs/notebooks/gpu-device-with-output.rst | 182 ++++++------ docs/notebooks/hello-npu-with-output.rst | 12 +- .../hugging-face-hub-with-output.rst | 52 ++-- ...nyuan-dit-image-generation-with-output.rst | 2 +- ...lassification-quantization-with-output.rst | 88 +++--- ...ruct-pix2pix-image-editing-with-output.rst | 268 +++++++++--------- docs/notebooks/internvl2-with-output.rst | 80 +++--- ...anus-multimodal-generation-with-output.rst | 4 +- ...classification-to-openvino-with-output.rst | 66 ++--- .../knowledge-graphs-conve-with-output.rst | 86 +++--- .../language-quantize-bert-with-output.rst | 84 +++--- ...a-multimodal-chatbot-genai-with-output.rst | 74 ++--- ...multimodal-chatbot-optimum-with-output.rst | 70 ++--- ...va-next-multimodal-chatbot-with-output.rst | 80 +++--- .../notebooks/llm-agent-react-with-output.rst | 2 +- .../llm-chatbot-generate-api-with-output.rst | 4 +- docs/notebooks/llm-chatbot-with-output.rst | 8 +- docs/notebooks/meter-reader-with-output.rst | 188 ++++++------ ...nicpm-v-multimodal-chatbot-with-output.rst | 62 ++-- docs/notebooks/mllama-3.2-with-output.rst | 68 ++--- .../mobileclip-video-search-with-output.rst | 2 +- .../modelscope-to-openvino-with-output.rst | 108 +++---- .../music-generation-with-output.rst | 112 ++++---- ...o-llava-multimodal-chatbot-with-output.rst | 2 +- docs/notebooks/omniparser-with-output.rst | 2 +- docs/notebooks/openvino-api-with-output.rst | 108 +++---- .../openvino-tokenizers-with-output.rst | 100 +++---- docs/notebooks/openvoice-with-output.rst | 182 ++++++------ .../optimize-preprocessing-with-output.rst | 102 +++---- ...to-openvino-classification-with-output.rst | 58 ++-- .../notebooks/person-tracking-with-output.rst | 114 ++++---- docs/notebooks/phi-3-vision-with-output.rst | 4 +- .../pix2struct-docvqa-with-output.rst | 38 +-- .../pytorch-onnx-to-openvino-with-output.rst | 50 ++-- ...training-quantization-nncf-with-output.rst | 124 ++++---- ...uantization-aware-training-with-output.rst | 136 ++++----- ...on-sparsity-aware-training-with-output.rst | 124 ++++---- .../pytorch-to-openvino-with-output.rst | 110 +++---- docs/notebooks/qwen2-audio-with-output.rst | 4 +- docs/notebooks/qwen2-vl-with-output.rst | 54 ++-- .../rmbg-background-removal-with-output.rst | 2 +- .../segment-anything-2-image-with-output.rst | 2 +- .../segment-anything-with-output.rst | 254 ++++++++--------- ...-shot-image-classification-with-output.rst | 102 +++---- ...tch-to-image-pix2pix-turbo-with-output.rst | 4 +- ...sound-generation-audioldm2-with-output.rst | 136 ++++----- .../sparsity-optimization-with-output.rst | 44 +-- ...tion-quantization-wav2vec2-with-output.rst | 76 ++--- docs/notebooks/stable-audio-with-output.rst | 166 +++++------ ...e-cascade-image-generation-with-output.rst | 114 ++++---- ...fusion-torchdynamo-backend-with-output.rst | 10 +- .../stable-diffusion-v3-with-output.rst | 92 +++--- docs/notebooks/stable-fast-3d-with-output.rst | 46 +-- ...-line-level-text-detection-with-output.rst | 162 +++++------ ...classification-to-openvino-with-output.rst | 48 ++-- ...e-segmentation-to-openvino-with-output.rst | 100 +++---- ...ject-detection-to-openvino-with-output.rst | 100 +++---- ...uantization-aware-training-with-output.rst | 4 +- .../text-to-image-genai-with-output.rst | 2 +- ...tflite-selfie-segmentation-with-output.rst | 88 +++--- .../tflite-to-openvino-with-output.rst | 38 +-- .../vision-background-removal-with-output.rst | 56 ++-- .../vision-monodepth-with-output.rst | 96 +++---- ...ov11-instance-segmentation-with-output.rst | 158 +++++------ ...yolov11-keypoint-detection-with-output.rst | 156 +++++----- .../yolov11-object-detection-with-output.rst | 160 +++++------ ...tion-with-accuracy-control-with-output.rst | 2 +- ...lov8-instance-segmentation-with-output.rst | 160 +++++------ .../yolov8-keypoint-detection-with-output.rst | 158 +++++------ .../yolov8-object-detection-with-output.rst | 4 +- .../yolov9-optimization-with-output.rst | 2 +- 137 files changed, 3700 insertions(+), 3698 deletions(-) rename docs/articles_en/{ => get-started}/learn-openvino.rst (100%) rename docs/articles_en/{ => get-started}/learn-openvino/interactive-tutorials-python.rst (94%) rename docs/articles_en/{ => get-started}/learn-openvino/interactive-tutorials-python/notebooks-installation.rst (100%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples.rst (97%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/benchmark-tool.rst (98%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/bert-benchmark.rst (85%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/get-started-demos.rst (93%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/hello-classification.rst (93%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/hello-nv12-input-classification.rst (92%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/hello-query-device.rst (95%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/hello-reshape-ssd.rst (90%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/image-classification-async.rst (95%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/model-creation.rst (92%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/sync-benchmark.rst (93%) rename docs/articles_en/{ => get-started}/learn-openvino/openvino-samples/throughput-benchmark.rst (94%) diff --git a/docs/articles_en/about-openvino.rst b/docs/articles_en/about-openvino.rst index 48422d9b3a7ae9..50251c9e811327 100644 --- a/docs/articles_en/about-openvino.rst +++ b/docs/articles_en/about-openvino.rst @@ -40,7 +40,7 @@ OpenVINO Ecosystem Along with the primary components of model optimization and runtime, the toolkit also includes: * `Neural Network Compression Framework (NNCF) `__ - a tool for enhanced OpenVINO™ inference to get performance boost with minimal accuracy drop. -* :doc:`Openvino Notebooks `- Jupyter Python notebook, which demonstrate key features of the toolkit. +* :doc:`Openvino Notebooks `- Jupyter Python notebook, which demonstrate key features of the toolkit. * `OpenVINO Model Server `__ - a server that enables scalability via a serving microservice. * :doc:`OpenVINO Training Extensions ` – a convenient environment to train Deep Learning models and convert them using the OpenVINO™ toolkit for optimized inference. * :doc:`Dataset Management Framework (Datumaro) ` - a tool to build, transform, and analyze datasets. diff --git a/docs/articles_en/about-openvino/performance-benchmarks/getting-performance-numbers.rst b/docs/articles_en/about-openvino/performance-benchmarks/getting-performance-numbers.rst index 9ba82690b00395..8b95010ebfa9dc 100644 --- a/docs/articles_en/about-openvino/performance-benchmarks/getting-performance-numbers.rst +++ b/docs/articles_en/about-openvino/performance-benchmarks/getting-performance-numbers.rst @@ -128,7 +128,7 @@ General considerations When comparing OpenVINO Runtime performance with the framework or reference code, make sure that both versions are as similar as possible: - * Wrap the exact inference execution (for examples, see :doc:`Benchmark app <../../learn-openvino/openvino-samples/benchmark-tool>`). + * Wrap the exact inference execution (for examples, see :doc:`Benchmark app <../../get-started/learn-openvino/openvino-samples/benchmark-tool>`). * Do not include model loading time. * Ensure that the inputs are identical for OpenVINO Runtime and the framework. For example, watch out for random values that can be used to populate the inputs. * In situations when any user-side pre-processing should be tracked separately, consider :doc:`image pre-processing and conversion <../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing>`. @@ -149,7 +149,7 @@ OpenVINO benchmarking (general) +++++++++++++++++++++++++++++++ The default way of measuring OpenVINO performance is running a piece of code, referred to as -:doc:`the benchmark tool <../../learn-openvino/openvino-samples/benchmark-tool>`. +:doc:`the benchmark tool <../../get-started/learn-openvino/openvino-samples/benchmark-tool>`. For Python, it is part of the OpenVINO Runtime installation, while for C++, it is available as a code sample. @@ -186,7 +186,7 @@ Internal Inference Performance Counters and Execution Graphs More detailed insights into inference performance breakdown can be achieved with device-specific performance counters and/or execution graphs. -Both :doc:`C++ and Python <../../learn-openvino/openvino-samples/benchmark-tool>` +Both :doc:`C++ and Python <../../get-started/learn-openvino/openvino-samples/benchmark-tool>` versions of the benchmark_app support a ``-pc`` command-line parameter that outputs an internal execution breakdown. diff --git a/docs/articles_en/about-openvino/performance-benchmarks/performance-benchmarks-faq.rst b/docs/articles_en/about-openvino/performance-benchmarks/performance-benchmarks-faq.rst index 5495711bc0054a..c5c3524b283552 100644 --- a/docs/articles_en/about-openvino/performance-benchmarks/performance-benchmarks-faq.rst +++ b/docs/articles_en/about-openvino/performance-benchmarks/performance-benchmarks-faq.rst @@ -27,7 +27,7 @@ Performance Information F.A.Q. All of the performance benchmarks on traditional network models are generated using the open-source tool within the Intel® Distribution of OpenVINO™ toolkit - called :doc:`benchmark_app <../../learn-openvino/openvino-samples/benchmark-tool>`. + called :doc:`benchmark_app <../../get-started/learn-openvino/openvino-samples/benchmark-tool>`. For diffusers (Stable-Diffusion) and foundational models (aka LLMs) please use the OpenVINO GenAI opensource repo `OpenVINO GenAI tools/llm_bench `__ diff --git a/docs/articles_en/documentation/openvino-extensibility.rst b/docs/articles_en/documentation/openvino-extensibility.rst index 6b2d0878bb687c..0e9042c7578839 100644 --- a/docs/articles_en/documentation/openvino-extensibility.rst +++ b/docs/articles_en/documentation/openvino-extensibility.rst @@ -187,6 +187,6 @@ See Also ######## * :doc:`OpenVINO Transformations ` -* :doc:`Using OpenVINO Runtime Samples <../learn-openvino/openvino-samples>` -* :doc:`Hello Shape Infer SSD sample <../learn-openvino/openvino-samples/hello-reshape-ssd>` +* :doc:`Using OpenVINO Runtime Samples <../get-started/learn-openvino/openvino-samples>` +* :doc:`Hello Shape Infer SSD sample <../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` diff --git a/docs/articles_en/documentation/openvino-extensibility/openvino-plugin-library/advanced-guides/low-precision-transformations.rst b/docs/articles_en/documentation/openvino-extensibility/openvino-plugin-library/advanced-guides/low-precision-transformations.rst index 4b64b2177af361..a2edce2bde9bc3 100644 --- a/docs/articles_en/documentation/openvino-extensibility/openvino-plugin-library/advanced-guides/low-precision-transformations.rst +++ b/docs/articles_en/documentation/openvino-extensibility/openvino-plugin-library/advanced-guides/low-precision-transformations.rst @@ -322,7 +322,7 @@ redistributed in the "Saved model" format, converted to a frozen graph using the Inference +++++++++ -The simplest way to infer the model and collect performance counters is :doc:`Benchmark Application <../../../../learn-openvino/openvino-samples/benchmark-tool>`. +The simplest way to infer the model and collect performance counters is :doc:`Benchmark Application <../../../../get-started/learn-openvino/openvino-samples/benchmark-tool>`. .. code-block:: sh diff --git a/docs/articles_en/documentation/openvino-security.rst b/docs/articles_en/documentation/openvino-security.rst index 03a99ba49e89e2..94c3630e0fa1ac 100644 --- a/docs/articles_en/documentation/openvino-security.rst +++ b/docs/articles_en/documentation/openvino-security.rst @@ -86,4 +86,4 @@ Additional Resources - Intel® Distribution of OpenVINO™ toolkit `home page `__. - :doc:`Convert a Model <../openvino-workflow/model-preparation/convert-model-to-ir>`. - :doc:`OpenVINO™ Runtime User Guide <../openvino-workflow/running-inference>`. -- For more information on Sample Applications, see the :doc:`OpenVINO Samples Overview <../learn-openvino/openvino-samples>` +- For more information on Sample Applications, see the :doc:`OpenVINO Samples Overview <../get-started/learn-openvino/openvino-samples>` diff --git a/docs/articles_en/get-started.rst b/docs/articles_en/get-started.rst index 94299293113f91..a9302fbb05272f 100644 --- a/docs/articles_en/get-started.rst +++ b/docs/articles_en/get-started.rst @@ -12,6 +12,7 @@ GET STARTED :hidden: Install OpenVINO + Learn OpenVINO System Requirements <./about-openvino/release-notes-openvino/system-requirements> @@ -67,7 +68,7 @@ Learn the basics of working with models and inference in OpenVINO. Begin with Interactive Tutorials - Jupyter Notebooks ----------------------------------------- -Start with :doc:`interactive Python ` that show the basics of model inference, the OpenVINO API, how to convert models to OpenVINO format, and more. +Start with :doc:`interactive Python ` that show the basics of model inference, the OpenVINO API, how to convert models to OpenVINO format, and more. * `Hello Image Classification `__ - Load an image classification model in OpenVINO and use it to apply a label to an image * `OpenVINO Runtime API Tutorial `__ - Learn the basic Python API for working with models in OpenVINO @@ -79,7 +80,7 @@ Start with :doc:`interactive Python ` for various C++ and Python applications that can be used as a starting point for your own application. For C++ developers, step through the :doc:`Get Started with C++ Samples ` to learn how to build and run an image classification program that uses OpenVINO’s C++ API. +View :doc:`sample code ` for various C++ and Python applications that can be used as a starting point for your own application. For C++ developers, step through the :doc:`Get Started with C++ Samples ` to learn how to build and run an image classification program that uses OpenVINO’s C++ API. .. _integrate-openvino: @@ -120,7 +121,7 @@ Pipeline and model configuration features in OpenVINO Runtime allow you to easil * :doc:`Automatic Batching ` performs on-the-fly grouping of inference requests to maximize utilization of the target hardware’s memory and processing cores. * :doc:`Performance Hints ` automatically adjust runtime parameters to prioritize for low latency or high throughput * :doc:`Dynamic Shapes ` reshapes models to accept arbitrarily-sized inputs, increasing flexibility for applications that encounter different data shapes -* :doc:`Benchmark Tool ` characterizes model performance in various hardware and pipeline configurations +* :doc:`Benchmark Tool ` characterizes model performance in various hardware and pipeline configurations .. _additional-about-openvino/additional-resources: diff --git a/docs/articles_en/get-started/install-openvino/configurations.rst b/docs/articles_en/get-started/install-openvino/configurations.rst index c0e885dd956c78..ec009211996b3d 100644 --- a/docs/articles_en/get-started/install-openvino/configurations.rst +++ b/docs/articles_en/get-started/install-openvino/configurations.rst @@ -15,6 +15,7 @@ Additional Configurations For GPU For NPU GenAI Dependencies + Troubleshooting Guide for OpenVINO™ Installation & Configuration For certain use cases, you may need to install additional software, to benefit from the full potential of OpenVINO™. Check the following list for components used in your workflow: diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-apt.rst b/docs/articles_en/get-started/install-openvino/install-openvino-apt.rst index 35498fa64ee4b1..726e2872bdae0e 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-apt.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-apt.rst @@ -156,7 +156,7 @@ need to install additional components. Check the to see if your case needs any of them. With the APT distribution, you can build OpenVINO sample files, as explained in the -:doc:`guide for OpenVINO sample applications <../../../learn-openvino/openvino-samples>`. +:doc:`guide for OpenVINO sample applications <../../../get-started/learn-openvino/openvino-samples>`. For C++ and C, just run the ``build_samples.sh`` script: .. tab-set:: @@ -215,7 +215,7 @@ What's Next? Now that you've installed OpenVINO Runtime, you're ready to run your own machine learning applications! Learn more about how to integrate a model in OpenVINO applications by trying out the following tutorials: -* Try the :doc:`C++ Quick Start Example <../../../learn-openvino/openvino-samples/get-started-demos>` for step-by-step +* Try the :doc:`C++ Quick Start Example <../../../get-started/learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. .. image:: https://user-images.githubusercontent.com/36741649/127170593-86976dc3-e5e4-40be-b0a6-206379cd7df5.jpg @@ -223,8 +223,8 @@ Learn more about how to integrate a model in OpenVINO applications by trying out * Visit the :ref:`Samples ` page for other C++ example applications to get you started with OpenVINO, such as: - * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../learn-openvino/openvino-samples/hello-reshape-ssd>` - * :doc:`Object classification sample <../../../learn-openvino/openvino-samples/hello-classification>` + * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` + * :doc:`Object classification sample <../../../get-started/learn-openvino/openvino-samples/hello-classification>` You can also try the following: @@ -232,6 +232,6 @@ You can also try the following: * To prepare your models for working with OpenVINO, see :doc:`Model Preparation <../../../openvino-workflow/model-preparation>`. * See pre-trained deep learning models on `Hugging Face `__ * Learn more about :doc:`Inference with OpenVINO Runtime <../../../openvino-workflow/running-inference>`. -* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../learn-openvino/openvino-samples>`. +* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>`. * Take a glance at the OpenVINO `product home page `__ . diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-archive-linux.rst b/docs/articles_en/get-started/install-openvino/install-openvino-archive-linux.rst index 5f89d4e95221d3..fca179d815fca7 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-archive-linux.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-archive-linux.rst @@ -224,7 +224,7 @@ Learn more about how to integrate a model in OpenVINO applications by trying out .. image:: https://user-images.githubusercontent.com/15709723/127752390-f6aa371f-31b5-4846-84b9-18dd4f662406.gif :width: 400 - Visit the :doc:`Tutorials <../../../learn-openvino/interactive-tutorials-python>` page for more Jupyter Notebooks to get you started with OpenVINO, such as: + Visit the :doc:`Tutorials <../../../get-started/learn-openvino/interactive-tutorials-python>` page for more Jupyter Notebooks to get you started with OpenVINO, such as: * `OpenVINO Python API Tutorial <../../notebooks/openvino-api-with-output.html>`__ * `Basic image classification program with Hello Image Classification <../../notebooks/hello-world-with-output.html>`__ @@ -234,16 +234,16 @@ Learn more about how to integrate a model in OpenVINO applications by trying out .. tab-item:: Get started with C++ :sync: get-started-cpp - Try the :doc:`C++ Quick Start Example <../../../learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions + Try the :doc:`C++ Quick Start Example <../../../get-started/learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. .. image:: https://user-images.githubusercontent.com/36741649/127170593-86976dc3-e5e4-40be-b0a6-206379cd7df5.jpg :width: 400 - Visit the :doc:`Samples <../../../learn-openvino/openvino-samples>` page for other C++ example applications to get you started with OpenVINO, such as: + Visit the :doc:`Samples <../../../get-started/learn-openvino/openvino-samples>` page for other C++ example applications to get you started with OpenVINO, such as: - * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../learn-openvino/openvino-samples/hello-reshape-ssd>` - * :doc:`Object classification sample <../../../learn-openvino/openvino-samples/hello-classification>` + * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` + * :doc:`Object classification sample <../../../get-started/learn-openvino/openvino-samples/hello-classification>` @@ -276,5 +276,5 @@ Additional Resources * :doc:`Troubleshooting Guide for OpenVINO Installation & Configuration <./configurations/troubleshooting-install-config>` * Converting models for use with OpenVINO™: :doc:`Convert a Model <../../../openvino-workflow/model-preparation>` * Writing your own OpenVINO™ applications: :doc:`OpenVINO™ Runtime User Guide <../../../openvino-workflow/running-inference>` -* Sample applications: :doc:`OpenVINO™ Toolkit Samples Overview <../../../learn-openvino/openvino-samples>` +* Sample applications: :doc:`OpenVINO™ Toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>` * Pre-trained deep learning models on `Hugging Face `__. diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-archive-macos.rst b/docs/articles_en/get-started/install-openvino/install-openvino-archive-macos.rst index a3bbfcf8d6330b..89aab67b231c41 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-archive-macos.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-archive-macos.rst @@ -145,7 +145,7 @@ Now that you've installed OpenVINO Runtime, you're ready to run your own machine .. image:: https://user-images.githubusercontent.com/15709723/127752390-f6aa371f-31b5-4846-84b9-18dd4f662406.gif :width: 400 - Visit the :doc:`Tutorials <../../../learn-openvino/interactive-tutorials-python>` page for more Jupyter Notebooks to get you started with OpenVINO, such as: + Visit the :doc:`Tutorials <../../../get-started/learn-openvino/interactive-tutorials-python>` page for more Jupyter Notebooks to get you started with OpenVINO, such as: * `OpenVINO Python API Tutorial <../../notebooks/openvino-api-with-output.html>`__ * `Basic image classification program with Hello Image Classification <../../notebooks/hello-world-with-output.html>`__ @@ -154,15 +154,15 @@ Now that you've installed OpenVINO Runtime, you're ready to run your own machine .. tab-item:: Get started with C++ :sync: get-started-cpp - Try the :doc:`C++ Quick Start Example <../../../learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. + Try the :doc:`C++ Quick Start Example <../../../get-started/learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. .. image:: https://user-images.githubusercontent.com/36741649/127170593-86976dc3-e5e4-40be-b0a6-206379cd7df5.jpg :width: 400 Visit the :ref:`Samples ` page for other C++ example applications to get you started with OpenVINO, such as: - * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../learn-openvino/openvino-samples/hello-reshape-ssd>` - * :doc:`Object classification sample <../../../learn-openvino/openvino-samples/hello-classification>` + * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` + * :doc:`Object classification sample <../../../get-started/learn-openvino/openvino-samples/hello-classification>` Uninstalling Intel® Distribution of OpenVINO™ Toolkit ##################################################### @@ -189,5 +189,5 @@ Additional Resources * :doc:`Troubleshooting Guide for OpenVINO Installation & Configuration <../install-openvino>` * :doc:`Convert models for use with OpenVINO™ <../../../openvino-workflow/model-preparation/convert-model-to-ir>` * :doc:`Write your own OpenVINO™ applications <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` -* Sample applications: :doc:`OpenVINO™ Toolkit Samples Overview <../../../learn-openvino/openvino-samples>` +* Sample applications: :doc:`OpenVINO™ Toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>` * Pre-trained deep learning models on `Hugging Face `__ diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-archive-windows.rst b/docs/articles_en/get-started/install-openvino/install-openvino-archive-windows.rst index 52899de206ff42..ebda48847aafab 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-archive-windows.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-archive-windows.rst @@ -161,7 +161,7 @@ Now that you've installed OpenVINO Runtime, you're ready to run your own machine .. image:: https://user-images.githubusercontent.com/15709723/127752390-f6aa371f-31b5-4846-84b9-18dd4f662406.gif :width: 400 - Visit the :doc:`Tutorials <../../../learn-openvino/interactive-tutorials-python>` page for more Jupyter Notebooks to get you started with OpenVINO, such as: + Visit the :doc:`Tutorials <../../../get-started/learn-openvino/interactive-tutorials-python>` page for more Jupyter Notebooks to get you started with OpenVINO, such as: * `OpenVINO Python API Tutorial <../../notebooks/openvino-api-with-output.html>`__ * `Basic image classification program with Hello Image Classification <../../notebooks/hello-world-with-output.html>`__ @@ -170,15 +170,15 @@ Now that you've installed OpenVINO Runtime, you're ready to run your own machine .. tab-item:: Get started with C++ :sync: get-started-cpp - Try the :doc:`C++ Quick Start Example <../../../learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. + Try the :doc:`C++ Quick Start Example <../../../get-started/learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. .. image:: https://user-images.githubusercontent.com/36741649/127170593-86976dc3-e5e4-40be-b0a6-206379cd7df5.jpg :width: 400 Visit the :ref:`Samples ` page for other C++ example applications to get you started with OpenVINO, such as: - * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../learn-openvino/openvino-samples/hello-reshape-ssd>` - * :doc:`Object classification sample <../../../learn-openvino/openvino-samples/hello-classification>` + * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` + * :doc:`Object classification sample <../../../get-started/learn-openvino/openvino-samples/hello-classification>` .. _uninstall-from-windows: @@ -212,5 +212,5 @@ Additional Resources * :doc:`Troubleshooting Guide for OpenVINO Installation & Configuration <../install-openvino>` * :doc:`Convert models for use with OpenVINO™ <../../../openvino-workflow/model-preparation/convert-model-to-ir>` * :doc:`Write your own OpenVINO™ applications <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` -* Sample applications: :doc:`OpenVINO™ Toolkit Samples Overview <../../../learn-openvino/openvino-samples>` +* Sample applications: :doc:`OpenVINO™ Toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>` * Pre-trained deep learning models on `Hugging Face `__. diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-brew.rst b/docs/articles_en/get-started/install-openvino/install-openvino-brew.rst index 033d3a80e5d57a..ce4655a8e2cf72 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-brew.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-brew.rst @@ -61,7 +61,7 @@ Now that you've installed OpenVINO Runtime, you can try the following things: * To prepare your models for working with OpenVINO, see :doc:`Model Preparation <../../../openvino-workflow/model-preparation>`. * See pre-trained deep learning models on `Hugging Face `__. * Learn more about :doc:`Inference with OpenVINO Runtime <../../../openvino-workflow/running-inference>`. -* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../learn-openvino/openvino-samples>`. +* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>`. * Check out the OpenVINO `product home page `__. diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-conan.rst b/docs/articles_en/get-started/install-openvino/install-openvino-conan.rst index 06557003b3cbf6..b8c10c9a2a00ac 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-conan.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-conan.rst @@ -72,7 +72,7 @@ Additional Resources * Learn more about :doc:`OpenVINO Workflow <../../../openvino-workflow>`. * To prepare your models for working with OpenVINO, see :doc:`Model Preparation <../../../openvino-workflow/model-preparation>`. * Learn more about :doc:`Inference with OpenVINO Runtime <../../../openvino-workflow/running-inference>`. -* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../learn-openvino/openvino-samples>`. +* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>`. * Check out the OpenVINO `product home page `__. diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-conda.rst b/docs/articles_en/get-started/install-openvino/install-openvino-conda.rst index 3ad9849199006e..6b544f48541ec9 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-conda.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-conda.rst @@ -146,14 +146,14 @@ What's Next? Now that you've installed OpenVINO Runtime, you are ready to run your own machine learning applications! To learn more about how to integrate a model in OpenVINO applications, try out some tutorials and sample applications. -Try the :doc:`C++ Quick Start Example <../../../learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions +Try the :doc:`C++ Quick Start Example <../../../get-started/learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. .. image:: https://user-images.githubusercontent.com/36741649/127170593-86976dc3-e5e4-40be-b0a6-206379cd7df5.jpg :width: 400 -Visit the :doc:`Samples <../../../learn-openvino/openvino-samples>` page for other C++ example applications to get you started with OpenVINO, such as: +Visit the :doc:`Samples <../../../get-started/learn-openvino/openvino-samples>` page for other C++ example applications to get you started with OpenVINO, such as: -* :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../learn-openvino/openvino-samples/hello-reshape-ssd>` -* :doc:`Object classification sample <../../../learn-openvino/openvino-samples/hello-classification>` +* :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` +* :doc:`Object classification sample <../../../get-started/learn-openvino/openvino-samples/hello-classification>` diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-pip.rst b/docs/articles_en/get-started/install-openvino/install-openvino-pip.rst index df276a5aae4a1d..bf0965e3edf7fc 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-pip.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-pip.rst @@ -149,7 +149,7 @@ your web browser. Get started with Python +++++++++++++++++++++++ -Visit the :doc:`Tutorials <../../../learn-openvino/interactive-tutorials-python>` page for more +Visit the :doc:`Tutorials <../../../get-started/learn-openvino/interactive-tutorials-python>` page for more Jupyter Notebooks to get you started with OpenVINO, such as: * `OpenVINO Python API Tutorial `__ diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-vcpkg.rst b/docs/articles_en/get-started/install-openvino/install-openvino-vcpkg.rst index 7e07c0871bf7d7..8dcff56b351557 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-vcpkg.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-vcpkg.rst @@ -83,7 +83,7 @@ Now that you've installed OpenVINO Runtime, you can try the following things: * To prepare your models for working with OpenVINO, see :doc:`Model Preparation <../../../openvino-workflow/model-preparation>`. * See pre-trained deep learning models on `Hugging Face `__. * Learn more about :doc:`Inference with OpenVINO Runtime <../../../openvino-workflow/running-inference>`. -* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../learn-openvino/openvino-samples>`. +* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>`. * Check out the OpenVINO `product home page `__ . diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-yum.rst b/docs/articles_en/get-started/install-openvino/install-openvino-yum.rst index 6a3d441a888cbd..b2d1870376b444 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-yum.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-yum.rst @@ -117,7 +117,7 @@ need to install additional components. Check the to see if your case needs any of them. With the YUM distribution, you can build OpenVINO sample files, as explained in the -:doc:`guide for OpenVINO sample applications <../../../learn-openvino/openvino-samples>`. +:doc:`guide for OpenVINO sample applications <../../../get-started/learn-openvino/openvino-samples>`. For C++ and C, just run the ``build_samples.sh`` script: .. tab-set:: @@ -175,7 +175,7 @@ What's Next? Now that you've installed OpenVINO Runtime, you're ready to run your own machine learning applications! Learn more about how to integrate a model in OpenVINO applications by trying out the following tutorials: -* Try the :doc:`C++ Quick Start Example <../../../learn-openvino/openvino-samples/get-started-demos>` +* Try the :doc:`C++ Quick Start Example <../../../get-started/learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. .. image:: https://user-images.githubusercontent.com/36741649/127170593-86976dc3-e5e4-40be-b0a6-206379cd7df5.jpg @@ -183,8 +183,8 @@ Learn more about how to integrate a model in OpenVINO applications by trying out * Visit the :ref:`Samples ` page for other C++ example applications to get you started with OpenVINO, such as: - * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../learn-openvino/openvino-samples/hello-reshape-ssd>` - * :doc:`Object classification sample <../../../learn-openvino/openvino-samples/hello-classification>` + * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` + * :doc:`Object classification sample <../../../get-started/learn-openvino/openvino-samples/hello-classification>` You can also try the following things: @@ -192,7 +192,7 @@ You can also try the following things: * To prepare your models for working with OpenVINO, see :doc:`Model Preparation <../../../openvino-workflow/model-preparation>`. * See pre-trained deep learning models on `Hugging Face `__. * Learn more about :doc:`Inference with OpenVINO Runtime <../../../openvino-workflow/running-inference>`. -* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../learn-openvino/openvino-samples>`. +* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>`. * Take a glance at the OpenVINO `product home page `__ . diff --git a/docs/articles_en/get-started/install-openvino/install-openvino-zypper.rst b/docs/articles_en/get-started/install-openvino/install-openvino-zypper.rst index e27eda31429dc6..ca17a7b1bc45c1 100644 --- a/docs/articles_en/get-started/install-openvino/install-openvino-zypper.rst +++ b/docs/articles_en/get-started/install-openvino/install-openvino-zypper.rst @@ -69,7 +69,7 @@ need to install additional components. Check the to see if your case needs any of them. With the ZYPPER distribution, you can build OpenVINO sample files, as explained in the -:doc:`guide for OpenVINO sample applications <../../../learn-openvino/openvino-samples>`. +:doc:`guide for OpenVINO sample applications <../../../get-started/learn-openvino/openvino-samples>`. For C++ and C, just run the ``build_samples.sh`` script: .. tab-set:: @@ -127,7 +127,7 @@ What's Next? Now that you've installed OpenVINO Runtime, you're ready to run your own machine learning applications! Learn more about how to integrate a model in OpenVINO applications by trying out the following tutorials: -* Try the :doc:`C++ Quick Start Example <../../../learn-openvino/openvino-samples/get-started-demos>` +* Try the :doc:`C++ Quick Start Example <../../../get-started/learn-openvino/openvino-samples/get-started-demos>` for step-by-step instructions on building and running a basic image classification C++ application. .. image:: https://user-images.githubusercontent.com/36741649/127170593-86976dc3-e5e4-40be-b0a6-206379cd7df5.jpg @@ -135,8 +135,8 @@ Learn more about how to integrate a model in OpenVINO applications by trying out * Visit the :ref:`Samples ` page for other C++ example applications to get you started with OpenVINO, such as: - * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../learn-openvino/openvino-samples/hello-reshape-ssd>` - * :doc:`Object classification sample <../../../learn-openvino/openvino-samples/hello-classification>` + * :doc:`Basic object detection with the Hello Reshape SSD C++ sample <../../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>` + * :doc:`Object classification sample <../../../get-started/learn-openvino/openvino-samples/hello-classification>` You can also try the following things: @@ -144,7 +144,7 @@ You can also try the following things: * To prepare your models for working with OpenVINO, see :doc:`Model Preparation <../../../openvino-workflow/model-preparation>`. * See pre-trained deep learning models on `Hugging Face `__. * Learn more about :doc:`Inference with OpenVINO Runtime <../../../openvino-workflow/running-inference>`. -* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../learn-openvino/openvino-samples>`. +* See sample applications in :doc:`OpenVINO toolkit Samples Overview <../../../get-started/learn-openvino/openvino-samples>`. * Take a glance at the OpenVINO `product home page `__ . diff --git a/docs/articles_en/learn-openvino.rst b/docs/articles_en/get-started/learn-openvino.rst similarity index 100% rename from docs/articles_en/learn-openvino.rst rename to docs/articles_en/get-started/learn-openvino.rst diff --git a/docs/articles_en/learn-openvino/interactive-tutorials-python.rst b/docs/articles_en/get-started/learn-openvino/interactive-tutorials-python.rst similarity index 94% rename from docs/articles_en/learn-openvino/interactive-tutorials-python.rst rename to docs/articles_en/get-started/learn-openvino/interactive-tutorials-python.rst index 637c22aa4587a1..f8b50e489488fa 100644 --- a/docs/articles_en/learn-openvino/interactive-tutorials-python.rst +++ b/docs/articles_en/get-started/learn-openvino/interactive-tutorials-python.rst @@ -46,10 +46,10 @@ Additional Resources * `Google Colab `__ -.. |binder logo| image:: ../assets/images/launch_in_binder.svg +.. |binder logo| image:: ../../assets/images/launch_in_binder.svg :class: notebook-badge-p :alt: Binder button -.. |colab logo| image:: ../assets/images/open_in_colab.svg +.. |colab logo| image:: ../../assets/images/open_in_colab.svg :class: notebook-badge-p :alt: Google Colab button diff --git a/docs/articles_en/learn-openvino/interactive-tutorials-python/notebooks-installation.rst b/docs/articles_en/get-started/learn-openvino/interactive-tutorials-python/notebooks-installation.rst similarity index 100% rename from docs/articles_en/learn-openvino/interactive-tutorials-python/notebooks-installation.rst rename to docs/articles_en/get-started/learn-openvino/interactive-tutorials-python/notebooks-installation.rst diff --git a/docs/articles_en/learn-openvino/openvino-samples.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples.rst similarity index 97% rename from docs/articles_en/learn-openvino/openvino-samples.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples.rst index a2f99addbbaf01..fdb14fe635a7d4 100644 --- a/docs/articles_en/learn-openvino/openvino-samples.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples.rst @@ -86,4 +86,4 @@ Additional Resources #################### * :doc:`Get Started with Samples ` -* :doc:`OpenVINO Runtime User Guide <../openvino-workflow/running-inference>` +* :doc:`OpenVINO Runtime User Guide <../../openvino-workflow/running-inference>` diff --git a/docs/articles_en/learn-openvino/openvino-samples/benchmark-tool.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/benchmark-tool.rst similarity index 98% rename from docs/articles_en/learn-openvino/openvino-samples/benchmark-tool.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/benchmark-tool.rst index cde0eef055d5cb..3f841f624d7f77 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/benchmark-tool.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/benchmark-tool.rst @@ -11,7 +11,7 @@ Benchmark Tool This page demonstrates how to use the Benchmark Tool to estimate deep learning inference performance on supported devices. Note that the MULTI plugin mentioned here is considered a legacy tool and currently is just a mapping of the -:doc:`AUTO plugin <../../openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection>`. +:doc:`AUTO plugin <../../../openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection>`. .. note:: @@ -27,13 +27,13 @@ Basic Usage :sync: python The Python ``benchmark_app`` is automatically installed when you install OpenVINO - using :doc:`PyPI <../../get-started/install-openvino/install-openvino-pip>`. + using :doc:`PyPI <../../../get-started/install-openvino/install-openvino-pip>`. Before running ``benchmark_app``, make sure the ``openvino_env`` virtual environment is activated, and navigate to the directory where your model is located. The benchmarking application works with models in the OpenVINO IR (``model.xml`` and ``model.bin``) and ONNX (``model.onnx``) formats. - Make sure to :doc:`convert your models <../../openvino-workflow/model-preparation/convert-model-to-ir>` + Make sure to :doc:`convert your models <../../../openvino-workflow/model-preparation/convert-model-to-ir>` if necessary. To run benchmarking with default options on a model, use the following command: @@ -59,7 +59,7 @@ Basic Usage The benchmarking application works with models in the OpenVINO IR, TensorFlow, TensorFlow Lite, PaddlePaddle, PyTorch and ONNX formats. If you need it, - OpenVINO also allows you to :doc:`convert your models <../../openvino-workflow/model-preparation/convert-model-to-ir>`. + OpenVINO also allows you to :doc:`convert your models <../../../openvino-workflow/model-preparation/convert-model-to-ir>`. To run benchmarking with default options on a model, use the following command: @@ -182,10 +182,10 @@ parallel inference requests to utilize all the threads available on the device. On GPU, it automatically sets the inference batch size to fill up the GPU memory available. For more information on performance hints, see the -:doc:`High-level Performance Hints <../../openvino-workflow/running-inference/optimize-inference/high-level-performance-hints>` page. +:doc:`High-level Performance Hints <../../../openvino-workflow/running-inference/optimize-inference/high-level-performance-hints>` page. For more details on optimal runtime configurations and how they are automatically determined using performance hints, see -:doc:`Runtime Inference Optimizations <../../openvino-workflow/running-inference/optimize-inference>`. +:doc:`Runtime Inference Optimizations <../../../openvino-workflow/running-inference/optimize-inference>`. Device @@ -220,7 +220,7 @@ You may also specify ``AUTO`` as the device, in which case the ``benchmark_app`` automatically select the best device for benchmarking and support it with the CPU at the model loading stage. This may result in increased performance, thus, should be used purposefully. For more information, see the -:doc:`Automatic device selection <../../openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection>` page. +:doc:`Automatic device selection <../../../openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection>` page. .. note:: @@ -934,4 +934,4 @@ Additional Resources - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` diff --git a/docs/articles_en/learn-openvino/openvino-samples/bert-benchmark.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/bert-benchmark.rst similarity index 85% rename from docs/articles_en/learn-openvino/openvino-samples/bert-benchmark.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/bert-benchmark.rst index 13f18fc3272b34..459dbcdd5817a4 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/bert-benchmark.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/bert-benchmark.rst @@ -26,7 +26,7 @@ resulting model, downloads a dataset and runs a benchmark on the dataset. You can see the explicit description of each sample step at -:doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +:doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. Running @@ -60,8 +60,8 @@ The sample outputs how long it takes to process a dataset. Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `Bert Benchmark Python Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/get-started-demos.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/get-started-demos.rst similarity index 93% rename from docs/articles_en/learn-openvino/openvino-samples/get-started-demos.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/get-started-demos.rst index f9ae7fcabbc129..f61ccf5cacd2f3 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/get-started-demos.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/get-started-demos.rst @@ -9,9 +9,9 @@ Get Started with Samples To use OpenVINO samples, install OpenVINO using one of the following distributions: -* Archive files (recommended) - :doc:`Linux <../../get-started/install-openvino/install-openvino-archive-linux>` | :doc:`Windows <../../get-started/install-openvino/install-openvino-archive-windows>` | :doc:`macOS <../../get-started/install-openvino/install-openvino-archive-macos>` -* :doc:`APT <../../get-started/install-openvino/install-openvino-apt>` or :doc:`YUM <../../get-started/install-openvino/install-openvino-yum>` for Linux -* :doc:`Docker image <../../get-started/install-openvino/install-openvino-docker-linux>` +* Archive files (recommended) - :doc:`Linux <../../../get-started/install-openvino/install-openvino-archive-linux>` | :doc:`Windows <../../../get-started/install-openvino/install-openvino-archive-windows>` | :doc:`macOS <../../../get-started/install-openvino/install-openvino-archive-macos>` +* :doc:`APT <../../../get-started/install-openvino/install-openvino-apt>` or :doc:`YUM <../../../get-started/install-openvino/install-openvino-yum>` for Linux +* :doc:`Docker image <../../../get-started/install-openvino/install-openvino-docker-linux>` * `Build from source `__ If you install OpenVINO Runtime via archive files, sample applications are created in the following directories: @@ -23,7 +23,7 @@ If you install OpenVINO Runtime via archive files, sample applications are creat .. note:: If you install OpenVINO without samples, you can still get them directly from `the OpenVINO repository `__. -Before you build samples, refer to the :doc:`system requirements <../../about-openvino/release-notes-openvino/system-requirements>` page and make sure that all the prerequisites have been installed. Next, you can perform the following steps: +Before you build samples, refer to the :doc:`system requirements <../../../about-openvino/release-notes-openvino/system-requirements>` page and make sure that all the prerequisites have been installed. Next, you can perform the following steps: 1. :ref:`Build Samples `. 2. :ref:`Select a Sample `. @@ -262,7 +262,7 @@ You need a model that is specific for your inference task. You can get it from o Convert the Model -------------------- -If Your model requires conversion, check the `article `__ for information how to do it. +If Your model requires conversion, check the `article `__ for information how to do it. .. _download-media: @@ -409,7 +409,7 @@ The following command shows how to run the Image Classification Code Sample usin .. note:: - * Running inference on Intel® Processor Graphics (GPU) requires :doc:`additional hardware configuration steps <../../get-started/install-openvino/configurations/configurations-intel-gpu>`, as described earlier on this page. + * Running inference on Intel® Processor Graphics (GPU) requires :doc:`additional hardware configuration steps <../../../get-started/install-openvino/configurations/configurations-intel-gpu>`, as described earlier on this page. * Running on GPU is not compatible with macOS. .. tab-set:: @@ -469,7 +469,7 @@ The following command shows how to run the Image Classification Code Sample usin When the sample application is complete, you are given the label and confidence for the top 10 categories. The input image and sample output of the inference results is shown below: -.. image:: ../../assets/images/dog.png +.. image:: ../../../assets/images/dog.png .. code-block:: sh diff --git a/docs/articles_en/learn-openvino/openvino-samples/hello-classification.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-classification.rst similarity index 93% rename from docs/articles_en/learn-openvino/openvino-samples/hello-classification.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/hello-classification.rst index 219365e2bc0d7f..482ec739b40664 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/hello-classification.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-classification.rst @@ -50,7 +50,7 @@ inference, and processes output data, logging each step in a standard output str You can see the explicit description of each sample step at -:doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +:doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. Running @@ -94,10 +94,10 @@ To run the sample, you need to specify a model and an image: application or reconvert your model using model conversion API with ``reverse_input_channels`` argument specified. For more information about the argument, refer to the **Color Conversion** section of - :doc:`Preprocessing API <../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. + :doc:`Preprocessing API <../../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. - Before running the sample with a trained model, make sure the model is converted to the intermediate representation (IR) format (\*.xml + \*.bin) - using the :doc:`model conversion API <../../openvino-workflow/model-preparation/convert-model-to-ir>`. + using the :doc:`model conversion API <../../../openvino-workflow/model-preparation/convert-model-to-ir>`. - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. - The sample supports NCHW model layout only. @@ -254,10 +254,10 @@ Sample Output Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `OpenVINO Runtime C API `__ - `Hello Classification Python Sample on Github `__ - `Hello Classification C++ Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/hello-nv12-input-classification.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-nv12-input-classification.rst similarity index 92% rename from docs/articles_en/learn-openvino/openvino-samples/hello-nv12-input-classification.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/hello-nv12-input-classification.rst index 3298a8625e6bfe..3aa8b0a10fb996 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/hello-nv12-input-classification.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-nv12-input-classification.rst @@ -45,7 +45,7 @@ You can place labels in ``.labels`` file near the model to get pretty output. You can see the explicit description of each sample step at -:doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +:doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. Running @@ -96,10 +96,10 @@ the following command, you can convert an ordinary image to an uncompressed NV12 you trained your model to work with RGB order, you need to reconvert your model using model conversion API with ``reverse_input_channels`` argument specified. For more information about the argument, refer to the - **Color Conversion** section of :doc:`Preprocessing API <../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. + **Color Conversion** section of :doc:`Preprocessing API <../../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. - Before running the sample with a trained model, make sure the model is converted to the intermediate representation (IR) format (\*.xml + \*.bin) - using the :doc:`model conversion API <../../openvino-workflow/model-preparation/convert-model-to-ir>`. + using the :doc:`model conversion API <../../../openvino-workflow/model-preparation/convert-model-to-ir>`. - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. Example @@ -205,10 +205,10 @@ Sample Output Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `API Reference `__ - `Hello NV12 Input Classification C++ Sample on Github `__ - `Hello NV12 Input Classification C Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/hello-query-device.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-query-device.rst similarity index 95% rename from docs/articles_en/learn-openvino/openvino-samples/hello-query-device.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/hello-query-device.rst index 46f145a808e330..c14012526ea7be 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/hello-query-device.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-query-device.rst @@ -9,7 +9,7 @@ Hello Query Device Sample This sample demonstrates how to show OpenVINO™ Runtime devices and prints their -metrics and default configuration values using :doc:`Query Device API feature <../../openvino-workflow/running-inference/inference-devices-and-modes/query-device-properties>`. +metrics and default configuration values using :doc:`Query Device API feature <../../../openvino-workflow/running-inference/inference-devices-and-modes/query-device-properties>`. To build the sample, use instructions available at :ref:`Build the Sample Applications ` section in "Get Started with Samples" guide. @@ -130,7 +130,7 @@ For example: Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO™ Toolkit Samples <../openvino-samples>` - `Hello Query Device Python Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/hello-reshape-ssd.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-reshape-ssd.rst similarity index 90% rename from docs/articles_en/learn-openvino/openvino-samples/hello-reshape-ssd.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/hello-reshape-ssd.rst index 0e929bb5ed2701..5f33b6b6b32e84 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/hello-reshape-ssd.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/hello-reshape-ssd.rst @@ -9,7 +9,7 @@ Hello Reshape SSD Sample This sample demonstrates how to do synchronous inference of object detection models -using :doc:`Shape Inference feature <../../openvino-workflow/running-inference/changing-input-shape>`. Before +using :doc:`Shape Inference feature <../../../openvino-workflow/running-inference/changing-input-shape>`. Before using the sample, refer to the following requirements: - Models with only one input and output are supported. @@ -46,7 +46,7 @@ As a result, the program creates an output image, logging each step in a standar You can see the explicit description of -each sample step at :doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. +each sample step at :doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. Running #################### @@ -84,10 +84,10 @@ To run the sample, you need to specify a model and an image: reconvert your model using model conversion API with ``reverse_input_channels`` argument specified. For more information about the argument, refer to the **Color Conversion** section of - :doc:`Preprocessing API <../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. + :doc:`Preprocessing API <../../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. - Before running the sample with a trained model, make sure the model is converted to the intermediate representation (IR) format (\*.xml + \*.bin) - using :doc:`model conversion API <../../openvino-workflow/model-preparation/convert-model-to-ir>`. + using :doc:`model conversion API <../../../openvino-workflow/model-preparation/convert-model-to-ir>`. - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. Example @@ -201,10 +201,10 @@ Sample Output Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `Hello Reshape SSD Python Sample on Github `__ - `Hello Reshape SSD C++ Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/image-classification-async.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/image-classification-async.rst similarity index 95% rename from docs/articles_en/learn-openvino/openvino-samples/image-classification-async.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/image-classification-async.rst index d88b950463210d..96fc49c2f08645 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/image-classification-async.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/image-classification-async.rst @@ -56,7 +56,7 @@ You can place labels in ``.labels`` file near the model to get pretty output. You can see the explicit description of each sample step at -:doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +:doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. @@ -129,9 +129,9 @@ To run the sample, you need to specify a model and an image: .. note:: - - By default, OpenVINO™ Toolkit Samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using model conversion API with ``reverse_input_channels`` argument specified. For more information about the argument, refer to the **Color Conversion** section of :doc:`Preprocessing API <../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. + - By default, OpenVINO™ Toolkit Samples and demos expect input with BGR channels order. If you trained your model to work with RGB order, you need to manually rearrange the default channels order in the sample or demo application or reconvert your model using model conversion API with ``reverse_input_channels`` argument specified. For more information about the argument, refer to the **Color Conversion** section of :doc:`Preprocessing API <../../../openvino-workflow/running-inference/optimize-inference/optimize-preprocessing/preprocessing-api-details>`. - - Before running the sample with a trained model, make sure the model is converted to the intermediate representation (IR) format (\*.xml + \*.bin) using :doc:`model conversion API <../../openvino-workflow/model-preparation/convert-model-to-ir>`. + - Before running the sample with a trained model, make sure the model is converted to the intermediate representation (IR) format (\*.xml + \*.bin) using :doc:`model conversion API <../../../openvino-workflow/model-preparation/convert-model-to-ir>`. - The sample accepts models in ONNX format (.onnx) that do not require preprocessing. @@ -323,9 +323,9 @@ Sample Output Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO™ Toolkit Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `Image Classification Async Python Sample on Github `__ - `Image Classification Async C++ Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/model-creation.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/model-creation.rst similarity index 92% rename from docs/articles_en/learn-openvino/openvino-samples/model-creation.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/model-creation.rst index ad01cee53a69b1..87853f5bbf15a2 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/model-creation.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/model-creation.rst @@ -8,7 +8,7 @@ Model Creation Sample Inference Request API (Python, C++). -This sample demonstrates how to run inference using a :doc:`model <../../openvino-workflow/running-inference/integrate-openvino-with-your-application/model-representation>` +This sample demonstrates how to run inference using a :doc:`model <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application/model-representation>` built on the fly that uses weights from the LeNet classification model, which is known to work well on digit classification tasks. You do not need an XML file, the model is created from the source code on the fly. Before using the sample, @@ -23,7 +23,7 @@ refer to the following requirements: How It Works #################### -At startup, the sample application reads command-line parameters, :doc:`builds a model <../../openvino-workflow/running-inference/integrate-openvino-with-your-application/model-representation>` +At startup, the sample application reads command-line parameters, :doc:`builds a model <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application/model-representation>` and passes the weights file. Then, it loads the model and input data to the OpenVINO™ Runtime plugin. Finally, it performs synchronous inference and processes output data, logging each step in a standard output stream. @@ -47,7 +47,7 @@ data, logging each step in a standard output stream. :language: cpp -You can see the explicit description of each sample step at :doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. +You can see the explicit description of each sample step at :doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. Running #################### @@ -76,7 +76,7 @@ To run the sample, you need to specify model weights and a device. - This sample supports models with FP32 weights only. - The ``lenet.bin`` weights file is generated by - :doc:`model conversion API <../../openvino-workflow/model-preparation/convert-model-to-ir>` + :doc:`model conversion API <../../../openvino-workflow/model-preparation/convert-model-to-ir>` from the public LeNet model, with the ``input_shape [64,1,28,28]`` parameter specified. - The original model is available in the `Caffe repository `__ on GitHub. @@ -289,9 +289,9 @@ Sample Output Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `Model Creation Python Sample on Github `__ - `Model Creation C++ Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/sync-benchmark.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/sync-benchmark.rst similarity index 93% rename from docs/articles_en/learn-openvino/openvino-samples/sync-benchmark.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/sync-benchmark.rst index ccaa1f03a35552..f9643855dfd91d 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/sync-benchmark.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/sync-benchmark.rst @@ -45,7 +45,7 @@ Then, it processes and reports performance results. You can see the explicit description of -each sample step at :doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +each sample step at :doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. Running @@ -162,9 +162,9 @@ Sample Output Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `Sync Benchmark Python Sample on Github `__ - `Sync Benchmark C++ Sample on Github `__ diff --git a/docs/articles_en/learn-openvino/openvino-samples/throughput-benchmark.rst b/docs/articles_en/get-started/learn-openvino/openvino-samples/throughput-benchmark.rst similarity index 94% rename from docs/articles_en/learn-openvino/openvino-samples/throughput-benchmark.rst rename to docs/articles_en/get-started/learn-openvino/openvino-samples/throughput-benchmark.rst index 4632fab82bd0ea..8baabc49998482 100644 --- a/docs/articles_en/learn-openvino/openvino-samples/throughput-benchmark.rst +++ b/docs/articles_en/get-started/learn-openvino/openvino-samples/throughput-benchmark.rst @@ -49,7 +49,7 @@ Then, it processes and reports performance results. You can see the explicit description of each sample step at -:doc:`Integration Steps <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +:doc:`Integration Steps <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` section of "Integrate OpenVINO™ Runtime with Your Application" guide. Running @@ -167,9 +167,9 @@ Sample Output Additional Resources #################### -- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` +- :doc:`Integrate the OpenVINO™ Runtime with Your Application <../../../openvino-workflow/running-inference/integrate-openvino-with-your-application>` - :doc:`Get Started with Samples ` - :doc:`Using OpenVINO Samples <../openvino-samples>` -- :doc:`Convert a Model <../../openvino-workflow/model-preparation/convert-model-to-ir>` +- :doc:`Convert a Model <../../../openvino-workflow/model-preparation/convert-model-to-ir>` - `Throughput Benchmark Python Sample on Github `__ - `Throughput Benchmark C++ Sample on Github `__ diff --git a/docs/articles_en/openvino-workflow/model-preparation/convert-model-onnx.rst b/docs/articles_en/openvino-workflow/model-preparation/convert-model-onnx.rst index 9d1f0a3e0d754a..e2a968f7107630 100644 --- a/docs/articles_en/openvino-workflow/model-preparation/convert-model-onnx.rst +++ b/docs/articles_en/openvino-workflow/model-preparation/convert-model-onnx.rst @@ -69,5 +69,5 @@ Additional Resources #################### Check out more examples of model conversion in -:doc:`interactive Python tutorials <../../learn-openvino/interactive-tutorials-python>`. +:doc:`interactive Python tutorials <../../get-started/learn-openvino/interactive-tutorials-python>`. diff --git a/docs/articles_en/openvino-workflow/model-preparation/convert-model-paddle.rst b/docs/articles_en/openvino-workflow/model-preparation/convert-model-paddle.rst index b91af11c012566..2808a18e6759e2 100644 --- a/docs/articles_en/openvino-workflow/model-preparation/convert-model-paddle.rst +++ b/docs/articles_en/openvino-workflow/model-preparation/convert-model-paddle.rst @@ -160,5 +160,5 @@ Additional Resources #################### Check out more examples of model conversion in -:doc:`interactive Python tutorials <../../learn-openvino/interactive-tutorials-python>`. +:doc:`interactive Python tutorials <../../get-started/learn-openvino/interactive-tutorials-python>`. diff --git a/docs/articles_en/openvino-workflow/model-preparation/convert-model-pytorch.rst b/docs/articles_en/openvino-workflow/model-preparation/convert-model-pytorch.rst index fa1b6b733bb548..9a00aee059f6d2 100644 --- a/docs/articles_en/openvino-workflow/model-preparation/convert-model-pytorch.rst +++ b/docs/articles_en/openvino-workflow/model-preparation/convert-model-pytorch.rst @@ -97,7 +97,7 @@ inference in the existing PyTorch application to OpenVINO and how to get value f category_name = weights.meta["categories"][class_id] print(f"{category_name}: {100 * score:.1f}% (with OpenVINO)") -Check out more examples in :doc:`interactive Python tutorials <../../learn-openvino/interactive-tutorials-python>`. +Check out more examples in :doc:`interactive Python tutorials <../../get-started/learn-openvino/interactive-tutorials-python>`. .. note:: diff --git a/docs/articles_en/openvino-workflow/running-inference/changing-input-shape.rst b/docs/articles_en/openvino-workflow/running-inference/changing-input-shape.rst index 3daf95ccb2cc18..423f9c01dc0cbe 100644 --- a/docs/articles_en/openvino-workflow/running-inference/changing-input-shape.rst +++ b/docs/articles_en/openvino-workflow/running-inference/changing-input-shape.rst @@ -151,7 +151,7 @@ When using the ``reshape`` method, you may take one of the approaches: You can find the usage scenarios of the ``reshape`` method in -:doc:`Hello Reshape SSD Samples <../../learn-openvino/openvino-samples/hello-reshape-ssd>`. +:doc:`Hello Reshape SSD Samples <../../get-started/learn-openvino/openvino-samples/hello-reshape-ssd>`. .. note:: @@ -209,6 +209,6 @@ Additional Resources * `ov::Model::reshape `__ - in OpenVINO Runtime C++ API * `Model.reshape `__ - in OpenVINO Runtime Python API. * :doc:`Dynamic Shapes ` -* :doc:`OpenVINO samples <../../learn-openvino/openvino-samples>` +* :doc:`OpenVINO samples <../../get-started/learn-openvino/openvino-samples>` * :doc:`Preprocessing API ` diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes.rst index 31d0af303c633a..2d560b343c3b26 100644 --- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes.rst +++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes.rst @@ -54,7 +54,7 @@ as an example): Device: GPU.1 -You may see how to obtain this information in the :doc:`Hello Query Device Sample <../../learn-openvino/openvino-samples/hello-query-device>`. +You may see how to obtain this information in the :doc:`Hello Query Device Sample <../../get-started/learn-openvino/openvino-samples/hello-query-device>`. Here is an example of a simple programmatic way to enumerate the devices and use them with the multi-device mode: diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection.rst index a5ab0c845dfa66..539ed84edb120e 100644 --- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection.rst +++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection.rst @@ -314,7 +314,7 @@ asynchronous inference pipeline. For information on asynchronous inference, see :doc:`Async API documentation <../integrate-openvino-with-your-application/inference-request>` . The following notebooks provide examples of how to set up an asynchronous pipeline: -* :doc:`Image Classification Async Sample <../../../learn-openvino/openvino-samples/image-classification-async>` +* :doc:`Image Classification Async Sample <../../../get-started/learn-openvino/openvino-samples/image-classification-async>` * `Notebook - Asynchronous Inference with OpenVINO™ <./../../../notebooks/async-api-with-output.html>`__ * `Notebook - Automatic Device Selection with OpenVINO <./../../../notebooks/auto-device-with-output.html>`__ @@ -497,7 +497,7 @@ For limited device choice: benchmark_app –d AUTO:CPU,GPU –m -i -niter 1000 -For more information, refer to the :doc:`Benchmark Tool <../../../learn-openvino/openvino-samples/benchmark-tool>` article. +For more information, refer to the :doc:`Benchmark Tool <../../../get-started/learn-openvino/openvino-samples/benchmark-tool>` article. .. note:: diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/automatic-batching.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/automatic-batching.rst index 61e157cf31fc5d..8882be2220acb6 100644 --- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/automatic-batching.rst +++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/automatic-batching.rst @@ -208,7 +208,7 @@ The following are limitations of the current AUTO Batching implementations: Testing Performance with Benchmark_app ###################################### -Using the :doc:`benchmark_app sample <../../../learn-openvino/openvino-samples/benchmark-tool>` is the best way to evaluate the performance of Automatic Batching: +Using the :doc:`benchmark_app sample <../../../get-started/learn-openvino/openvino-samples/benchmark-tool>` is the best way to evaluate the performance of Automatic Batching: - The most straightforward way is using the performance hints: diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/cpu-device.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/cpu-device.rst index 00fd19dd404b11..0b0c610da17335 100644 --- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/cpu-device.rst +++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/cpu-device.rst @@ -75,7 +75,7 @@ CPU plugin supports the following data types as inference precision of internal - ``INT8`` (Intel® x86-64) - ``uINT1`` (Intel® x86-64) -:doc:`Hello Query Device C++ Sample <../../../learn-openvino/openvino-samples/hello-query-device>` can be used to print out supported data types for all detected devices. +:doc:`Hello Query Device C++ Sample <../../../get-started/learn-openvino/openvino-samples/hello-query-device>` can be used to print out supported data types for all detected devices. Quantized Data Types Specifics diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/gpu-device.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/gpu-device.rst index cb39fe7cb7dcac..4b2915333249ce 100644 --- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/gpu-device.rst +++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/gpu-device.rst @@ -33,7 +33,7 @@ Device Naming Convention * If the system does not have an integrated GPU, devices are enumerated, starting from 0. * For GPUs with multi-tile architecture (multiple sub-devices in OpenCL terms), a specific tile may be addressed as ``GPU.X.Y``, where ``X,Y={0, 1, 2,...}``, ``X`` - id of the GPU device, ``Y`` - id of the tile within device ``X`` -For demonstration purposes, see the :doc:`Hello Query Device C++ Sample <../../../learn-openvino/openvino-samples/hello-query-device>` that can print out the list of available devices with associated indices. Below is an example output (truncated to the device names only): +For demonstration purposes, see the :doc:`Hello Query Device C++ Sample <../../../get-started/learn-openvino/openvino-samples/hello-query-device>` that can print out the list of available devices with associated indices. Below is an example output (truncated to the device names only): .. code-block:: sh @@ -131,7 +131,7 @@ Floating-point precision of a GPU primitive is selected based on operation preci The newer generation Intel Iris Xe and Xe MAX GPUs provide accelerated performance for i8/u8 models. Hardware acceleration for ``i8``/``u8`` precision may be unavailable on older generation platforms. In such cases, a model is executed in the floating-point precision taken from IR. Hardware support of ``u8``/``i8`` acceleration can be queried via the ``ov::device::capabilities`` property. -:doc:`Hello Query Device C++ Sample <../../../learn-openvino/openvino-samples/hello-query-device>` can be used to print out the supported data types for all detected devices. +:doc:`Hello Query Device C++ Sample <../../../get-started/learn-openvino/openvino-samples/hello-query-device>` can be used to print out the supported data types for all detected devices. Supported Features diff --git a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/query-device-properties.rst b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/query-device-properties.rst index a704833b374f19..5a634799783df9 100644 --- a/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/query-device-properties.rst +++ b/docs/articles_en/openvino-workflow/running-inference/inference-devices-and-modes/query-device-properties.rst @@ -31,7 +31,7 @@ of ``ov::available_devices``, the string name of ``AVAILABLE_DEVICES`` and the t static constexpr Property, PropertyMutability::RO> available_devices{"AVAILABLE_DEVICES"}; -Refer to the :doc:`Hello Query Device C++ Sample <../../../learn-openvino/openvino-samples/hello-query-device>` +Refer to the :doc:`Hello Query Device C++ Sample <../../../get-started/learn-openvino/openvino-samples/hello-query-device>` sources for an example of using the setting and getting properties in user applications. diff --git a/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application.rst b/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application.rst index d3d5b0cce92d89..8381112683b52f 100644 --- a/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application.rst +++ b/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application.rst @@ -415,10 +415,10 @@ For details on additional CMake build options, refer to the `CMake page `__ -* See the :doc:`OpenVINO Samples <../../learn-openvino/openvino-samples>` page for specific examples of how OpenVINO pipelines are implemented for applications like image classification, text prediction, and many others. +* See the :doc:`OpenVINO Samples <../../get-started/learn-openvino/openvino-samples>` page for specific examples of how OpenVINO pipelines are implemented for applications like image classification, text prediction, and many others. * Models in the OpenVINO IR format on `Hugging Face `__. * :doc:`OpenVINO™ Runtime Preprocessing ` * :doc:`String Tensors ` diff --git a/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application/inference-request.rst b/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application/inference-request.rst index e8ffda10f035d1..93baeff1e13674 100644 --- a/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application/inference-request.rst +++ b/docs/articles_en/openvino-workflow/running-inference/integrate-openvino-with-your-application/inference-request.rst @@ -154,7 +154,7 @@ When you are running several inference requests in parallel, a device can proces Use weak reference of infer_request (``ov::InferRequest*``, ``ov::InferRequest&``, ``std::weal_ptr``, etc.) in the callback. It is necessary to avoid cyclic references. -For more details, see the :doc:`Classification Async Sample <../../../learn-openvino/openvino-samples/image-classification-async>`. +For more details, see the :doc:`Classification Async Sample <../../../get-started/learn-openvino/openvino-samples/image-classification-async>`. You can use the ``ov::InferRequest::cancel`` method if you want to abort execution of the current inference request: diff --git a/docs/articles_en/openvino-workflow/running-inference/optimize-inference/general-optimizations.rst b/docs/articles_en/openvino-workflow/running-inference/optimize-inference/general-optimizations.rst index 5f01623d248755..af6ea2814a0384 100644 --- a/docs/articles_en/openvino-workflow/running-inference/optimize-inference/general-optimizations.rst +++ b/docs/articles_en/openvino-workflow/running-inference/optimize-inference/general-optimizations.rst @@ -60,7 +60,7 @@ Below are example-codes for the regular and async-based approaches to compare: The technique can be generalized to any available parallel slack. For example, you can do inference and simultaneously encode the resulting or previous frames or run further inference, like emotion detection on top of the face detection results. -Refer to the :doc:`Benchmark App Sample <../../../learn-openvino/openvino-samples/benchmark-tool>` for complete examples of the Async API in action. +Refer to the :doc:`Benchmark App Sample <../../../get-started/learn-openvino/openvino-samples/benchmark-tool>` for complete examples of the Async API in action. .. note:: diff --git a/docs/articles_en/openvino-workflow/running-inference/optimize-inference/high-level-performance-hints.rst b/docs/articles_en/openvino-workflow/running-inference/optimize-inference/high-level-performance-hints.rst index e45f51a37afa5e..90fe7dc8b98bee 100644 --- a/docs/articles_en/openvino-workflow/running-inference/optimize-inference/high-level-performance-hints.rst +++ b/docs/articles_en/openvino-workflow/running-inference/optimize-inference/high-level-performance-hints.rst @@ -158,7 +158,7 @@ For example, use ``ov::hint::PerformanceMode::THROUGHPUT`` to prepare a general Testing Performance of the Hints with the Benchmark_App ####################################################### -Using the :doc:`benchmark_app sample <../../../learn-openvino/openvino-samples/benchmark-tool>` is the best way to evaluate the functionality of the performance hints for a particular device: +Using the :doc:`benchmark_app sample <../../../get-started/learn-openvino/openvino-samples/benchmark-tool>` is the best way to evaluate the functionality of the performance hints for a particular device: * benchmark_app **-hint tput** -d 'device' -m 'path to your model' * benchmark_app **-hint latency** -d 'device' -m 'path to your model' diff --git a/docs/nbdoc/nbdoc.py b/docs/nbdoc/nbdoc.py index 63ce0c9e150462..d93566d3e96dee 100644 --- a/docs/nbdoc/nbdoc.py +++ b/docs/nbdoc/nbdoc.py @@ -140,7 +140,7 @@ def main(): sourcedir = args.sourcedir outdir = args.outdir - main_tutorials_file = Path('../../docs/articles_en/learn-openvino/interactive-tutorials-python.rst').resolve(strict=True) + main_tutorials_file = Path('../../docs/articles_en/get-started/learn-openvino/interactive-tutorials-python.rst').resolve(strict=True) add_glob_directive(main_tutorials_file) shutil.copytree(sourcedir, outdir) # Run processing on downloaded files in notebooks directory diff --git a/docs/notebooks/3D-segmentation-point-clouds-with-output.rst b/docs/notebooks/3D-segmentation-point-clouds-with-output.rst index 5afd5c5a91cffe..3cbf4dcea101c6 100644 --- a/docs/notebooks/3D-segmentation-point-clouds-with-output.rst +++ b/docs/notebooks/3D-segmentation-point-clouds-with-output.rst @@ -66,15 +66,15 @@ Imports import numpy as np import matplotlib.pyplot as plt import openvino as ov - + # Fetch `notebook_utils` module import requests - + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) open("notebook_utils.py", "w").write(r.text) - + from notebook_utils import download_file, device_widget Prepare the Model @@ -108,14 +108,14 @@ function returns an OpenVINO model ready to load on a device and start making predictions. We can save it on a disk for next usage with ``ov.save_model``. For more information about model conversion Python API, see this -`page `__. +`page `__. .. code:: ipython3 ir_model_xml = onnx_model_path.with_suffix(".xml") - + core = ov.Core() - + if not ir_model_xml.exists(): # Convert model to OpenVINO Model model = ov.convert_model(onnx_model_path) @@ -135,37 +135,37 @@ Data Processing Module def load_data(point_file: Union[str, Path]): """ Load the point cloud data and convert it to ndarray - + Parameters: point_file: string, path of .pts data Returns: point_set: point clound represented in np.array format """ - + point_set = np.loadtxt(point_file).astype(np.float32) - + # normailization point_set = point_set - np.expand_dims(np.mean(point_set, axis=0), 0) # center dist = np.max(np.sqrt(np.sum(point_set**2, axis=1)), 0) point_set = point_set / dist # scale - + return point_set - - + + def visualize(point_set: np.ndarray): """ Create a 3D view for data visualization - + Parameters: point_set: np.ndarray, the coordinate data in X Y Z format """ - + fig = plt.figure(dpi=192, figsize=(4, 4)) ax = fig.add_subplot(111, projection="3d") X = point_set[:, 0] Y = point_set[:, 2] Z = point_set[:, 1] - + # Scale the view of each axis to adapt to the coordinate data distribution max_range = np.array([X.max() - X.min(), Y.max() - Y.min(), Z.max() - Z.min()]).max() * 0.5 mid_x = (X.max() + X.min()) * 0.5 @@ -174,12 +174,12 @@ Data Processing Module ax.set_xlim(mid_x - max_range, mid_x + max_range) ax.set_ylim(mid_y - max_range, mid_y + max_range) ax.set_zlim(mid_z - max_range, mid_z + max_range) - + plt.tick_params(labelsize=5) ax.set_xlabel("X", fontsize=10) ax.set_ylabel("Y", fontsize=10) ax.set_zlabel("Z", fontsize=10) - + return ax Visualize the original 3D data @@ -199,7 +199,7 @@ chair for example. "https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/pts/chair.pts", directory="data", ) - + points = load_data(str(point_data)) X = points[:, 0] Y = points[:, 2] @@ -242,11 +242,11 @@ each input point. # Parts of a chair classes = ["back", "seat", "leg", "arm"] - + # Preprocess the input data point = points.transpose(1, 0) point = np.expand_dims(point, axis=0) - + # Print info about model input and output shape print(f"input shape: {model.input(0).partial_shape}") print(f"output shape: {model.output(0).partial_shape}") @@ -268,7 +268,7 @@ select device from dropdown list for running inference using OpenVINO .. code:: ipython3 device = device_widget() - + device @@ -286,7 +286,7 @@ select device from dropdown list for running inference using OpenVINO compiled_model = core.compile_model(model=model, device_name=device.value) output_layer = compiled_model.output(0) result = compiled_model([point])[output_layer] - + # Find the label map for all points of chair with highest confidence pred = np.argmax(result[0], axis=1) ax = visualize(point) @@ -302,10 +302,10 @@ select device from dropdown list for running inference using OpenVINO XCur = np.array(XCur) YCur = np.array(YCur) ZCur = np.array(ZCur) - + # add current point of the part ax.scatter(XCur, YCur, ZCur, s=5, cmap="jet", marker="o", label=classes[i]) - + ax.set_title("3D Segmentation Visualization") plt.legend(loc="upper right", fontsize=8) plt.show() diff --git a/docs/notebooks/async-api-with-output.rst b/docs/notebooks/async-api-with-output.rst index 86ff1bc0aa9b0c..3511e46de7b858 100644 --- a/docs/notebooks/async-api-with-output.rst +++ b/docs/notebooks/async-api-with-output.rst @@ -2,7 +2,7 @@ Asynchronous Inference with OpenVINO™ ===================================== This notebook demonstrates how to use the `Async -API `__ +API `__ for asynchronous execution with OpenVINO. OpenVINO Runtime supports inference in either synchronous or @@ -76,15 +76,15 @@ Imports import openvino as ov from IPython import display import matplotlib.pyplot as plt - + # Fetch the notebook utils script from the openvino_notebooks repo import requests - + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) open("notebook_utils.py", "w").write(r.text) - + import notebook_utils as utils Prepare model and data processing @@ -105,17 +105,17 @@ the person in each frame of the video. .. code:: ipython3 from pathlib import Path - + # directory where model will be downloaded base_model_dir = "model" - + # model name as named in Open Model Zoo model_name = "person-detection-0202" precision = "FP16" model_path = Path("model") / f"{model_name}.xml" - + base_model_url = "https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1" - + if not Path(model_path).exists(): utils.download_file(f"{base_model_url}/{model_name}/{precision}/{model_name}.xml", filename=model_path.name, directory=model_path.parent) utils.download_file( @@ -143,7 +143,7 @@ Select inference device .. code:: ipython3 device = utils.device_widget(default="CPU") - + device @@ -164,14 +164,14 @@ Load the model # initialize OpenVINO runtime core = ov.Core() - + # read the network and corresponding weights from file model = core.read_model(model=model_path) - + # compile the model for the CPU (you can choose manually CPU, GPU etc.) # or let the engine choose the best available device (AUTO) compiled_model = core.compile_model(model=model, device_name=device.value) - + # get input node input_layer_ir = model.input(0) N, C, H, W = input_layer_ir.shape @@ -187,7 +187,7 @@ Create functions for data processing def preprocess(image): """ Define the preprocess function for input data - + :param: image: the orignal input frame :returns: resized_image: the image processed @@ -197,12 +197,12 @@ Create functions for data processing resized_image = resized_image.transpose((2, 0, 1)) resized_image = np.expand_dims(resized_image, axis=0).astype(np.float32) return resized_image - - + + def postprocess(result, image, fps): """ Define the postprocess function for output data - + :param: result: the inference results image: the orignal input frame fps: average throughput calculated for each frame @@ -287,7 +287,7 @@ immediately processed: def sync_api(source, flip, fps, use_popup, skip_first_frames): """ Define the main function for video processing in sync mode - + :param: source: the video path or the ID of your webcam :returns: sync_fps: the inference throughput in sync mode @@ -410,7 +410,7 @@ pipeline (decoding vs inference) and not by the sum of the stages. def async_api(source, flip, fps, use_popup, skip_first_frames): """ Define the main function for video processing in async mode - + :param: source: the video path or the ID of your webcam :returns: async_fps: the inference throughput in async mode @@ -517,20 +517,20 @@ Compare the performance width = 0.4 fontsize = 14 - + plt.rc("font", size=fontsize) fig, ax = plt.subplots(1, 1, figsize=(10, 8)) - + rects1 = ax.bar([0], sync_fps, width, color="#557f2d") rects2 = ax.bar([width], async_fps, width) ax.set_ylabel("frames per second") ax.set_xticks([0, width]) ax.set_xticklabels(["Sync mode", "Async mode"]) ax.set_xlabel("Higher is better") - + fig.suptitle("Sync mode VS Async mode") fig.tight_layout() - + plt.show() @@ -544,7 +544,7 @@ Compare the performance Asynchronous mode pipelines can be supported with the -`AsyncInferQueue `__ +`AsyncInferQueue `__ wrapper class. This class automatically spawns the pool of ``InferRequest`` objects (also called “jobs”) and provides synchronization mechanisms to control the flow of the pipeline. It is a @@ -566,7 +566,7 @@ the possibility of passing runtime values. def callback(infer_request, info) -> None: """ Define the callback function for postprocessing - + :param: infer_request: the infer_request object info: a tuple includes original frame and starts time :returns: @@ -580,7 +580,7 @@ the possibility of passing runtime values. total_time = stop_time - start_time frame_number = frame_number + 1 inferqueue_fps = frame_number / total_time - + res = infer_request.get_output_tensor(0).data[0] frame = postprocess(res, frame, inferqueue_fps) # Encode numpy array to jpg @@ -596,7 +596,7 @@ the possibility of passing runtime values. def inferqueue(source, flip, fps, skip_first_frames) -> None: """ Define the main function for video processing with async infer queue - + :param: source: the video path or the ID of your webcam :retuns: None diff --git a/docs/notebooks/auto-device-with-output.rst b/docs/notebooks/auto-device-with-output.rst index aecc81950051d5..7991375e1f8b8d 100644 --- a/docs/notebooks/auto-device-with-output.rst +++ b/docs/notebooks/auto-device-with-output.rst @@ -2,7 +2,7 @@ Automatic Device Selection with OpenVINO™ ========================================= The `Auto -device `__ +device `__ (or AUTO in short) selects the most suitable device for inference by considering the model precision, power efficiency and processing capability of the available `compute @@ -13,8 +13,8 @@ network efficiently. Next, if dedicated accelerators are available, these devices are preferred (for example, integrated and discrete -`GPU `__). -`CPU `__ +`GPU `__). +`CPU `__ is used as the default “fallback device”. Keep in mind that AUTO makes this selection only once, during the loading of a model. @@ -80,10 +80,10 @@ Import modules and create Core .. code:: ipython3 import platform - + # Install required packages %pip install -q "openvino>=2023.1.0" "matplotlib>=3.4" Pillow torch torchvision tqdm --extra-index-url https://download.pytorch.org/whl/cpu - + if platform.system() == "Darwin": %pip install -q "numpy<2.0.0" @@ -97,13 +97,13 @@ Import modules and create Core import time import sys - + import openvino as ov - + from IPython.display import Markdown, display - + core = ov.Core() - + if not any("GPU" in device for device in core.available_devices): display( Markdown( @@ -141,17 +141,17 @@ with ``ov.compile_model`` or serialized for next usage with ``ov.save_model``. For more information about model conversion API, see this -`page `__. +`page `__. .. code:: ipython3 import torchvision from pathlib import Path - + base_model_dir = Path("./model") base_model_dir.mkdir(exist_ok=True) model_path = base_model_dir / "resnet50.xml" - + if not model_path.exists(): pt_model = torchvision.models.resnet50(weights="DEFAULT") ov_model = ov.convert_model(pt_model, input=[[1, 3, 224, 224]]) @@ -183,14 +183,14 @@ By default, ``compile_model`` API will select **AUTO** as .. code:: ipython3 import openvino.properties.log as log - - + + # Set LOG_LEVEL to LOG_INFO. core.set_property("AUTO", {log.level(): log.Level.INFO}) - + # Load the model onto the target device. compiled_model = core.compile_model(ov_model) - + if isinstance(compiled_model, ov.CompiledModel): print("Successfully compiled model without a device_name.") @@ -235,9 +235,9 @@ improve readability of your code. # Set LOG_LEVEL to LOG_NONE. core.set_property("AUTO", {log.level(): log.Level.NO}) - + compiled_model = core.compile_model(model=ov_model, device_name="AUTO") - + if isinstance(compiled_model, ov.CompiledModel): print("Successfully compiled model using AUTO.") @@ -287,25 +287,25 @@ function, we will reuse it for preparing input data. # Fetch `notebook_utils` module import requests - + r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py") open("notebook_utils.py", "w").write(r.text) - + from notebook_utils import download_file .. code:: ipython3 from PIL import Image - + # Download the image from the openvino_notebooks storage image_filename = download_file( "https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/coco.jpg", directory="data", ) - + image = Image.open(str(image_filename)) input_transform = torchvision.models.ResNet50_Weights.DEFAULT.transforms() - + input_tensor = input_transform(image) input_tensor = input_tensor.unsqueeze(0).numpy() image @@ -336,10 +336,10 @@ Load the model to GPU device and perform inference # Start time. gpu_load_start_time = time.perf_counter() compiled_model = core.compile_model(model=ov_model, device_name="GPU") # load to GPU - + # Execute the first inference. results = compiled_model(input_tensor)[0] - + # Measure time to the first inference. gpu_fil_end_time = time.perf_counter() gpu_fil_span = gpu_fil_end_time - gpu_load_start_time @@ -365,11 +365,11 @@ executed on CPU until GPU is ready. # Start time. auto_load_start_time = time.perf_counter() compiled_model = core.compile_model(model=ov_model) # The device_name is AUTO by default. - + # Execute the first inference. results = compiled_model(input_tensor)[0] - - + + # Measure time to the first inference. auto_fil_end_time = time.perf_counter() auto_fil_span = auto_fil_end_time - auto_load_start_time @@ -401,9 +401,9 @@ completely portable between devices – meaning AUTO can configure the performance hint on whichever device is being used. For more information, refer to the `Performance -Hints `__ +Hints `__ section of `Automatic Device -Selection `__ +Selection `__ article. Class and callback definition @@ -422,7 +422,7 @@ Class and callback definition :member: latency_list: Record the latency of each inference execution over @interval seconds duration. :member: interval: The metrics will be updated every @interval seconds """ - + def __init__(self, interval): """ Create and initilize one instance of class PerformanceMetrics. @@ -432,11 +432,11 @@ Class and callback definition """ self.fps = 0 self.latency = 0 - + self.start_time = time.perf_counter() self.latency_list = [] self.interval = interval - + def update(self, infer_request: ov.InferRequest) -> bool: """ Update the metrics if current ongoing @interval seconds duration is expired. Record the latency only if it is not expired. @@ -458,8 +458,8 @@ Class and callback definition return True else: return False - - + + class InferContext: """ Inference context. Record and update peforamnce metrics via @metrics, set @feed_inference to False once @remaining_update_num <=0 @@ -467,7 +467,7 @@ Class and callback definition :member: remaining_update_num: the remaining times for peforamnce metrics updating. :member: feed_inference: if feed inference request is required or not. """ - + def __init__(self, update_interval, num): """ Create and initilize one instance of class InferContext. @@ -479,7 +479,7 @@ Class and callback definition self.metrics = PerformanceMetrics(update_interval) self.remaining_update_num = num self.feed_inference = True - + def update(self, infer_request: ov.InferRequest): """ Update the context. Set @feed_inference to False if the number of remaining performance metric updates (@remaining_update_num) reaches 0 @@ -488,13 +488,13 @@ Class and callback definition """ if self.remaining_update_num <= 0: self.feed_inference = False - + if self.metrics.update(infer_request): self.remaining_update_num = self.remaining_update_num - 1 if self.remaining_update_num <= 0: self.feed_inference = False - - + + def completion_callback(infer_request: ov.InferRequest, context) -> None: """ callback for the inference request, pass the @infer_request to @context for updating @@ -503,8 +503,8 @@ Class and callback definition :returns: None """ context.update(infer_request) - - + + # Performance metrics update interval (seconds) and number of times. metrics_update_interval = 10 metrics_update_num = 6 @@ -520,32 +520,32 @@ Loop for inference and update the FPS/Latency every .. code:: ipython3 import openvino.properties.hint as hints - - + + THROUGHPUT_hint_context = InferContext(metrics_update_interval, metrics_update_num) - + print("Compiling Model for AUTO device with THROUGHPUT hint") sys.stdout.flush() - + compiled_model = core.compile_model(model=ov_model, config={hints.performance_mode(): hints.PerformanceMode.THROUGHPUT}) - + infer_queue = ov.AsyncInferQueue(compiled_model, 0) # Setting to 0 will query optimal number by default. infer_queue.set_callback(completion_callback) - + print(f"Start inference, {metrics_update_num: .0f} groups of FPS/latency will be measured over {metrics_update_interval: .0f}s intervals") sys.stdout.flush() - + while THROUGHPUT_hint_context.feed_inference: infer_queue.start_async(input_tensor, THROUGHPUT_hint_context) - + infer_queue.wait_all() - + # Take the FPS and latency of the latest period. THROUGHPUT_hint_fps = THROUGHPUT_hint_context.metrics.fps THROUGHPUT_hint_latency = THROUGHPUT_hint_context.metrics.latency - + print("Done") - + del compiled_model @@ -573,30 +573,30 @@ Loop for inference and update the FPS/Latency for each .. code:: ipython3 LATENCY_hint_context = InferContext(metrics_update_interval, metrics_update_num) - + print("Compiling Model for AUTO Device with LATENCY hint") sys.stdout.flush() - + compiled_model = core.compile_model(model=ov_model, config={hints.performance_mode(): hints.PerformanceMode.LATENCY}) - + # Setting to 0 will query optimal number by default. infer_queue = ov.AsyncInferQueue(compiled_model, 0) infer_queue.set_callback(completion_callback) - + print(f"Start inference, {metrics_update_num: .0f} groups fps/latency will be out with {metrics_update_interval: .0f}s interval") sys.stdout.flush() - + while LATENCY_hint_context.feed_inference: infer_queue.start_async(input_tensor, LATENCY_hint_context) - + infer_queue.wait_all() - + # Take the FPS and latency of the latest period. LATENCY_hint_fps = LATENCY_hint_context.metrics.fps LATENCY_hint_latency = LATENCY_hint_context.metrics.latency - + print("Done") - + del compiled_model @@ -621,16 +621,16 @@ Difference in FPS and latency .. code:: ipython3 import matplotlib.pyplot as plt - + TPUT = 0 LAT = 1 labels = ["THROUGHPUT hint", "LATENCY hint"] - + fig1, ax1 = plt.subplots(1, 1) fig1.patch.set_visible(False) ax1.axis("tight") ax1.axis("off") - + cell_text = [] cell_text.append( [ @@ -639,7 +639,7 @@ Difference in FPS and latency ] ) cell_text.append(["%.2f%s" % (LATENCY_hint_fps, " FPS"), "%.2f%s" % (LATENCY_hint_latency, " ms")]) - + table = ax1.table( cellText=cell_text, colLabels=["FPS (Higher is better)", "Latency (Lower is better)"], @@ -654,7 +654,7 @@ Difference in FPS and latency table.auto_set_column_width(0) table.auto_set_column_width(1) table.scale(1, 3) - + fig1.tight_layout() plt.show() @@ -668,28 +668,28 @@ Difference in FPS and latency # Output the difference. width = 0.4 fontsize = 14 - + plt.rc("font", size=fontsize) fig, ax = plt.subplots(1, 2, figsize=(10, 8)) - + rects1 = ax[0].bar([0], THROUGHPUT_hint_fps, width, label=labels[TPUT], color="#557f2d") rects2 = ax[0].bar([width], LATENCY_hint_fps, width, label=labels[LAT]) ax[0].set_ylabel("frames per second") ax[0].set_xticks([width / 2]) ax[0].set_xticklabels(["FPS"]) ax[0].set_xlabel("Higher is better") - + rects1 = ax[1].bar([0], THROUGHPUT_hint_latency, width, label=labels[TPUT], color="#557f2d") rects2 = ax[1].bar([width], LATENCY_hint_latency, width, label=labels[LAT]) ax[1].set_ylabel("milliseconds") ax[1].set_xticks([width / 2]) ax[1].set_xticklabels(["Latency (ms)"]) ax[1].set_xlabel("Lower is better") - + fig.suptitle("Performance Hints") fig.legend(labels, fontsize=fontsize) fig.tight_layout() - + plt.show() diff --git a/docs/notebooks/catvton-with-output.rst b/docs/notebooks/catvton-with-output.rst index 2186b6eb8dba6f..0a591f34239ce3 100644 --- a/docs/notebooks/catvton-with-output.rst +++ b/docs/notebooks/catvton-with-output.rst @@ -73,8 +73,8 @@ Prerequisites .. code:: ipython3 import platform - - + + if platform.system() == "Darwin": %pip install -q "numpy<2.0.0" %pip install -q "openvino>=2024.4" "nncf>=2.13.0" @@ -84,13 +84,13 @@ Prerequisites .. code:: ipython3 import requests - - + + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) open("notebook_utils.py", "w").write(r.text) - + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py", ) @@ -99,8 +99,8 @@ Prerequisites .. code:: ipython3 from cmd_helper import clone_repo - - + + clone_repo("https://github.com/Zheng-Chong/CatVTON.git", "3b795364a4d2f3b5adb365f39cdea376d20bc53c") Convert the model to OpenVINO IR @@ -110,7 +110,7 @@ Convert the model to OpenVINO IR OpenVINO supports PyTorch models via conversion to OpenVINO Intermediate Representation (IR). `OpenVINO model conversion -API `__ +API `__ should be used for these purposes. ``ov.convert_model`` function accepts original PyTorch model instance and example input for tracing and returns ``ov.Model`` representing this model in OpenVINO framework. @@ -138,7 +138,7 @@ version). .. code:: ipython3 from ov_catvton_helper import download_models, convert_pipeline_models, convert_automasker_models - + pipeline, mask_processor, automasker = download_models() vae_scaling_factor = pipeline.vae.config.scaling_factor convert_pipeline_models(pipeline) @@ -154,14 +154,14 @@ Select device from dropdown list for running inference using OpenVINO. .. code:: ipython3 import openvino as ov - + from notebook_utils import device_widget - - + + core = ov.Core() - + device = device_widget() - + device ``get_compiled_pipeline`` and ``get_compiled_automasker`` functions @@ -186,7 +186,7 @@ that all of wrapper classes return ``torch.Tensor``\ s instead of SCHP_PROCESSOR_ATR, SCHP_PROCESSOR_LIP, ) - + pipeline = get_compiled_pipeline(pipeline, core, device, VAE_ENCODER_PATH, VAE_DECODER_PATH, UNET_PATH, vae_scaling_factor) automasker = get_compiled_automasker(automasker, core, device, DENSEPOSE_PROCESSOR_PATH, SCHP_PROCESSOR_ATR, SCHP_PROCESSOR_LIP) @@ -208,9 +208,9 @@ model, and 4-bit weight compression for the remaining models. .. code:: ipython3 from notebook_utils import quantization_widget - + to_quantize = quantization_widget() - + to_quantize Let’s load ``skip magic`` extension to skip quantization if @@ -219,13 +219,13 @@ Let’s load ``skip magic`` extension to skip quantization if .. code:: ipython3 is_optimized_pipe_available = False - + # Fetch skip_kernel_extension module r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py", ) open("skip_kernel_extension.py", "w").write(r.text) - + %load_ext skip_kernel_extension Run Post-Training Quantization @@ -246,10 +246,10 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + from pathlib import Path from catvton_quantization_helper import collect_calibration_data, UNET_INT8_PATH - + dataset = [ ( Path("CatVTON/resource/demo/example/person/men/model_5.png"), @@ -260,7 +260,7 @@ data. Path("CatVTON/resource/demo/example/condition/overall/21744571_51588794_1000.jpg"), ), ] - + if not UNET_INT8_PATH.exists(): subset_size = 100 calibration_data = collect_calibration_data(pipeline, automasker, mask_processor, dataset, subset_size) @@ -268,17 +268,17 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + import gc import nncf from ov_catvton_helper import UNET_PATH - + # cleanup before quantization to free memory del pipeline del automasker gc.collect() - - + + if not UNET_INT8_PATH.exists(): unet = core.read_model(UNET_PATH) quantized_model = nncf.quantize( @@ -304,11 +304,11 @@ applied to footprint reduction. .. code:: ipython3 %%skip not $to_quantize.value - + from catvton_quantization_helper import compress_models - + compress_models(core) - + is_optimized_pipe_available = True Compare model file sizes @@ -320,7 +320,7 @@ Compare model file sizes %%skip not $to_quantize.value from catvton_quantization_helper import compare_models_size - + compare_models_size() @@ -332,7 +332,7 @@ Compare model file sizes densepose_processor compression rate: 2.019 schp_processor_atr compression rate: 1.993 schp_processor_lip compression rate: 1.993 - + Interactive inference --------------------- @@ -345,15 +345,15 @@ to launch the interactive demo. .. code:: ipython3 from ov_catvton_helper import get_pipeline_selection_option - + use_quantized_models = get_pipeline_selection_option(is_optimized_pipe_available) - + use_quantized_models .. code:: ipython3 from gradio_helper import make_demo - + from catvton_quantization_helper import ( VAE_ENCODER_INT4_PATH, VAE_DECODER_INT4_PATH, @@ -362,7 +362,7 @@ to launch the interactive demo. SCHP_PROCESSOR_LIP_INT4, UNET_INT8_PATH, ) - + pipeline, mask_processor, automasker = download_models() if use_quantized_models.value: pipeline = get_compiled_pipeline(pipeline, core, device, VAE_ENCODER_INT4_PATH, VAE_DECODER_INT4_PATH, UNET_INT8_PATH, vae_scaling_factor) @@ -370,7 +370,7 @@ to launch the interactive demo. else: pipeline = get_compiled_pipeline(pipeline, core, device, VAE_ENCODER_PATH, VAE_DECODER_PATH, UNET_PATH, vae_scaling_factor) automasker = get_compiled_automasker(automasker, core, device, DENSEPOSE_PROCESSOR_PATH, SCHP_PROCESSOR_ATR, SCHP_PROCESSOR_LIP) - + output_dir = "output" demo = make_demo(pipeline, mask_processor, automasker, output_dir) try: diff --git a/docs/notebooks/clip-language-saliency-map-with-output.rst b/docs/notebooks/clip-language-saliency-map-with-output.rst index dd6f608429e1c5..7a9a167eac14cf 100644 --- a/docs/notebooks/clip-language-saliency-map-with-output.rst +++ b/docs/notebooks/clip-language-saliency-map-with-output.rst @@ -129,7 +129,7 @@ Initial Implementation with Transformers and Pytorch from pathlib import Path from typing import Tuple, Union, Optional import requests - + from matplotlib import colors import matplotlib.pyplot as plt import numpy as np @@ -137,7 +137,7 @@ Initial Implementation with Transformers and Pytorch import tqdm from PIL import Image from transformers import CLIPModel, CLIPProcessor - + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) @@ -157,7 +157,7 @@ steps. .. code:: ipython3 model_checkpoint = "openai/clip-vit-base-patch16" - + model = CLIPModel.from_pretrained(model_checkpoint).eval() processor = CLIPProcessor.from_pretrained(model_checkpoint) @@ -175,19 +175,19 @@ formula above. x = np.random.randint(image_width - crop_size + 1) y = np.random.randint(image_height - crop_size + 1) return x, y, crop_size - - + + def get_cropped_image(im_tensor: np.array, x: int, y: int, crop_size: int) -> np.array: return im_tensor[y : y + crop_size, x : x + crop_size, ...] - - + + def update_saliency_map(saliency_map: np.array, similarity: float, x: int, y: int, crop_size: int) -> None: saliency_map[ y : y + crop_size, x : x + crop_size, ] += similarity - - + + def cosine_similarity(one: Union[np.ndarray, torch.Tensor], other: Union[np.ndarray, torch.Tensor]) -> Union[np.ndarray, torch.Tensor]: return one @ other.T / (np.linalg.norm(one) * np.linalg.norm(other)) @@ -211,17 +211,17 @@ parameters at the end, when you get an optimized model. n_iters = 300 min_crop_size = 50 - + query = "Who developed the Theory of General Relativity?" image_path = Path("example.jpg") - + r = requests.get("https://github.com/user-attachments/assets/a5bedef2-e915-4286-bcc9-d599083a99a6") - + with image_path.open("wb") as f: f.write(r.content) image = Image.open(image_path) im_tensor = np.array(image) - + x_dim, y_dim = image.size Given the ``model`` and ``processor``, the actual inference is simple: @@ -255,15 +255,15 @@ items in the “How To Build a Saliency Map With CLIP?” list above. initial_similarity = cosine_similarity(results.text_embeds, results.image_embeds).item() # 1. Computing query and image similarity saliency_map = np.zeros((y_dim, x_dim)) - + for _ in tqdm.notebook.tqdm(range(n_iters)): # 6. Setting number of the procedure iterations x, y, crop_size = get_random_crop_params(y_dim, x_dim, min_crop_size) im_crop = get_cropped_image(im_tensor, x, y, crop_size) # 2. Getting a random crop of the image - + inputs = processor(text=[query], images=[im_crop], return_tensors="pt") with torch.no_grad(): results = model(**inputs) # 3. Computing crop and query similarity - + similarity = ( cosine_similarity(results.text_embeds, results.image_embeds).item() - initial_similarity ) # 4. Subtracting query and image similarity from crop and query similarity @@ -313,8 +313,8 @@ Let us overlay the saliency map on the image: plt.title(f'Query: "{query}"') plt.axis("off") return fig - - + + plot_saliency_map(im_tensor, saliency_map, query); @@ -341,21 +341,21 @@ obtain embeddings for the cropped images. with torch.no_grad(): results = model(**inputs) text_embeds = results.text_embeds # save text embeddings to use them later - + initial_similarity = cosine_similarity(text_embeds, results.image_embeds).item() saliency_map = np.zeros((y_dim, x_dim)) - + for _ in tqdm.notebook.tqdm(range(n_iters)): x, y, crop_size = get_random_crop_params(y_dim, x_dim, min_crop_size) im_crop = get_cropped_image(im_tensor, x, y, crop_size) - + image_inputs = processor(images=[im_crop], return_tensors="pt") # crop preprocessing with torch.no_grad(): image_embeds = model.get_image_features(**image_inputs) # calculate image embeddings only - + similarity = cosine_similarity(text_embeds, image_embeds).item() - initial_similarity update_saliency_map(saliency_map, similarity, x, y, crop_size) - + plot_saliency_map(im_tensor, saliency_map, query); @@ -399,9 +399,9 @@ details about that can be found in HuggingFace Transformers .. code:: ipython3 import openvino as ov - + model_name = model_checkpoint.split("/")[-1] - + model.config.torchscript = True model.forward = model.get_text_features text_ov_model = ov.convert_model( @@ -411,7 +411,7 @@ details about that can be found in HuggingFace Transformers "attention_mask": inputs.attention_mask, }, ) - + # get image size after preprocessing from the processor crops_info = processor.image_processor.crop_size.values() if hasattr(processor, "image_processor") else processor.feature_extractor.crop_size.values() model.forward = model.get_image_features @@ -420,12 +420,12 @@ details about that can be found in HuggingFace Transformers example_input={"pixel_values": inputs.pixel_values}, input=[1, 3, *crops_info], ) - + ov_dir = Path("ir") ov_dir.mkdir(exist_ok=True) text_model_path = ov_dir / f"{model_name}_text.xml" image_model_path = ov_dir / f"{model_name}_image.xml" - + # write resulting models on disk ov.save_model(text_ov_model, text_model_path) ov.save_model(image_ov_model, image_model_path) @@ -489,7 +489,7 @@ Inference with OpenVINO™ .. code:: ipython3 core = ov.Core() - + text_model = core.read_model(text_model_path) image_model = core.read_model(image_model_path) @@ -503,9 +503,9 @@ select device from dropdown list for running inference using OpenVINO .. code:: ipython3 from notebook_utils import device_widget - + device = device_widget() - + device @@ -536,23 +536,23 @@ the inference process is mostly similar. text_inputs = dict(processor(text=[query], images=[im_tensor], return_tensors="np")) image_inputs = text_inputs.pop("pixel_values") - + text_embeds = text_model(text_inputs)[0] image_embeds = image_model(image_inputs)[0] - + initial_similarity = cosine_similarity(text_embeds, image_embeds) saliency_map = np.zeros((y_dim, x_dim)) - + for _ in tqdm.notebook.tqdm(range(n_iters)): x, y, crop_size = get_random_crop_params(y_dim, x_dim, min_crop_size) im_crop = get_cropped_image(im_tensor, x, y, crop_size) - + image_inputs = processor(images=[im_crop], return_tensors="np").pixel_values image_embeds = image_model(image_inputs)[image_model.output()] - + similarity = cosine_similarity(text_embeds, image_embeds) - initial_similarity update_saliency_map(saliency_map, similarity, x, y, crop_size) - + plot_saliency_map(im_tensor, saliency_map, query); @@ -601,10 +601,10 @@ performance hint. from typing import Dict, Any import openvino.properties.hint as hints - - + + image_model = core.read_model(image_model_path) - + image_model = core.compile_model( model=image_model, device_name=device.value, @@ -615,10 +615,10 @@ performance hint. text_inputs = dict(processor(text=[query], images=[im_tensor], return_tensors="np")) image_inputs = text_inputs.pop("pixel_values") - + text_embeds = text_model(text_inputs)[text_model.output()] image_embeds = image_model(image_inputs)[image_model.output()] - + initial_similarity = cosine_similarity(text_embeds, image_embeds) saliency_map = np.zeros((y_dim, x_dim)) @@ -641,14 +641,14 @@ should pass a progress bar object and call ``update`` method after user_data: Dict[str, Any], # data that you passed along with input pixel values ) -> None: pbar = user_data.pop("pbar") - + image_embeds = infer_request.get_output_tensor().data similarity = cosine_similarity(user_data.pop("text_embeds"), image_embeds) - user_data.pop("initial_similarity") update_saliency_map(**user_data, similarity=similarity) - + pbar.update(1) # update the progress bar - - + + infer_queue = ov.AsyncInferQueue(image_model) infer_queue.set_callback(completion_callback) @@ -672,9 +672,9 @@ should pass a progress bar object and call ``update`` method after for _ in range(n_iters): x, y, crop_size = get_random_crop_params(y_dim, x_dim, min_crop_size) im_crop = get_cropped_image(im_tensor, x, y, crop_size) - + image_inputs = processor(images=[im_crop], return_tensors="np") - + # push data to the queue infer_queue.start_async( # pass inference data as usual @@ -690,13 +690,13 @@ should pass a progress bar object and call ``update`` method after "pbar": pbar, }, ) - + # after you pushed all data to the queue you wait until all callbacks finished infer_queue.wait_all() - + return plot_saliency_map(im_tensor, saliency_map, query if include_query else None) - - + + infer( im_tensor, x_dim, @@ -733,8 +733,8 @@ Let us wrap all code in the function and add a user interface to it. .. code:: ipython3 import ipywidgets as widgets - - + + def build_saliency_map( image: Image, query: str, @@ -745,16 +745,16 @@ Let us wrap all code in the function and add a user interface to it. ): x_dim, y_dim = image.size im_tensor = np.array(image) - + text_inputs = dict(processor(text=[query], images=[im_tensor], return_tensors="np")) image_inputs = text_inputs.pop("pixel_values") - + text_embeds = text_model(text_inputs)[text_model.output()] image_embeds = image_model(image_inputs)[image_model.output()] - + initial_similarity = cosine_similarity(text_embeds, image_embeds) saliency_map = np.zeros((y_dim, x_dim)) - + return infer( im_tensor, x_dim, @@ -787,8 +787,8 @@ done so far in the notebook. max=200, description="min_crop_size", ) - - + + @widgets.interact_manual(image_link="", query="", n_iters=n_iters_widget, min_crop_size=min_crop_size_widget) def build_saliency_map_from_image_link( image_link: str, @@ -801,10 +801,10 @@ done so far in the notebook. except requests.RequestException as e: print(f"Cannot load image from link: {image_link}\nException: {e}") return - + image = Image.open(image_bytes) image = image.convert("RGB") # remove transparency channel or convert grayscale 1 channel to 3 channels - + build_saliency_map(image, query, n_iters, min_crop_size) @@ -819,15 +819,15 @@ The second version will enable loading the image from your computer. .. code:: ipython3 import io - - + + load_file_widget = widgets.FileUpload( accept="image/*", multiple=False, description="Image file", ) - - + + @widgets.interact_manual( file=load_file_widget, query="", @@ -846,9 +846,9 @@ The second version will enable loading the image from your computer. except Exception as e: print(f"Cannot load the image: {e}") return - + image = image.convert("RGB") - + build_saliency_map(image, query, n_iters, min_crop_size) @@ -868,11 +868,11 @@ Interactive demo with Gradio if not Path("gradio_helper.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/clip-language-saliency-map/gradio_helper.py") open("gradio_helper.py", "w").write(r.text) - + from gradio_helper import make_demo - + demo = make_demo(build_saliency_map) - + try: demo.queue().launch(debug=False) except Exception: @@ -885,7 +885,7 @@ Interactive demo with Gradio .. parsed-literal:: Running on local URL: http://127.0.0.1:7860 - + To create a public link, set `share=True` in `launch()`. @@ -915,7 +915,7 @@ can explore the CLIP capabilities further. For example: ``update_saliency_map`` functions to process multiple crop images at once and accelerate the pipeline even more. - Optimize models with - `NNCF `__ + `NNCF `__ to get further acceleration. You can find example how to quantize CLIP model in `this notebook `__ diff --git a/docs/notebooks/clip-zero-shot-classification-with-output.rst b/docs/notebooks/clip-zero-shot-classification-with-output.rst index 3da831e6d9d0dd..e9ccc07d424cf7 100644 --- a/docs/notebooks/clip-zero-shot-classification-with-output.rst +++ b/docs/notebooks/clip-zero-shot-classification-with-output.rst @@ -230,7 +230,7 @@ For best results with OpenVINO, it is recommended to convert the model to OpenVINO IR format. OpenVINO supports PyTorch via Model conversion API. To convert the PyTorch model to OpenVINO IR format we will use ``ov.convert_model`` of `model conversion -API `__. +API `__. The ``ov.convert_model`` Python function returns an OpenVINO Model object ready to load on the device and start making predictions. We can save it on disk for the next usage with ``ov.save_model``. diff --git a/docs/notebooks/convert-to-openvino-with-output.rst b/docs/notebooks/convert-to-openvino-with-output.rst index bc5a45f244e376..8cf851bfcd9c16 100644 --- a/docs/notebooks/convert-to-openvino-with-output.rst +++ b/docs/notebooks/convert-to-openvino-with-output.rst @@ -74,13 +74,13 @@ These model formats can be read, compiled, and converted to OpenVINO IR, either automatically or explicitly. For more details, refer to `Model -Preparation `__ +Preparation `__ documentation. .. code:: ipython3 # OVC CLI tool parameters description - + ! ovc --help @@ -89,12 +89,12 @@ documentation. usage: ovc INPUT_MODEL... [-h] [--output_model OUTPUT_MODEL] [--compress_to_fp16 [True | False]] [--version] [--input INPUT] [--output OUTPUT] [--extension EXTENSION] [--verbose] - + positional arguments: INPUT_MODEL Input model file(s) from TensorFlow, ONNX, PaddlePaddle. Use openvino.convert_model in Python to convert models from PyTorch. - + optional arguments: -h, --help show this help message and exit --output_model OUTPUT_MODEL @@ -151,7 +151,7 @@ This notebook uses two models for conversion examples: .. code:: ipython3 from pathlib import Path - + # create a directory for models files MODEL_DIRECTORY_PATH = Path("model") MODEL_DIRECTORY_PATH.mkdir(exist_ok=True) @@ -164,14 +164,14 @@ NLP model from Hugging Face and export it in ONNX format: from transformers import AutoModelForSequenceClassification, AutoTokenizer import torch - + ONNX_NLP_MODEL_PATH = MODEL_DIRECTORY_PATH / "distilbert.onnx" - + # download model hf_model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english") # initialize tokenizer tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english") - + if not ONNX_NLP_MODEL_PATH.exists(): inputs = tokenizer("Hi, how are you?", return_tensors="pt") input_names = list(inputs.keys()) @@ -202,7 +202,7 @@ CV classification model from torchvision: .. code:: ipython3 from torchvision.models import resnet50, ResNet50_Weights - + # create model object pytorch_model = resnet50(weights=ResNet50_Weights.DEFAULT) # switch model from training to inference mode @@ -398,9 +398,9 @@ Convert PyTorch model to ONNX format: import torch import warnings - + ONNX_CV_MODEL_PATH = MODEL_DIRECTORY_PATH / "resnet.onnx" - + if ONNX_CV_MODEL_PATH.exists(): print(f"ONNX model {ONNX_CV_MODEL_PATH} already exists.") else: @@ -425,11 +425,11 @@ To convert a model to OpenVINO IR, use the following API: .. code:: ipython3 import openvino as ov - + # ov.convert_model returns an openvino.runtime.Model object print(ONNX_NLP_MODEL_PATH) ov_model = ov.convert_model(ONNX_NLP_MODEL_PATH) - + # then model can be serialized to *.xml & *.bin files ov.save_model(ov_model, MODEL_DIRECTORY_PATH / "distilbert.xml") @@ -473,13 +473,13 @@ inputs. Doing so at the model preparation stage, not at runtime, can be beneficial in terms of performance and memory consumption. For more information refer to `Setting Input -Shapes `__ +Shapes `__ documentation. .. code:: ipython3 import openvino as ov - + ov_model = ov.convert_model(ONNX_NLP_MODEL_PATH, input=[("input_ids", [1, 128]), ("attention_mask", [1, 128])]) .. code:: ipython3 @@ -512,7 +512,7 @@ conversion API parameter as ``-1`` or ``?`` when using ``ovc``: .. code:: ipython3 import openvino as ov - + ov_model = ov.convert_model(ONNX_NLP_MODEL_PATH, input=[("input_ids", [1, -1]), ("attention_mask", [1, -1])]) .. code:: ipython3 @@ -547,10 +547,10 @@ sequence length dimension: .. code:: ipython3 import openvino as ov - - + + sequence_length_dim = ov.Dimension(10, 128) - + ov_model = ov.convert_model( ONNX_NLP_MODEL_PATH, input=[ @@ -593,7 +593,7 @@ disabled by setting ``compress_to_fp16`` flag to ``False``: .. code:: ipython3 import openvino as ov - + ov_model = ov.convert_model(ONNX_NLP_MODEL_PATH) ov.save_model(ov_model, MODEL_DIRECTORY_PATH / "distilbert.xml", compress_to_fp16=False) @@ -623,18 +623,18 @@ Convert Models from memory Model conversion API supports passing original framework Python object directly. More details can be found in -`PyTorch `__, -`TensorFlow `__, -`PaddlePaddle `__ +`PyTorch `__, +`TensorFlow `__, +`PaddlePaddle `__ frameworks conversion guides. .. code:: ipython3 import openvino as ov import torch - + example_input = torch.rand(1, 3, 224, 224) - + ov_model = ov.convert_model(pytorch_model, example_input=example_input, input=example_input.shape) @@ -646,15 +646,15 @@ frameworks conversion guides. .. code:: ipython3 import os - + import openvino as ov import tensorflow_hub as hub - + os.environ["TFHUB_CACHE_DIR"] = str(Path("./tfhub_modules").resolve()) - + model = hub.load("https://www.kaggle.com/models/google/movenet/frameworks/TensorFlow2/variations/singlepose-lightning/versions/4") movenet = model.signatures["serving_default"] - + ov_model = ov.convert_model(movenet) @@ -679,7 +679,7 @@ OVC or can be replaced with functionality from ``ov.PrePostProcessor`` class. Refer to `Optimize Preprocessing notebook `__ for more information about `Preprocessing -API `__. +API `__. Here is the migration guide from legacy model preprocessing to Preprocessing API. @@ -693,7 +693,7 @@ for both inputs and outputs. Some preprocessing requires to set input layouts, for example, setting a batch, applying mean or scales, and reversing input channels (BGR<->RGB). For the layout syntax, check the `Layout API -overview `__. +overview `__. To specify the layout, you can use the layout option followed by the layout value. @@ -704,9 +704,9 @@ Resnet50 model that was exported to the ONNX format: # Converter API import openvino as ov - + ov_model = ov.convert_model(ONNX_CV_MODEL_PATH) - + prep = ov.preprocess.PrePostProcessor(ov_model) prep.input("input.1").model().set_layout(ov.Layout("nchw")) ov_model = prep.build() @@ -735,9 +735,9 @@ and the layout of an original model: # Converter API import openvino as ov - + ov_model = ov.convert_model(ONNX_CV_MODEL_PATH) - + prep = ov.preprocess.PrePostProcessor(ov_model) prep.input("input.1").tensor().set_layout(ov.Layout("nhwc")) prep.input("input.1").model().set_layout(ov.Layout("nchw")) @@ -771,14 +771,14 @@ more examples. # Converter API import openvino as ov - + ov_model = ov.convert_model(ONNX_CV_MODEL_PATH) - + prep = ov.preprocess.PrePostProcessor(ov_model) prep.input("input.1").tensor().set_layout(ov.Layout("nchw")) prep.input("input.1").preprocess().mean([255 * x for x in [0.485, 0.456, 0.406]]) prep.input("input.1").preprocess().scale([255 * x for x in [0.229, 0.224, 0.225]]) - + ov_model = prep.build() .. code:: python @@ -809,9 +809,9 @@ the color channels before inference. # Converter API import openvino as ov - + ov_model = ov.convert_model(ONNX_CV_MODEL_PATH) - + prep = ov.preprocess.PrePostProcessor(ov_model) prep.input("input.1").tensor().set_layout(ov.Layout("nchw")) prep.input("input.1").preprocess().reverse_channels() diff --git a/docs/notebooks/cross-lingual-books-alignment-with-output.rst b/docs/notebooks/cross-lingual-books-alignment-with-output.rst index 68f51ad137ff16..b9f4024dcb8f0f 100644 --- a/docs/notebooks/cross-lingual-books-alignment-with-output.rst +++ b/docs/notebooks/cross-lingual-books-alignment-with-output.rst @@ -482,7 +482,7 @@ Optimize the Model with OpenVINO The LaBSE model is quite large and can be slow to infer on some hardware, so let’s optimize it with OpenVINO. `Model Conversion -API `__ +API `__ accepts the PyTorch/Transformers model object and additional information about model inputs. An ``example_input`` is needed to trace the model execution graph, as PyTorch constructs it dynamically during inference. @@ -862,7 +862,7 @@ the pipeline - getting embeddings. You might wonder why, when using OpenVINO, you need to compile the model after reading it. There are two main reasons for this: 1. Compatibility with different devices. The model can be compiled to run on a `specific -device `__, +device `__, like CPU, GPU or GNA. Each device may work with different data types, support different features, and gain performance by changing the neural network for a specific computing model. With OpenVINO, you do not need @@ -871,13 +871,13 @@ hardware. A universal OpenVINO model representation is enough. 1. Optimization for different scenarios. For example, one scenario prioritizes minimizing the *time between starting and finishing model inference* (`latency-oriented -optimization `__). +optimization `__). In our case, it is more important *how many texts per second the model can process* (`throughput-oriented -optimization `__). +optimization `__). To get a throughput-optimized model, pass a `performance -hint `__ +hint `__ as a configuration during compilation. Then OpenVINO selects the optimal parameters for execution on the available hardware. @@ -897,7 +897,7 @@ parameters for execution on the available hardware. To further optimize hardware utilization, let’s change the inference mode from synchronous (Sync) to asynchronous (Async). While the synchronous API may be easier to start with, it is -`recommended `__ +`recommended `__ to use the asynchronous (callbacks-based) API in production code. It is the most general and scalable way to implement flow control for any number of requests. @@ -941,7 +941,7 @@ advance and fill it in as the inference requests are executed. Let’s compare the models and plot the results. **Note**: To get a more accurate benchmark, use the `Benchmark Python - Tool `__ + Tool `__ .. code:: ipython3 @@ -1049,8 +1049,8 @@ boost. Here are useful links with information about the techniques used in this notebook: - `OpenVINO performance -hints `__ +hints `__ - `OpenVINO Async -API `__ +API `__ - `Throughput -Optimizations `__ +Optimizations `__ diff --git a/docs/notebooks/ct-segmentation-quantize-nncf-with-output.rst b/docs/notebooks/ct-segmentation-quantize-nncf-with-output.rst index 853da533385284..13da68e4db5001 100644 --- a/docs/notebooks/ct-segmentation-quantize-nncf-with-output.rst +++ b/docs/notebooks/ct-segmentation-quantize-nncf-with-output.rst @@ -14,7 +14,7 @@ scratch; the data is from This third tutorial in the series shows how to: - Convert an Original model to OpenVINO IR with `model conversion - API `__ + API `__ - Quantize a PyTorch model with NNCF - Evaluate the F1 score metric of the original model and the quantized model @@ -120,9 +120,9 @@ Imports import zipfile from pathlib import Path from typing import Union - + warnings.filterwarnings("ignore", category=UserWarning) - + import cv2 import matplotlib.pyplot as plt import monai @@ -134,19 +134,19 @@ Imports from nncf.common.logging.logger import set_log_level from torchmetrics import F1Score as F1 import requests - - + + set_log_level(logging.ERROR) # Disables all NNCF info and warning messages - + # Fetch `notebook_utils` module r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py") open("notebook_utils.py", "w").write(r.text) from notebook_utils import download_file, device_widget - + if not Path("./custom_segmentation.py").exists(): download_file(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/ct-segmentation-quantize/custom_segmentation.py") from custom_segmentation import SegmentationModel - + if not Path("./async_pipeline.py").exists(): download_file(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/ct-segmentation-quantize/async_pipeline.py") from async_pipeline import show_live_inference @@ -199,13 +199,13 @@ notebook `__. state_dict_url = "https://storage.openvinotoolkit.org/repositories/openvino_notebooks/models/kidney-segmentation-kits19/unet_kits19_state_dict.pth" state_dict_file = download_file(state_dict_url, directory="pretrained_model") state_dict = torch.load(state_dict_file, map_location=torch.device("cpu")) - + new_state_dict = {} for k, v in state_dict.items(): new_key = k.replace("_model.", "") new_state_dict[new_key] = v new_state_dict.pop("loss_function.pos_weight") - + model = monai.networks.nets.BasicUNet(spatial_dims=2, in_channels=1, out_channels=1).eval() model.load_state_dict(new_state_dict) @@ -293,8 +293,8 @@ method to display the images in the expected orientation: def rotate_and_flip(image): """Rotate `image` by 90 degrees and flip horizontally""" return cv2.flip(cv2.rotate(image, rotateCode=cv2.ROTATE_90_CLOCKWISE), flipCode=1) - - + + class KitsDataset: def __init__(self, basedir: str): """ @@ -303,35 +303,35 @@ method to display the images in the expected orientation: with each subdirectory containing directories imaging_frames, with jpg images, and segmentation_frames with segmentation masks as png files. See [data-preparation-ct-scan](./data-preparation-ct-scan.ipynb) - + :param basedir: Directory that contains the prepared CT scans """ masks = sorted(BASEDIR.glob("case_*/segmentation_frames/*png")) - + self.basedir = basedir self.dataset = masks print(f"Created dataset with {len(self.dataset)} items. " f"Base directory for data: {basedir}") - + def __getitem__(self, index): """ Get an item from the dataset at the specified index. - + :return: (image, segmentation_mask) """ mask_path = self.dataset[index] image_path = str(mask_path.with_suffix(".jpg")).replace("segmentation_frames", "imaging_frames") - + # Load images with MONAI's LoadImage to match data loading in training notebook mask = LoadImage(image_only=True, dtype=np.uint8)(str(mask_path)).numpy() img = LoadImage(image_only=True, dtype=np.float32)(str(image_path)).numpy() - + if img.shape[:2] != (512, 512): img = cv2.resize(img.astype(np.uint8), (512, 512)).astype(np.float32) mask = cv2.resize(mask, (512, 512)) - + input_image = np.expand_dims(img, axis=0) return input_image, mask - + def __len__(self): return len(self.dataset) @@ -349,10 +349,10 @@ kidney pixels to verify that the annotations look correct: image_data, mask = next(item for item in dataset if np.count_nonzero(item[1]) > 5000) # Remove extra image dimension and rotate and flip the image for visualization image = rotate_and_flip(image_data.squeeze()) - + # The data loader returns annotations as (index, mask) and mask in shape (H,W) mask = rotate_and_flip(mask) - + fig, ax = plt.subplots(1, 2, figsize=(12, 6)) ax[0].imshow(image, cmap="gray") ax[1].imshow(mask, cmap="gray"); @@ -431,7 +431,7 @@ this notebook. fp32_ir_path = MODEL_DIR / Path("unet_kits19_fp32.xml") dummy_input = torch.randn(1, 1, 512, 512) - + fp32_ir_model = ov.convert_model(model, example_input=dummy_input, input=dummy_input.shape) ov.save_model(fp32_ir_model, str(fp32_ir_path)) @@ -476,8 +476,8 @@ steps: """ images, _ = data_item return images - - + + data_loader = torch.utils.data.DataLoader(dataset) calibration_dataset = nncf.Dataset(data_loader, transform_fn) quantized_model = nncf.quantize( @@ -534,7 +534,7 @@ Convert quantized model to OpenVINO IR model and save it. if x_e.shape[-i - 1] != x_0.shape[-i - 1]: /opt/home/k8sworker/ci-ai/cibuilds/jobs/ov-notebook/jobs/OVNotebookOps/builds/835/archive/.workspace/scm/ov-notebook/.venv/lib/python3.8/site-packages/torch/jit/_trace.py:1303: TracerWarning: Output nr 1. of the traced function does not match the corresponding output of the Python function. Detailed error: Tensor-likes are not close! - + Mismatched elements: 250458 / 262144 (95.5%) Greatest absolute difference: 3.8674159049987793 at index (0, 0, 351, 76) (up to 1e-05 allowed) Greatest relative difference: 12206.866810726728 at index (0, 0, 144, 31) (up to 1e-05 allowed) @@ -562,7 +562,7 @@ Compare File Size fp32_ir_model_size = fp32_ir_path.with_suffix(".bin").stat().st_size / 1024 quantized_model_size = int8_ir_path.with_suffix(".bin").stat().st_size / 1024 - + print(f"FP32 IR model size: {fp32_ir_model_size:.2f} KB") print(f"INT8 model size: {quantized_model_size:.2f} KB") @@ -583,7 +583,7 @@ Select Inference Device core = ov.Core() # By default, benchmark on MULTI:CPU,GPU if a GPU is available, otherwise on CPU. device_list = ["MULTI:CPU,GPU" if "GPU" in core.available_devices else "AUTO"] - + device = device_widget(device_list[0], added=device_list) device @@ -605,7 +605,7 @@ Compare Metrics for the original model and the quantized model to be sure that t int8_compiled_model = core.compile_model(int8_ir_model, device.value) int8_f1 = compute_f1(int8_compiled_model, dataset) - + print(f"FP32 F1: {fp32_f1:.3f}") print(f"INT8 F1: {int8_f1:.3f}") @@ -623,7 +623,7 @@ Compare Performance of the FP32 IR Model and Quantized Models To measure the inference performance of the ``FP32`` and ``INT8`` models, we use `Benchmark -Tool `__ +Tool `__ - OpenVINO’s inference performance measurement tool. Benchmark tool is a command line application, part of OpenVINO development tools, that can be run in the notebook with ``! benchmark_app`` or @@ -653,12 +653,12 @@ be run in the notebook with ``! benchmark_app`` or [Step 2/11] Loading OpenVINO Runtime [ INFO ] OpenVINO: [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] + [ INFO ] [ INFO ] Device info: [ INFO ] AUTO [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] - [ INFO ] + [ INFO ] + [ INFO ] [Step 3/11] Setting device configuration [ WARNING ] Performance hint was not explicitly specified in command line. Device(AUTO) performance hint will be set to PerformanceMode.LATENCY. [Step 4/11] Reading model files @@ -711,7 +711,7 @@ be run in the notebook with ``! benchmark_app`` or [ INFO ] PERF_COUNT: False [Step 9/11] Creating infer requests and preparing input tensors [ WARNING ] No input files were given for input 'x'!. This input will be filled with random values! - [ INFO ] Fill input 'x' with random values + [ INFO ] Fill input 'x' with random values [Step 10/11] Measuring performance (Start inference synchronously, limits: 15000 ms duration) [ INFO ] Benchmarking in inference only mode (inputs filling are not included in measurement loop). [ INFO ] First inference took 48.49 ms @@ -740,12 +740,12 @@ be run in the notebook with ``! benchmark_app`` or [Step 2/11] Loading OpenVINO Runtime [ INFO ] OpenVINO: [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] + [ INFO ] [ INFO ] Device info: [ INFO ] AUTO [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] - [ INFO ] + [ INFO ] + [ INFO ] [Step 3/11] Setting device configuration [ WARNING ] Performance hint was not explicitly specified in command line. Device(AUTO) performance hint will be set to PerformanceMode.LATENCY. [Step 4/11] Reading model files @@ -798,7 +798,7 @@ be run in the notebook with ``! benchmark_app`` or [ INFO ] PERF_COUNT: False [Step 9/11] Creating infer requests and preparing input tensors [ WARNING ] No input files were given for input 'x'!. This input will be filled with random values! - [ INFO ] Fill input 'x' with random values + [ INFO ] Fill input 'x' with random values [Step 10/11] Measuring performance (Start inference synchronously, limits: 15000 ms duration) [ INFO ] Benchmarking in inference only mode (inputs filling are not included in measurement loop). [ INFO ] First inference took 29.18 ms @@ -845,11 +845,11 @@ seed is displayed to enable reproducing specific runs of this cell. # to binary segmentation masks def sigmoid(x): return np.exp(-np.logaddexp(0, -x)) - - + + num_images = 4 colormap = "gray" - + # Load FP32 and INT8 models core = ov.Core() fp_model = core.read_model(fp32_ir_path) @@ -858,11 +858,11 @@ seed is displayed to enable reproducing specific runs of this cell. compiled_model_int8 = core.compile_model(int8_model, device_name=device.value) output_layer_fp = compiled_model_fp.output(0) output_layer_int8 = compiled_model_int8.output(0) - + # Create subset of dataset background_slices = (item for item in dataset if np.count_nonzero(item[1]) == 0) kidney_slices = (item for item in dataset if np.count_nonzero(item[1]) > 50) - + background_slices_l = list(background_slices) kidney_slices_l = list(kidney_slices) if len(background_slices_l) != 0: @@ -872,13 +872,13 @@ seed is displayed to enable reproducing specific runs of this cell. else: kidkey_id = np.random.choice(len(kidneyslices_l), 2) data_subset = [kidney_slices_l[idx] for idx in kidney_id] - + # Set seed to current time. To reproduce specific results, copy the printed seed # and manually set `seed` to that value. seed = int(time.time()) np.random.seed(seed) print(f"Visualizing results with seed {seed}") - + fig, ax = plt.subplots(nrows=num_images, ncols=4, figsize=(24, num_images * 4)) for i, (image, mask) in enumerate(data_subset): display_image = rotate_and_flip(image.squeeze()) @@ -887,13 +887,13 @@ seed is displayed to enable reproducing specific runs of this cell. input_image = np.expand_dims(image, 0) res_fp = compiled_model_fp([input_image]) res_int8 = compiled_model_int8([input_image]) - + # Process inference outputs and convert to binary segementation masks result_mask_fp = sigmoid(res_fp[output_layer_fp]).squeeze().round().astype(np.uint8) result_mask_int8 = sigmoid(res_int8[output_layer_int8]).squeeze().round().astype(np.uint8) result_mask_fp = rotate_and_flip(result_mask_fp) result_mask_int8 = rotate_and_flip(result_mask_int8) - + # Display images, annotations, FP32 result and INT8 result ax[i, 0].imshow(display_image, cmap=colormap) ax[i, 1].imshow(target_mask, cmap=colormap) @@ -947,7 +947,7 @@ overlay of the segmentation mask on the original image/frame. .. code:: ipython3 CASE = 117 - + segmentation_model = SegmentationModel(ie=core, model_path=int8_ir_path, sigmoid=True, rotate_and_flip=True) case_path = BASEDIR / f"case_{CASE:05d}" image_paths = sorted(case_path.glob("imaging_frames/*jpg")) diff --git a/docs/notebooks/ddcolor-image-colorization-with-output.rst b/docs/notebooks/ddcolor-image-colorization-with-output.rst index 11b92fe4897f5e..6215f42113cacd 100644 --- a/docs/notebooks/ddcolor-image-colorization-with-output.rst +++ b/docs/notebooks/ddcolor-image-colorization-with-output.rst @@ -499,7 +499,7 @@ Compare inference time of the FP16 and INT8 models To measure the inference performance of OpenVINO FP16 and INT8 models, use `Benchmark -Tool `__. +Tool `__. **NOTE**: For the most accurate performance estimation, it is recommended to run ``benchmark_app`` in a terminal/command prompt diff --git a/docs/notebooks/depth-anything-v2-with-output.rst b/docs/notebooks/depth-anything-v2-with-output.rst index aba253c3ea2549..e5106f8b8781db 100644 --- a/docs/notebooks/depth-anything-v2-with-output.rst +++ b/docs/notebooks/depth-anything-v2-with-output.rst @@ -83,14 +83,14 @@ Prerequisites import requests from pathlib import Path - - + + if not Path("notebook_utils.py").exists(): r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) open("notebook_utils.py", "w").write(r.text) - + if not Path("cmd_helper.py").exists(): r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py", @@ -100,8 +100,8 @@ Prerequisites .. code:: ipython3 from cmd_helper import clone_repo - - + + clone_repo("https://huggingface.co/spaces/depth-anything/Depth-Anything-V2") @@ -116,12 +116,12 @@ Prerequisites .. code:: ipython3 import platform - - + + %pip install -q "openvino>=2024.2.0" "datasets>=2.14.6" "nncf>=2.11.0" "tqdm" "matplotlib>=3.4" %pip install -q "typing-extensions>=4.9.0" eval-type-backport "gradio>=4.19" gradio_imageslider %pip install -q torch torchvision "opencv-python" huggingface_hub --extra-index-url https://download.pytorch.org/whl/cpu - + if platform.system() == "Darwin": %pip install -q "numpy<2.0.0" if platform.python_version_tuple()[1] in ["8", "9"]: @@ -148,10 +148,10 @@ attention optimizations first. attention_file_path = Path("./Depth-Anything-V2/depth_anything_v2/dinov2_layers/attention.py") orig_attention_path = attention_file_path.parent / ("orig_" + attention_file_path.name) - + if not orig_attention_path.exists(): attention_file_path.rename(orig_attention_path) - + with orig_attention_path.open("r") as f: data = f.read() data = data.replace("XFORMERS_AVAILABLE = True", "XFORMERS_AVAILABLE = False") @@ -166,15 +166,15 @@ Prepare input data .. code:: ipython3 from PIL import Image - + from notebook_utils import download_file, device_widget, quantization_widget - - + + download_file( "https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/3f779fc1-c1b2-4dec-915a-64dae510a2bb", "furseal.png", ) - + Image.open("furseal.png").resize((600, 400)) @@ -208,11 +208,11 @@ DepthAnythingV2 family. .. code:: ipython3 from huggingface_hub import hf_hub_download - + encoder = "vits" model_type = "Small" model_id = f"depth_anything_v2_{encoder}" - + model_path = hf_hub_download(repo_id=f"depth-anything/Depth-Anything-V2-{model_type}", filename=f"{model_id}.pth", repo_type="model") Preprocessed image passed to model forward and model returns depth map @@ -224,22 +224,22 @@ is preprocessed image height, ``W`` is preprocessed image width. import cv2 import torch import torch.nn.functional as F - + from depth_anything_v2.dpt import DepthAnythingV2 - + model = DepthAnythingV2(encoder=encoder, features=64, out_channels=[48, 96, 192, 384]) model.load_state_dict(torch.load(model_path, map_location="cpu")) model.eval() - + raw_img = cv2.imread("furseal.png") image, (h, w) = model.image2tensor(raw_img) image = image.to("cpu").to(torch.float32) - + with torch.no_grad(): depth = model.forward(image) - + depth = F.interpolate(depth[:, None], (h, w), mode="bilinear", align_corners=True)[0, 0] - + output = depth.cpu().numpy() @@ -256,16 +256,16 @@ is preprocessed image height, ``W`` is preprocessed image width. from matplotlib import pyplot as plt import numpy as np import cv2 - - + + def get_depth_map(output, w, h): depth = cv2.resize(output, (w, h)) - + depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0 depth = depth.astype(np.uint8) - + depth = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO) - + return depth .. code:: ipython3 @@ -303,9 +303,9 @@ loading on device using ``core.complie_model``. .. code:: ipython3 import openvino as ov - + OV_DEPTH_ANYTHING_PATH = Path(f"{model_id}.xml") - + if not OV_DEPTH_ANYTHING_PATH.exists(): ov_model = ov.convert_model(model, example_input=torch.rand(1, 3, 518, 518), input=[1, 3, 518, 518]) ov.save_model(ov_model, OV_DEPTH_ANYTHING_PATH) @@ -340,7 +340,7 @@ For starting work, please select inference device from dropdown list. .. code:: ipython3 device = device_widget() - + device @@ -355,7 +355,7 @@ For starting work, please select inference device from dropdown list. .. code:: ipython3 core = ov.Core() - + compiled_model = core.compile_model(OV_DEPTH_ANYTHING_PATH, device.value) Run inference on image @@ -372,7 +372,7 @@ range. from depth_anything_v2.util.transform import Resize, NormalizeImage, PrepareForNet from torchvision.transforms import Compose - + transform = Compose( [ Resize( @@ -391,11 +391,11 @@ range. .. code:: ipython3 h, w = raw_img.shape[:-1] - + image = cv2.cvtColor(raw_img, cv2.COLOR_BGR2RGB) / 255.0 image = transform({"image": image})["image"] image = torch.from_numpy(image).unsqueeze(0) - + res = compiled_model(image)[0] .. code:: ipython3 @@ -427,12 +427,12 @@ Run inference on video .. code:: ipython3 VIDEO_FILE = "./Coco Walking in Berkeley.mp4" - + download_file( "https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/Coco%20Walking%20in%20Berkeley.mp4", VIDEO_FILE, ) - + # Number of seconds of input video to process. Set `NUM_SECONDS` to 0 to process # the full video. NUM_SECONDS = 4 @@ -449,7 +449,7 @@ Run inference on video # Try the `THEO` encoding if you have FFMPEG installed. # FOURCC = cv2.VideoWriter_fourcc(*"THEO") FOURCC = cv2.VideoWriter_fourcc(*"vp09") - + # Create Path objects for the input video and the result video. output_directory = Path("output") output_directory.mkdir(exist_ok=True) @@ -470,11 +470,11 @@ Run inference on video raise ValueError(f"The video at {VIDEO_FILE} cannot be read.") input_fps = cap.get(cv2.CAP_PROP_FPS) input_video_frame_height, input_video_frame_width = image.shape[:2] - + target_fps = input_fps / ADVANCE_FRAMES target_frame_height = int(input_video_frame_height * SCALE_OUTPUT) target_frame_width = int(input_video_frame_width * SCALE_OUTPUT) - + cap.release() print(f"The input video has a frame width of {input_video_frame_width}, " f"frame height of {input_video_frame_height} and runs at {input_fps:.2f} fps") print( @@ -495,13 +495,13 @@ Run inference on video def normalize_minmax(data): """Normalizes the values in `data` between 0 and 1""" return (data - data.min()) / (data.max() - data.min()) - - + + def convert_result_to_image(result, colormap="viridis"): """ Convert network result of floating point numbers to an RGB image with integer values from 0-255 by applying a colormap. - + `result` is expected to be a single network result in 1,H,W shape `colormap` is a matplotlib colormap. See https://matplotlib.org/stable/tutorials/colors/colormaps.html @@ -512,8 +512,8 @@ Run inference on video result = result.astype(np.uint8) result = cv2.applyColorMap(result, cv2.COLORMAP_INFERNO)[:, :, ::-1] return result - - + + def to_rgb(image_data) -> np.ndarray: """ Convert image_data from BGR to RGB @@ -532,17 +532,17 @@ Run inference on video clear_output, display, ) - - + + def process_video(compiled_model, video_file, result_video_path): # Initialize variables. input_video_frame_nr = 0 start_time = time.perf_counter() total_inference_duration = 0 - + # Open the input video cap = cv2.VideoCapture(str(video_file)) - + # Create a result video. out_video = cv2.VideoWriter( str(result_video_path), @@ -550,35 +550,35 @@ Run inference on video target_fps, (target_frame_width * 2, target_frame_height), ) - + num_frames = int(NUM_SECONDS * input_fps) total_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT) if num_frames == 0 else num_frames progress_bar = ProgressBar(total=total_frames) progress_bar.display() - + try: while cap.isOpened(): ret, image = cap.read() if not ret: cap.release() break - + if input_video_frame_nr >= total_frames: break - + h, w = image.shape[:-1] input_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) / 255.0 input_image = transform({"image": input_image})["image"] # Reshape the image to network input shape NCHW. input_image = np.expand_dims(input_image, 0) - + # Do inference. inference_start_time = time.perf_counter() result = compiled_model(input_image)[0] inference_stop_time = time.perf_counter() inference_duration = inference_stop_time - inference_start_time total_inference_duration += inference_duration - + if input_video_frame_nr % (10 * ADVANCE_FRAMES) == 0: clear_output(wait=True) progress_bar.display() @@ -592,7 +592,7 @@ Run inference on video f"({1/inference_duration:.2f} FPS)" ) ) - + # Transform the network result to a RGB image. result_frame = to_rgb(convert_result_to_image(result)) # Resize the image and the result to a target frame shape. @@ -602,13 +602,13 @@ Run inference on video stacked_frame = np.hstack((image, result_frame)) # Save a frame to the video. out_video.write(stacked_frame) - + input_video_frame_nr = input_video_frame_nr + ADVANCE_FRAMES cap.set(1, input_video_frame_nr) - + progress_bar.progress = input_video_frame_nr progress_bar.update() - + except KeyboardInterrupt: print("Processing interrupted.") finally: @@ -618,7 +618,7 @@ Run inference on video cap.release() end_time = time.perf_counter() duration = end_time - start_time - + print( f"Processed {processed_frames} frames in {duration:.2f} seconds. " f"Total FPS (including video processing): {processed_frames/duration:.2f}." @@ -634,7 +634,7 @@ Run inference on video .. parsed-literal:: - Processed 60 frames in 13.15 seconds. Total FPS (including video processing): 4.56.Inference FPS: 10.69 + Processed 60 frames in 13.15 seconds. Total FPS (including video processing): 4.56.Inference FPS: 10.69 Video saved to 'output/Coco Walking in Berkeley_depth_anything.mp4'. @@ -662,7 +662,7 @@ Run inference on video Showing video saved at /opt/home/k8sworker/ci-ai/cibuilds/jobs/ov-notebook/jobs/OVNotebookOps/builds/835/archive/.workspace/scm/ov-notebook/notebooks/depth-anything/output/Coco Walking in Berkeley_depth_anything.mp4 - If you cannot see the video in your browser, please click on the following link to download the video + If you cannot see the video in your browser, please click on the following link to download the video @@ -704,7 +704,7 @@ improve model inference speed. .. code:: ipython3 to_quantize = quantization_widget() - + to_quantize @@ -724,9 +724,9 @@ improve model inference speed. url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py", ) open("skip_kernel_extension.py", "w").write(r.text) - + OV_DEPTH_ANYTHING_INT8_PATH = Path(f"{model_id}_int8.xml") - + %load_ext skip_kernel_extension Prepare calibration dataset @@ -741,9 +741,9 @@ dataset from Hugging Face as calibration data. .. code:: ipython3 %%skip not $to_quantize.value - + import datasets - + if not OV_DEPTH_ANYTHING_INT8_PATH.exists(): subset_size = 300 calibration_data = [] @@ -774,9 +774,9 @@ quantization code below may take some time. .. code:: ipython3 %%skip not $to_quantize.value - + import nncf - + if not OV_DEPTH_ANYTHING_INT8_PATH.exists(): model = core.read_model(OV_DEPTH_ANYTHING_PATH) quantized_model = nncf.quantize( @@ -859,11 +859,11 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + def visualize_results(orig_img:Image.Image, optimized_img:Image.Image): """ Helper function for results visualization - + Parameters: orig_img (Image.Image): generated image using FP16 model optimized_img (Image.Image): generated image using quantized model @@ -885,7 +885,7 @@ data. list_axes[1].imshow(np.array(optimized_img)) list_axes[0].set_title(orig_title, fontsize=15) list_axes[1].set_title(control_title, fontsize=15) - + fig.subplots_adjust(wspace=0.01, hspace=0.01) fig.tight_layout() return fig @@ -893,11 +893,11 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + image = cv2.cvtColor(cv2.imread('furseal.png'), cv2.COLOR_BGR2RGB) / 255.0 image = transform({'image': image})['image'] image = torch.from_numpy(image).unsqueeze(0) - + int8_compiled_model = core.compile_model(OV_DEPTH_ANYTHING_INT8_PATH, device.value) int8_res = int8_compiled_model(image)[0] int8_depth_color = get_depth_map(int8_res[0], w, h) @@ -905,7 +905,7 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + visualize_results(depth_color[:, :, ::-1], int8_depth_color[:, :, ::-1]) @@ -916,7 +916,7 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + int8_result_video_path = output_directory / f"{Path(VIDEO_FILE).stem}_depth_anything_int8.mp4" stacked_frame = process_video(int8_compiled_model, VIDEO_FILE, int8_result_video_path) display_video(stacked_frame) @@ -924,11 +924,11 @@ data. .. parsed-literal:: - Processed 60 frames in 12.60 seconds. Total FPS (including video processing): 4.76.Inference FPS: 13.15 + Processed 60 frames in 12.60 seconds. Total FPS (including video processing): 4.76.Inference FPS: 13.15 Video saved to 'output/Coco Walking in Berkeley_depth_anything_int8.mp4'. Showing video saved at /opt/home/k8sworker/ci-ai/cibuilds/jobs/ov-notebook/jobs/OVNotebookOps/builds/835/archive/.workspace/scm/ov-notebook/notebooks/depth-anything/output/Coco Walking in Berkeley_depth_anything.mp4 - If you cannot see the video in your browser, please click on the following link to download the video + If you cannot see the video in your browser, please click on the following link to download the video @@ -954,10 +954,10 @@ Compare model file size .. code:: ipython3 %%skip not $to_quantize.value - + fp16_ir_model_size = OV_DEPTH_ANYTHING_PATH.with_suffix(".bin").stat().st_size / 2**20 quantized_model_size = OV_DEPTH_ANYTHING_INT8_PATH.with_suffix(".bin").stat().st_size / 2**20 - + print(f"FP16 model size: {fp16_ir_model_size:.2f} MB") print(f"INT8 model size: {quantized_model_size:.2f} MB") print(f"Model compression rate: {fp16_ir_model_size / quantized_model_size:.3f}") @@ -977,7 +977,7 @@ Compare inference time of the FP16 and INT8 models To measure the inference performance of OpenVINO FP16 and INT8 models, use `Benchmark -Tool `__. +Tool `__. **NOTE**: For the most accurate performance estimation, it is recommended to run ``benchmark_app`` in a terminal/command prompt @@ -986,19 +986,19 @@ Tool =2023.3.0" "datasets>=2.14.6" "nncf" "tqdm" %pip install -q "typing-extensions>=4.9.0" eval-type-backport "gradio>=4.19" "matplotlib>=3.4" %pip install -q torch torchvision "opencv-python" huggingface_hub --extra-index-url https://download.pytorch.org/whl/cpu - + if platform.system() == "Darwin": %pip install -q "numpy<2.0.0" if platform.python_version_tuple()[1] in ["8", "9"]: @@ -132,14 +132,14 @@ attention optimizations first. .. code:: ipython3 from pathlib import Path - - + + attention_file_path = Path("./torchhub/facebookresearch_dinov2_main/dinov2/layers/attention.py") orig_attention_path = attention_file_path.parent / ("orig_" + attention_file_path.name) - + if not orig_attention_path.exists(): attention_file_path.rename(orig_attention_path) - + with orig_attention_path.open("r") as f: data = f.read() data = data.replace("XFORMERS_AVAILABLE = True", "XFORMERS_AVAILABLE = False") @@ -159,7 +159,7 @@ DepthAnything family. .. code:: ipython3 from depth_anything.dpt import DepthAnything - + encoder = "vits" # can also be 'vitb' or 'vitl' model_id = "depth_anything_{:}14".format(encoder) depth_anything = DepthAnything.from_pretrained(f"LiheYoung/{model_id}") @@ -179,22 +179,22 @@ Prepare input data .. code:: ipython3 from PIL import Image - - + + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) open("notebook_utils.py", "w").write(r.text) - - + + from notebook_utils import download_file, device_widget, quantization_widget - - + + download_file( "https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/3f779fc1-c1b2-4dec-915a-64dae510a2bb", "furseal.png", ) - + Image.open("furseal.png").resize((600, 400)) @@ -219,10 +219,10 @@ range. from depth_anything.util.transform import Resize, NormalizeImage, PrepareForNet from torchvision.transforms import Compose - + import cv2 import torch - + transform = Compose( [ Resize( @@ -237,8 +237,8 @@ range. PrepareForNet(), ] ) - - + + image = cv2.cvtColor(cv2.imread("furseal.png"), cv2.COLOR_BGR2RGB) / 255.0 h, w = image.shape[:-1] image = transform({"image": image})["image"] @@ -265,17 +265,17 @@ image size and prepare it for visualization. import torch.nn.functional as F import numpy as np - + depth = F.interpolate(depth[None], (h, w), mode="bilinear", align_corners=False)[0, 0] depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0 - + depth = depth.cpu().detach().numpy().astype(np.uint8) depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO) .. code:: ipython3 from matplotlib import pyplot as plt - + plt.imshow(depth_color[:, :, ::-1]); @@ -299,9 +299,9 @@ loading on device using ``core.complie_model``. .. code:: ipython3 import openvino as ov - + OV_DEPTH_ANYTHING_PATH = Path(f"{model_id}.xml") - + if not OV_DEPTH_ANYTHING_PATH.exists(): ov_model = ov.convert_model(depth_anything, example_input=image, input=[1, 3, 518, 518]) ov.save_model(ov_model, OV_DEPTH_ANYTHING_PATH) @@ -367,12 +367,12 @@ Run inference on image depth = model_output[0] depth = cv2.resize(depth, (w, h)) depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0 - + depth = depth.astype(np.uint8) depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO) return depth_color - - + + depth_color = get_depth_map(res) .. code:: ipython3 @@ -395,7 +395,7 @@ Run inference on video "https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/video/Coco%20Walking%20in%20Berkeley.mp4", "./Coco Walking in Berkeley.mp4", ) - + VIDEO_FILE = "./Coco Walking in Berkeley.mp4" # Number of seconds of input video to process. Set `NUM_SECONDS` to 0 to process # the full video. @@ -413,7 +413,7 @@ Run inference on video # Try the `THEO` encoding if you have FFMPEG installed. # FOURCC = cv2.VideoWriter_fourcc(*"THEO") FOURCC = cv2.VideoWriter_fourcc(*"vp09") - + # Create Path objects for the input video and the result video. output_directory = Path("output") output_directory.mkdir(exist_ok=True) @@ -434,11 +434,11 @@ Run inference on video raise ValueError(f"The video at {VIDEO_FILE} cannot be read.") input_fps = cap.get(cv2.CAP_PROP_FPS) input_video_frame_height, input_video_frame_width = image.shape[:2] - + target_fps = input_fps / ADVANCE_FRAMES target_frame_height = int(input_video_frame_height * SCALE_OUTPUT) target_frame_width = int(input_video_frame_width * SCALE_OUTPUT) - + cap.release() print(f"The input video has a frame width of {input_video_frame_width}, " f"frame height of {input_video_frame_height} and runs at {input_fps:.2f} fps") print( @@ -459,13 +459,13 @@ Run inference on video def normalize_minmax(data): """Normalizes the values in `data` between 0 and 1""" return (data - data.min()) / (data.max() - data.min()) - - + + def convert_result_to_image(result, colormap="viridis"): """ Convert network result of floating point numbers to an RGB image with integer values from 0-255 by applying a colormap. - + `result` is expected to be a single network result in 1,H,W shape `colormap` is a matplotlib colormap. See https://matplotlib.org/stable/tutorials/colors/colormaps.html @@ -476,8 +476,8 @@ Run inference on video result = result.astype(np.uint8) result = cv2.applyColorMap(result, cv2.COLORMAP_INFERNO)[:, :, ::-1] return result - - + + def to_rgb(image_data) -> np.ndarray: """ Convert image_data from BGR to RGB @@ -496,17 +496,17 @@ Run inference on video clear_output, display, ) - - + + def process_video(compiled_model, video_file, result_video_path): # Initialize variables. input_video_frame_nr = 0 start_time = time.perf_counter() total_inference_duration = 0 - + # Open the input video cap = cv2.VideoCapture(str(video_file)) - + # Create a result video. out_video = cv2.VideoWriter( str(result_video_path), @@ -514,35 +514,35 @@ Run inference on video target_fps, (target_frame_width * 2, target_frame_height), ) - + num_frames = int(NUM_SECONDS * input_fps) total_frames = cap.get(cv2.CAP_PROP_FRAME_COUNT) if num_frames == 0 else num_frames progress_bar = ProgressBar(total=total_frames) progress_bar.display() - + try: while cap.isOpened(): ret, image = cap.read() if not ret: cap.release() break - + if input_video_frame_nr >= total_frames: break - + h, w = image.shape[:-1] input_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) / 255.0 input_image = transform({"image": input_image})["image"] # Reshape the image to network input shape NCHW. input_image = np.expand_dims(input_image, 0) - + # Do inference. inference_start_time = time.perf_counter() result = compiled_model(input_image)[0] inference_stop_time = time.perf_counter() inference_duration = inference_stop_time - inference_start_time total_inference_duration += inference_duration - + if input_video_frame_nr % (10 * ADVANCE_FRAMES) == 0: clear_output(wait=True) progress_bar.display() @@ -556,7 +556,7 @@ Run inference on video f"({1/inference_duration:.2f} FPS)" ) ) - + # Transform the network result to a RGB image. result_frame = to_rgb(convert_result_to_image(result)) # Resize the image and the result to a target frame shape. @@ -566,13 +566,13 @@ Run inference on video stacked_frame = np.hstack((image, result_frame)) # Save a frame to the video. out_video.write(stacked_frame) - + input_video_frame_nr = input_video_frame_nr + ADVANCE_FRAMES cap.set(1, input_video_frame_nr) - + progress_bar.progress = input_video_frame_nr progress_bar.update() - + except KeyboardInterrupt: print("Processing interrupted.") finally: @@ -582,7 +582,7 @@ Run inference on video cap.release() end_time = time.perf_counter() duration = end_time - start_time - + print( f"Processed {processed_frames} frames in {duration:.2f} seconds. " f"Total FPS (including video processing): {processed_frames/duration:.2f}." @@ -598,7 +598,7 @@ Run inference on video .. parsed-literal:: - Processed 60 frames in 13.11 seconds. Total FPS (including video processing): 4.58.Inference FPS: 10.66 + Processed 60 frames in 13.11 seconds. Total FPS (including video processing): 4.58.Inference FPS: 10.66 Video saved to 'output/Coco Walking in Berkeley_depth_anything.mp4'. @@ -626,7 +626,7 @@ Run inference on video Showing video saved at /opt/home/k8sworker/ci-ai/cibuilds/jobs/ov-notebook/jobs/OVNotebookOps/builds/835/archive/.workspace/scm/ov-notebook/notebooks/depth-anything/Depth-Anything/output/Coco Walking in Berkeley_depth_anything.mp4 - If you cannot see the video in your browser, please click on the following link to download the video + If you cannot see the video in your browser, please click on the following link to download the video @@ -668,7 +668,7 @@ improve model inference speed. .. code:: ipython3 to_quantize = quantization_widget() - + to_quantize @@ -687,9 +687,9 @@ improve model inference speed. url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py", ) open("skip_kernel_extension.py", "w").write(r.text) - + OV_DEPTH_ANYTHING_INT8_PATH = Path(f"{model_id}_int8.xml") - + %load_ext skip_kernel_extension Prepare calibration dataset @@ -704,9 +704,9 @@ dataset from Hugging Face as calibration data. .. code:: ipython3 %%skip not $to_quantize.value - + import datasets - + if not OV_DEPTH_ANYTHING_INT8_PATH.exists(): subset_size = 300 calibration_data = [] @@ -737,9 +737,9 @@ quantization code below may take some time. .. code:: ipython3 %%skip not $to_quantize.value - + import nncf - + if not OV_DEPTH_ANYTHING_INT8_PATH.exists(): model = core.read_model(OV_DEPTH_ANYTHING_PATH) quantized_model = nncf.quantize( @@ -822,11 +822,11 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + def visualize_results(orig_img:Image.Image, optimized_img:Image.Image): """ Helper function for results visualization - + Parameters: orig_img (Image.Image): generated image using FP16 model optimized_img (Image.Image): generated image using quantized model @@ -848,7 +848,7 @@ data. list_axes[1].imshow(np.array(optimized_img)) list_axes[0].set_title(orig_title, fontsize=15) list_axes[1].set_title(control_title, fontsize=15) - + fig.subplots_adjust(wspace=0.01, hspace=0.01) fig.tight_layout() return fig @@ -856,11 +856,11 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + image = cv2.cvtColor(cv2.imread('furseal.png'), cv2.COLOR_BGR2RGB) / 255.0 image = transform({'image': image})['image'] image = torch.from_numpy(image).unsqueeze(0) - + int8_compiled_model = core.compile_model(OV_DEPTH_ANYTHING_INT8_PATH, device.value) int8_res = int8_compiled_model(image)[0] int8_depth_color = get_depth_map(int8_res) @@ -868,7 +868,7 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + visualize_results(depth_color[:, :, ::-1], int8_depth_color[:, :, ::-1]) @@ -879,7 +879,7 @@ data. .. code:: ipython3 %%skip not $to_quantize.value - + int8_result_video_path = output_directory / f"{Path(VIDEO_FILE).stem}_depth_anything_int8.mp4" stacked_frame = process_video(int8_compiled_model, VIDEO_FILE, int8_result_video_path) display_video(stacked_frame) @@ -887,11 +887,11 @@ data. .. parsed-literal:: - Processed 60 frames in 12.65 seconds. Total FPS (including video processing): 4.74.Inference FPS: 12.89 + Processed 60 frames in 12.65 seconds. Total FPS (including video processing): 4.74.Inference FPS: 12.89 Video saved to 'output/Coco Walking in Berkeley_depth_anything_int8.mp4'. Showing video saved at /opt/home/k8sworker/ci-ai/cibuilds/jobs/ov-notebook/jobs/OVNotebookOps/builds/835/archive/.workspace/scm/ov-notebook/notebooks/depth-anything/Depth-Anything/output/Coco Walking in Berkeley_depth_anything.mp4 - If you cannot see the video in your browser, please click on the following link to download the video + If you cannot see the video in your browser, please click on the following link to download the video @@ -917,10 +917,10 @@ Compare model file size .. code:: ipython3 %%skip not $to_quantize.value - + fp16_ir_model_size = OV_DEPTH_ANYTHING_PATH.with_suffix(".bin").stat().st_size / 2**20 quantized_model_size = OV_DEPTH_ANYTHING_INT8_PATH.with_suffix(".bin").stat().st_size / 2**20 - + print(f"FP16 model size: {fp16_ir_model_size:.2f} MB") print(f"INT8 model size: {quantized_model_size:.2f} MB") print(f"Model compression rate: {fp16_ir_model_size / quantized_model_size:.3f}") @@ -940,7 +940,7 @@ Compare inference time of the FP16 and INT8 models To measure the inference performance of OpenVINO FP16 and INT8 models, use `Benchmark -Tool `__. +Tool `__. **NOTE**: For the most accurate performance estimation, it is recommended to run ``benchmark_app`` in a terminal/command prompt @@ -949,19 +949,19 @@ Tool =2024.5.0" "nncf>=2.14.0" %pip install -q "torch>=2.2.0" "torchaudio>=2.2.0" "torchvision>=0.17.0" --extra-index-url https://download.pytorch.org/whl/cpu %pip install -q opencv-python "gradio>=4.13" "matplotlib>=3.4" tqdm - + if platform.system() == "Darwin": %pip install -q "numpy<2.0.0" @@ -105,8 +105,8 @@ Prerequisites import requests from pathlib import Path - - + + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py", ) @@ -124,18 +124,18 @@ Prerequisites .. code:: ipython3 from cmd_helper import clone_repo - - + + repo_dir = clone_repo("https://github.com/yformer/EfficientSAM.git") - + %cd $repo_dir - - + + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) open("notebook_utils.py", "w").write(r.text) - + from notebook_utils import download_file, device_widget, quantization_widget # noqa: F401 @@ -170,12 +170,12 @@ one of them as example. build_efficient_sam_vits, ) import zipfile - + MODELS_LIST = { "efficient-sam-vitt": build_efficient_sam_vitt, "efficient-sam-vits": build_efficient_sam_vits, } - + # Since EfficientSAM-S checkpoint file is >100MB, we store the zip file. with zipfile.ZipFile("weights/efficient_sam_vits.pt.zip", "r") as zip_ref: zip_ref.extractall("weights") @@ -185,16 +185,16 @@ Select one from supported models: .. code:: ipython3 import ipywidgets as widgets - + model_ids = list(MODELS_LIST) - + model_id = widgets.Dropdown( options=model_ids, value=model_ids[0], description="Model:", disabled=False, ) - + model_id @@ -211,7 +211,7 @@ build PyTorch model .. code:: ipython3 pt_model = MODELS_LIST[model_id.value]() - + pt_model.eval(); @@ -244,9 +244,9 @@ bounding box, 3 - right-bottom point of bounding box. .. code:: ipython3 from PIL import Image - + image_path = "figs/examples/dogs.jpg" - + image = Image.open(image_path) image @@ -273,8 +273,8 @@ points. We also provided some helper function for results visualization. import torch import matplotlib.pyplot as plt import numpy as np - - + + def prepare_input(input_image, points, labels, torch_tensor=True): img_tensor = np.ascontiguousarray(input_image)[None, ...].astype(np.float32) / 255 img_tensor = np.transpose(img_tensor, (0, 3, 1, 2)) @@ -285,16 +285,16 @@ points. We also provided some helper function for results visualization. pts_sampled = torch.from_numpy(pts_sampled) pts_labels = torch.from_numpy(pts_labels) return img_tensor, pts_sampled, pts_labels - - + + def postprocess_results(predicted_iou, predicted_logits): sorted_ids = np.argsort(-predicted_iou, axis=-1) predicted_iou = np.take_along_axis(predicted_iou, sorted_ids, axis=2) predicted_logits = np.take_along_axis(predicted_logits, sorted_ids[..., None, None], axis=2) - + return predicted_logits[0, 0, 0, :, :] >= 0 - - + + def show_points(coords, labels, ax, marker_size=375): pos_points = coords[labels == 1] neg_points = coords[labels == 0] @@ -316,14 +316,14 @@ points. We also provided some helper function for results visualization. edgecolor="white", linewidth=1.25, ) - - + + def show_box(box, ax): x0, y0 = box[0], box[1] w, h = box[2] - box[0], box[3] - box[1] ax.add_patch(plt.Rectangle((x0, y0), w, h, edgecolor="yellow", facecolor=(0, 0, 0, 0), lw=5)) - - + + def show_anns(mask, ax): ax.set_autoscale_on(False) img = np.ones((mask.shape[0], mask.shape[1], 4)) @@ -340,17 +340,17 @@ The complete model inference example demonstrated below input_points = [[580, 350], [650, 350]] input_labels = [1, 1] - + example_input = prepare_input(image, input_points, input_labels) - + predicted_logits, predicted_iou = pt_model(*example_input) - + predicted_mask = postprocess_results(predicted_iou.detach().numpy(), predicted_logits.detach().numpy()) .. code:: ipython3 image = Image.open(image_path) - + plt.figure(figsize=(20, 20)) plt.axis("off") plt.imshow(image) @@ -378,7 +378,7 @@ Convert model to OpenVINO IR format OpenVINO supports PyTorch models via conversion in Intermediate Representation (IR) format using OpenVINO `Model Conversion -API `__. +API `__. ``openvino.convert_model`` function accepts instance of PyTorch model and example input (that helps in correct model operation tracing and shape inference) and returns ``openvino.Model`` object that represents @@ -389,11 +389,11 @@ disk using ``openvino.save_model``. .. code:: ipython3 import openvino as ov - + core = ov.Core() - + ov_model_path = Path(f"{model_id.value}.xml") - + if not ov_model_path.exists(): ov_model = ov.convert_model(pt_model, example_input=example_input) ov.save_model(ov_model, ov_model_path) @@ -436,7 +436,7 @@ Select inference device from dropdown list .. code:: ipython3 device = device_widget() - + device @@ -468,11 +468,11 @@ Now, we can take a look on OpenVINO model prediction example_input = prepare_input(image, input_points, input_labels, torch_tensor=False) result = compiled_model(example_input) - + predicted_logits, predicted_iou = result[0], result[1] - + predicted_mask = postprocess_results(predicted_iou, predicted_logits) - + plt.figure(figsize=(20, 20)) plt.axis("off") plt.imshow(image) @@ -522,7 +522,7 @@ quantization. .. code:: ipython3 to_quantize = quantization_widget() - + to_quantize @@ -538,12 +538,12 @@ quantization. # Fetch `skip_kernel_extension` module import requests - + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/skip_kernel_extension.py", ) open("skip_kernel_extension.py", "w").write(r.text) - + %load_ext skip_kernel_extension Prepare calibration datasets @@ -561,14 +561,14 @@ creates DataLoader for preparing inputs for EfficientSAM model. .. code:: ipython3 %%skip not $to_quantize.value - + from zipfile import ZipFile - + DATA_URL = "https://ultralytics.com/assets/coco128.zip" OUT_DIR = Path('.') - + download_file(DATA_URL, directory=OUT_DIR, show_progress=True) - + if not (OUT_DIR / "coco128/images/train2017").exists(): with ZipFile('coco128.zip' , "r") as zip_ref: zip_ref.extractall(OUT_DIR) @@ -583,21 +583,21 @@ creates DataLoader for preparing inputs for EfficientSAM model. .. code:: ipython3 %%skip not $to_quantize.value - + import torch.utils.data as data - + class COCOLoader(data.Dataset): def __init__(self, images_path): self.images = list(Path(images_path).iterdir()) self.labels_dir = images_path.parents[1] / 'labels' / images_path.name - + def get_points(self, image_path, image_width, image_height): file_name = image_path.name.replace('.jpg', '.txt') label_file = self.labels_dir / file_name if not label_file.exists(): x1, x2 = np.random.randint(low=0, high=image_width, size=(2, )) y1, y2 = np.random.randint(low=0, high=image_height, size=(2, )) - else: + else: with label_file.open("r") as f: box_line = f.readline() _, x1, y1, x2, y2 = box_line.split() @@ -606,7 +606,7 @@ creates DataLoader for preparing inputs for EfficientSAM model. x2 = int(float(x2) * image_width) y2 = int(float(y2) * image_height) return [[x1, y1], [x2, y2]] - + def __getitem__(self, index): image_path = self.images[index] image = Image.open(image_path) @@ -616,14 +616,14 @@ creates DataLoader for preparing inputs for EfficientSAM model. labels = [1, 1] if index % 2 == 0 else [2, 3] batched_images, batched_points, batched_point_labels = prepare_input(image, points, labels, torch_tensor=False) return {'batched_images': np.ascontiguousarray(batched_images)[0], 'batched_points': np.ascontiguousarray(batched_points)[0], 'batched_point_labels': np.ascontiguousarray(batched_point_labels)[0]} - + def __len__(self): return len(self.images) .. code:: ipython3 %%skip not $to_quantize.value - + coco_dataset = COCOLoader(OUT_DIR / 'coco128/images/train2017') calibration_loader = torch.utils.data.DataLoader(coco_dataset) @@ -646,11 +646,11 @@ architecture type, we should specify ``transformer`` in ``model_type``. .. code:: ipython3 %%skip not $to_quantize.value - + import nncf - + calibration_dataset = nncf.Dataset(calibration_loader) - + model = core.read_model(ov_model_path) quantized_model = nncf.quantize(model, calibration_dataset, @@ -737,15 +737,15 @@ Verify quantized model inference .. code:: ipython3 %%skip not $to_quantize.value - + compiled_model = core.compile_model(quantized_model, device.value) - + result = compiled_model(example_input) - + predicted_logits, predicted_iou = result[0], result[1] - + predicted_mask = postprocess_results(predicted_iou, predicted_logits) - + plt.figure(figsize=(20, 20)) plt.axis("off") plt.imshow(image) @@ -774,7 +774,7 @@ Save quantize model on disk .. code:: ipython3 %%skip not $to_quantize.value - + quantized_model_path = Path(f"{model_id.value}_int8.xml") ov.save_model(quantized_model, quantized_model_path) @@ -786,10 +786,10 @@ Compare quantized model size .. code:: ipython3 %%skip not $to_quantize.value - + fp16_weights = ov_model_path.with_suffix('.bin') quantized_weights = quantized_model_path.with_suffix('.bin') - + print(f"Size of FP16 model is {fp16_weights.stat().st_size / 1024 / 1024:.2f} MB") print(f"Size of INT8 quantized model is {quantized_weights.stat().st_size / 1024 / 1024:.2f} MB") print(f"Compression rate for INT8 model: {fp16_weights.stat().st_size / quantized_weights.stat().st_size:.3f}") @@ -826,12 +826,12 @@ models, we use ``bencmark_app``. [Step 2/11] Loading OpenVINO Runtime [ INFO ] OpenVINO: [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] + [ INFO ] [ INFO ] Device info: [ INFO ] AUTO [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] - [ INFO ] + [ INFO ] + [ INFO ] [Step 3/11] Setting device configuration [ WARNING ] Performance hint was not explicitly specified in command line. Device(AUTO) performance hint will be set to PerformanceMode.THROUGHPUT. [Step 4/11] Reading model files @@ -892,9 +892,9 @@ models, we use ``bencmark_app``. [ WARNING ] No input files were given for input 'batched_images'!. This input will be filled with random values! [ WARNING ] No input files were given for input 'batched_points'!. This input will be filled with random values! [ WARNING ] No input files were given for input 'batched_point_labels'!. This input will be filled with random values! - [ INFO ] Fill input 'batched_images' with random values - [ INFO ] Fill input 'batched_points' with random values - [ INFO ] Fill input 'batched_point_labels' with random values + [ INFO ] Fill input 'batched_images' with random values + [ INFO ] Fill input 'batched_points' with random values + [ INFO ] Fill input 'batched_point_labels' with random values [Step 10/11] Measuring performance (Start inference asynchronously, 6 inference requests, limits: 15000 ms duration) [ INFO ] Benchmarking in full mode (inputs filling are included in measurement loop). [ INFO ] First inference took 850.98 ms @@ -923,12 +923,12 @@ models, we use ``bencmark_app``. [Step 2/11] Loading OpenVINO Runtime [ INFO ] OpenVINO: [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] + [ INFO ] [ INFO ] Device info: [ INFO ] AUTO [ INFO ] Build ................................. 2024.4.0-16579-c3152d32c9c-releases/2024/4 - [ INFO ] - [ INFO ] + [ INFO ] + [ INFO ] [Step 3/11] Setting device configuration [ WARNING ] Performance hint was not explicitly specified in command line. Device(AUTO) performance hint will be set to PerformanceMode.THROUGHPUT. [Step 4/11] Reading model files @@ -989,9 +989,9 @@ models, we use ``bencmark_app``. [ WARNING ] No input files were given for input 'batched_images'!. This input will be filled with random values! [ WARNING ] No input files were given for input 'batched_points'!. This input will be filled with random values! [ WARNING ] No input files were given for input 'batched_point_labels'!. This input will be filled with random values! - [ INFO ] Fill input 'batched_images' with random values - [ INFO ] Fill input 'batched_points' with random values - [ INFO ] Fill input 'batched_point_labels' with random values + [ INFO ] Fill input 'batched_images' with random values + [ INFO ] Fill input 'batched_points' with random values + [ INFO ] Fill input 'batched_point_labels' with random values [Step 10/11] Measuring performance (Start inference asynchronously, 6 inference requests, limits: 15000 ms duration) [ INFO ] Benchmarking in full mode (inputs filling are included in measurement loop). [ INFO ] First inference took 586.73 ms @@ -1018,18 +1018,18 @@ Interactive segmentation demo from PIL import Image import cv2 import matplotlib.pyplot as plt - - + + def sigmoid(x): return 1 / (1 + np.exp(-x)) - - + + def format_results(masks, scores, logits, filter=0): annotations = [] n = len(scores) for i in range(n): annotation = {} - + mask = masks[i] tmp = np.where(mask != 0) if np.sum(mask) < filter: @@ -1046,8 +1046,8 @@ Interactive segmentation demo annotation["area"] = annotation["segmentation"].sum() annotations.append(annotation) return annotations - - + + def point_prompt(masks, points, point_label, target_height, target_width): # numpy h = masks[0]["segmentation"].shape[0] w = masks[0]["segmentation"].shape[1] @@ -1067,8 +1067,8 @@ Interactive segmentation demo onemask -= mask onemask = onemask >= 1 return onemask, 0 - - + + def show_mask( annotation, ax, @@ -1085,7 +1085,7 @@ Interactive segmentation demo areas = np.sum(annotation, axis=(1, 2)) sorted_indices = np.argsort(areas)[::1] annotation = annotation[sorted_indices] - + index = (annotation != 0).argmax(axis=0) if random_color: color = np.random.random((mask_sum, 1, 1, 3)) @@ -1094,23 +1094,23 @@ Interactive segmentation demo transparency = np.ones((mask_sum, 1, 1, 1)) * 0.6 visual = np.concatenate([color, transparency], axis=-1) mask_image = np.expand_dims(annotation, -1) * visual - + mask = np.zeros((height, weight, 4)) - + h_indices, w_indices = np.meshgrid(np.arange(height), np.arange(weight), indexing="ij") indices = (index[h_indices, w_indices], h_indices, w_indices, slice(None)) - + mask[h_indices, w_indices, :] = mask_image[indices] if bbox is not None: x1, y1, x2, y2 = bbox ax.add_patch(plt.Rectangle((x1, y1), x2 - x1, y2 - y1, fill=False, edgecolor="b", linewidth=1)) - + if not retinamask: mask = cv2.resize(mask, (target_width, target_height), interpolation=cv2.INTER_NEAREST) - + return mask - - + + def process( annotations, image, @@ -1124,7 +1124,7 @@ Interactive segmentation demo ): if isinstance(annotations[0], dict): annotations = [annotation["segmentation"] for annotation in annotations] - + original_h = image.height original_w = image.width if better_quality: @@ -1143,10 +1143,10 @@ Interactive segmentation demo target_height=original_h, target_width=original_w, ) - + if isinstance(annotations, torch.Tensor): annotations = annotations.cpu().numpy() - + if withContours: contour_all = [] temp = np.zeros((original_h, original_w, 1)) @@ -1166,18 +1166,18 @@ Interactive segmentation demo cv2.drawContours(temp, contour_all, -1, (255, 255, 255), 2 // scale) color = np.array([0 / 255, 0 / 255, 255 / 255, 0.9]) contour_mask = temp / 255 * color.reshape(1, 1, -1) - + image = image.convert("RGBA") overlay_inner = Image.fromarray((inner_mask * 255).astype(np.uint8), "RGBA") image.paste(overlay_inner, (0, 0), overlay_inner) - + if withContours: overlay_contour = Image.fromarray((contour_mask * 255).astype(np.uint8), "RGBA") image.paste(overlay_contour, (0, 0), overlay_contour) - + return image - - + + def segment_with_boxs( image, seg_image, @@ -1191,48 +1191,48 @@ Interactive segmentation demo ): if global_points is None or len(global_points) < 2 or global_points[0] is None: return image, global_points, global_point_label - + input_size = int(input_size) w, h = image.size scale = input_size / max(w, h) new_w = int(w * scale) new_h = int(h * scale) image = image.resize((new_w, new_h)) - + scaled_points = np.array([[int(x * scale) for x in point] for point in global_points]) scaled_points = scaled_points[:2] scaled_point_label = np.array(global_point_label)[:2] - + if scaled_points.size == 0 and scaled_point_label.size == 0: return image, global_points, global_point_label - + nd_image = np.array(image) img_tensor = nd_image.astype(np.float32) / 255 img_tensor = np.transpose(img_tensor, (2, 0, 1)) - + pts_sampled = np.reshape(scaled_points, [1, 1, -1, 2]) pts_sampled = pts_sampled[:, :, :2, :] pts_labels = np.reshape(np.array([2, 3]), [1, 1, 2]) - + results = compiled_model([img_tensor[None, ...], pts_sampled, pts_labels]) predicted_logits = results[0] predicted_iou = results[1] all_masks = sigmoid(predicted_logits[0, 0, :, :, :]) >= 0.5 predicted_iou = predicted_iou[0, 0, ...] - + max_predicted_iou = -1 selected_mask_using_predicted_iou = None selected_predicted_iou = None - + for m in range(all_masks.shape[0]): curr_predicted_iou = predicted_iou[m] if curr_predicted_iou > max_predicted_iou or selected_mask_using_predicted_iou is None: max_predicted_iou = curr_predicted_iou selected_mask_using_predicted_iou = all_masks[m : m + 1] selected_predicted_iou = predicted_iou[m : m + 1] - + results = format_results(selected_mask_using_predicted_iou, selected_predicted_iou, predicted_logits, 0) - + annotations = results[0]["segmentation"] annotations = np.array([annotations]) fig = process( @@ -1245,12 +1245,12 @@ Interactive segmentation demo bbox=scaled_points.reshape([4]), withContours=withContours, ) - + global_points = [] global_point_label = [] return fig, global_points, global_point_label - - + + def segment_with_points( image, global_points, @@ -1267,32 +1267,32 @@ Interactive segmentation demo new_w = int(w * scale) new_h = int(h * scale) image = image.resize((new_w, new_h)) - + if global_points is None or len(global_points) < 1 or global_points[0] is None: return image, global_points, global_point_label scaled_points = np.array([[int(x * scale) for x in point] for point in global_points]) scaled_point_label = np.array(global_point_label) - + if scaled_points.size == 0 and scaled_point_label.size == 0: return image, global_points, global_point_label - + nd_image = np.array(image) img_tensor = (nd_image).astype(np.float32) / 255 img_tensor = np.transpose(img_tensor, (2, 0, 1)) - + pts_sampled = np.reshape(scaled_points, [1, 1, -1, 2]) pts_labels = np.reshape(np.array(global_point_label), [1, 1, -1]) - + results = compiled_model([img_tensor[None, ...], pts_sampled, pts_labels]) predicted_logits = results[0] predicted_iou = results[1] all_masks = sigmoid(predicted_logits[0, 0, :, :, :]) >= 0.5 predicted_iou = predicted_iou[0, 0, ...] - + results = format_results(all_masks, predicted_iou, predicted_logits, 0) annotations, _ = point_prompt(results, scaled_points, scaled_point_label, new_h, new_w) annotations = np.array([annotations]) - + fig = process( annotations=annotations, image=image, @@ -1304,7 +1304,7 @@ Interactive segmentation demo use_retina=use_retina, withContours=withContours, ) - + global_points = [] global_point_label = [] # return fig, None @@ -1314,15 +1314,15 @@ Interactive segmentation demo # Go back to the efficient-sam notebook directory %cd .. - + if not Path("gradio_helper.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/efficient-sam/gradio_helper.py") open("gradio_helper.py", "w").write(r.text) - + from gradio_helper import make_demo - + demo = make_demo(segment_with_point_fn=segment_with_points, segment_with_box_fn=segment_with_boxs) - + try: demo.queue().launch(debug=False) except Exception: @@ -1336,7 +1336,7 @@ Interactive segmentation demo /opt/home/k8sworker/ci-ai/cibuilds/jobs/ov-notebook/jobs/OVNotebookOps/builds/835/archive/.workspace/scm/ov-notebook/notebooks/efficient-sam Running on local URL: http://127.0.0.1:7860 - + To create a public link, set `share=True` in `launch()`. diff --git a/docs/notebooks/florence2-with-output.rst b/docs/notebooks/florence2-with-output.rst index 7ec9ce6e6557ca..7e9a8df4be6e6b 100644 --- a/docs/notebooks/florence2-with-output.rst +++ b/docs/notebooks/florence2-with-output.rst @@ -63,16 +63,16 @@ Prerequisites import requests from pathlib import Path - + if not Path("ov_florence2_helper.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/florence2/ov_florence2_helper.py") open("ov_florence2_helper.py", "w").write(r.text) - - + + if not Path("gradio_helper.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/florence2/gradio_helper.py") open("gradio_helper.py", "w").write(r.text) - + if not Path("notebook_utils.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py") open("notebook_utils.py", "w").write(r.text) @@ -92,9 +92,9 @@ available model. By default, we will use .. code:: ipython3 from ov_florence2_helper import convert_florence2, get_model_selector - + model_selector = get_model_selector() - + model_selector @@ -122,7 +122,7 @@ Convert model Florence2 is PyTorch model. OpenVINO supports PyTorch models via conversion to OpenVINO Intermediate Representation (IR). `OpenVINO model conversion -API `__ +API `__ should be used for these purposes. ``ov.convert_model`` function accepts original PyTorch model instance and example input for tracing and returns ``ov.Model`` representing this model in OpenVINO framework. @@ -169,7 +169,7 @@ pipeline. model_id = model_selector.value model_path = Path(model_id.split("/")[-1]) - + # Uncomment the line to see conversion code # ??convert_florence2 @@ -363,9 +363,9 @@ Select inference device .. code:: ipython3 from notebook_utils import device_widget - + device = device_widget() - + device @@ -390,7 +390,7 @@ will use ``generate`` method. .. code:: ipython3 from ov_florence2_helper import OVFlorence2Model - + # Uncomment the line to see model class code # ??OVFlorence2Model @@ -407,16 +407,16 @@ responsible for input data preparation and decoding model output. import requests from PIL import Image - + from transformers import AutoProcessor - + processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True) - + prompt = "" - + url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true" image = Image.open(requests.get(url, stream=True).raw) - + image @@ -431,16 +431,16 @@ Let’s check model capabilities in Object Detection. .. code:: ipython3 inputs = processor(text=prompt, images=image, return_tensors="pt") - + generated_ids = model.generate(input_ids=inputs["input_ids"], pixel_values=inputs["pixel_values"], max_new_tokens=1024, do_sample=False, num_beams=3) generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0] - + parsed_answer = processor.post_process_generation(generated_text, task="", image_size=(image.width, image.height)) .. code:: ipython3 from gradio_helper import plot_bbox - + fig = plot_bbox(image, parsed_answer[""]) @@ -610,9 +610,9 @@ image, providing both text and region information. .. code:: ipython3 from gradio_helper import make_demo - + demo = make_demo(model, processor) - + try: demo.launch(debug=False, height=600) except Exception: @@ -625,7 +625,7 @@ image, providing both text and region information. .. parsed-literal:: Running on local URL: http://127.0.0.1:7860 - + To create a public link, set `share=True` in `launch()`. diff --git a/docs/notebooks/flux.1-image-generation-with-output.rst b/docs/notebooks/flux.1-image-generation-with-output.rst index fe0c47899c3601..945e16ee3dfb9b 100644 --- a/docs/notebooks/flux.1-image-generation-with-output.rst +++ b/docs/notebooks/flux.1-image-generation-with-output.rst @@ -60,15 +60,15 @@ Prerequisites import requests from pathlib import Path - + if not Path("cmd_helper.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py") open("cmd_helper.py", "w").write(r.text) - + if not Path("gradio_helper.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/flux.1-image-generation/gradio_helper.py") open("gradio_helper.py", "w").write(r.text) - + if not Path("notebook_utils.py").exists(): r = requests.get(url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py") open("notebook_utils.py", "w").write(r.text) @@ -106,16 +106,16 @@ FLUX.1-dev version using widget bellow. .. code:: ipython3 import ipywidgets as widgets - + model_ids = ["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-dev"] - + model_selector = widgets.Dropdown( options=model_ids, default=model_ids[0], description="Model:", ) - - + + model_selector @@ -141,9 +141,9 @@ FLUX.1-dev version using widget bellow. .. code:: ipython3 # uncomment these lines to login to huggingfacehub to get access to pretrained model - + # from huggingface_hub import notebook_login, whoami - + # try: # whoami() # print('Authorization token already provided') @@ -211,7 +211,7 @@ Compress model weights For reducing model memory consumption we will use weights compression. The `Weights -Compression `__ +Compression `__ algorithm is aimed at compressing the weights of the models and can be used to optimize the model footprint and performance of large models where the size of weights is relatively larger than the size of @@ -228,7 +228,7 @@ introduces a minor drop in prediction quality. We will use description="Weight compression", disabled=False, ) - + to_compress @@ -243,12 +243,12 @@ introduces a minor drop in prediction quality. We will use .. code:: ipython3 from pathlib import Path - + model_id = model_selector.value - + model_base_dir = Path(model_id.split("/")[-1]) additional_args = {} - + if to_compress.value: model_dir = model_base_dir / "INT4" additional_args.update({"weight-format": "int4", "group-size": "64", "ratio": "1.0"}) @@ -259,7 +259,7 @@ introduces a minor drop in prediction quality. We will use .. code:: ipython3 from cmd_helper import optimum_cli - + if not model_dir.exists(): optimum_cli(model_id, model_dir, additional_args=additional_args) @@ -280,7 +280,7 @@ additionally will trigger model conversion). .. code:: ipython3 from notebook_utils import device_widget - + device = device_widget(default="CPU", exclude=["NPU"]) device @@ -296,14 +296,14 @@ additionally will trigger model conversion). .. code:: ipython3 import ipywidgets as widgets - + model_available = (model_base_dir / "INT4").is_dir() use_quantized_models = widgets.Checkbox( value=model_available, description="Use compressed models", disabled=not model_available, ) - + use_quantized_models @@ -318,9 +318,9 @@ additionally will trigger model conversion). .. code:: ipython3 from optimum.intel.openvino import OVDiffusionPipeline - + model_dir = model_base_dir / "INT4" if use_quantized_models.value else model_base_dir / "FP16" - + ov_pipe = OVDiffusionPipeline.from_pretrained(model_dir, device=device.value) @@ -334,17 +334,17 @@ additionally will trigger model conversion). 2024-10-28 18:12:30.761443: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers - + .. code:: ipython3 import torch - + prompt = "A cat holding a sign that says hello OpenVINO" image = ov_pipe( prompt, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256, generator=torch.Generator("cpu").manual_seed(0), height=256, width=256 ).images[0] - + image @@ -368,9 +368,9 @@ Interactive demo .. code:: ipython3 from gradio_helper import make_demo - + demo = make_demo(ov_pipe) - + # if you are launching remotely, specify server_name and server_port # demo.launch(server_name='your server name', server_port='server port in int') # if you have any issue to launch on your platform, you can pass share=True to launch method: diff --git a/docs/notebooks/freevc-voice-conversion-with-output.rst b/docs/notebooks/freevc-voice-conversion-with-output.rst index 69a935f4c4f78d..60d9a993e00b2a 100644 --- a/docs/notebooks/freevc-voice-conversion-with-output.rst +++ b/docs/notebooks/freevc-voice-conversion-with-output.rst @@ -86,14 +86,14 @@ Install extra requirements # Fetch `notebook_utils` module import requests - - + + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py", ) open("notebook_utils.py", "w").write(r.text) - - + + r = requests.get( url="https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py", ) @@ -111,20 +111,20 @@ Install extra requirements .. code:: ipython3 from pathlib import Path - + import gdown from cmd_helper import clone_repo from notebook_utils import download_file, device_widget - - + + clone_repo("https://github.com/OlaWod/FreeVC.git") - - + + wavlm_large_dir_path = Path("FreeVC/wavlm") wavlm_large_path = wavlm_large_dir_path / "WavLM-Large.pt" - + wavlm_url = "https://drive.google.com/uc?id=12-cB34qCTvByWT-QtOcZaqwwO21FLSqU&confirm=t&uuid=a703c43c-ccce-436c-8799-c11b88e9e7e4" - + if not wavlm_large_path.exists(): gdown.download(wavlm_url, str(wavlm_large_path)) @@ -142,7 +142,7 @@ Install extra requirements freevc_chpt_dir = Path("checkpoints") freevc_chpt_name = "freevc.pth" freevc_chpt_path = freevc_chpt_dir / freevc_chpt_name - + if not freevc_chpt_path.exists(): download_file( f"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/models/freevc/{freevc_chpt_name}", @@ -162,10 +162,10 @@ Install extra requirements audio1_url = f"https://huggingface.co/spaces/OlaWod/FreeVC/resolve/main/{audio1_name}" audio2_name = "p226_002.wav" audio2_url = f"https://huggingface.co/spaces/OlaWod/FreeVC/resolve/main/{audio2_name}" - + if not Path(audio1_name).exists(): download_file(audio1_url) - + if not Path(audio2_name).exists(): download_file(audio2_url) @@ -192,20 +192,20 @@ Imports and settings import logging import os import time - + import librosa import numpy as np import torch from scipy.io.wavfile import write from tqdm import tqdm - + import openvino as ov - + import utils from models import SynthesizerTrn from speaker_encoder.voice_encoder import SpeakerEncoder from wavlm import WavLM, WavLMConfig - + logger = logging.getLogger() logger.setLevel(logging.CRITICAL) @@ -219,7 +219,7 @@ Redefine function ``get_model`` from ``utils`` to exclude CUDA cmodel = WavLM(cfg) cmodel.load_state_dict(checkpoint["model"]) cmodel.eval() - + return cmodel Models initialization @@ -228,9 +228,9 @@ Models initialization hps = utils.get_hparams_from_file("FreeVC/configs/freevc.json") os.makedirs("outputs/freevc", exist_ok=True) - + net_g = SynthesizerTrn(hps.data.filter_length // 2 + 1, hps.train.segment_size // hps.data.hop_length, **hps.model) - + utils.load_checkpoint(freevc_chpt_path, net_g, optimizer=None, strict=True) cmodel = get_cmodel() smodel = SpeakerEncoder("FreeVC/speaker_encoder/ckpt/pretrained_bak_5805000.pt", device="cpu") @@ -274,19 +274,19 @@ Inference # tgt wav_tgt, _ = librosa.load(tgt, sr=hps.data.sampling_rate) wav_tgt, _ = librosa.effects.trim(wav_tgt, top_db=20) - + g_tgt = smodel.embed_utterance(wav_tgt) g_tgt = torch.from_numpy(g_tgt).unsqueeze(0) - + # src wav_src, _ = librosa.load(src, sr=hps.data.sampling_rate) wav_src = torch.from_numpy(wav_src).unsqueeze(0) - + c = utils.get_content(cmodel, wav_src) - + tgt_audio = net_g.infer(c, g=g_tgt) tgt_audio = tgt_audio[0][0].data.cpu().float().numpy() - + timestamp = time.strftime("%m-%d_%H-%M", time.localtime()) write( os.path.join("outputs/freevc", "{}.wav".format(timestamp)), @@ -315,7 +315,7 @@ and to be loaded on a device using ``compile_model`` or can be saved on a disk using the ``ov.save_model`` function. The ``read_model`` method loads a saved model from a disk. For more information about model conversion, see this -`page `__. +`page `__. Convert Prior Encoder. ~~~~~~~~~~~~~~~~~~~~~~ @@ -335,13 +335,13 @@ OpenVINO’s IR format. We keep the original name of the model in code: OUTPUT_DIR = Path("output") BASE_MODEL_NAME = "cmodel" - + OUTPUT_DIR.mkdir(exist_ok=True) - + ir_cmodel_path = Path(OUTPUT_DIR / (BASE_MODEL_NAME + "_ir")).with_suffix(".xml") - + length = 32000 - + dummy_input = torch.randn(1, length) Converting to OpenVINO’s IR format. @@ -349,17 +349,17 @@ Converting to OpenVINO’s IR format. .. code:: ipython3 core = ov.Core() - - + + class ModelWrapper(torch.nn.Module): def __init__(self, model): super().__init__() self.model = model - + def forward(self, input): return self.model(input)[0] - - + + if not ir_cmodel_path.exists(): ir_cmodel = ov.convert_model(ModelWrapper(cmodel), example_input=dummy_input) ov.save_model(ir_cmodel, ir_cmodel_path) @@ -408,16 +408,16 @@ Convert ``SpeakerEncoder`` OUTPUT_DIR = Path("output") BASE_MODEL_NAME = "smodel" - + OUTPUT_DIR.mkdir(exist_ok=True) - + ir_smodel_path = Path(OUTPUT_DIR / (BASE_MODEL_NAME + "ir")).with_suffix(".xml") - - + + length = 32000 - + dummy_input = torch.randn(1, length, 40) - + if not ir_smodel_path.exists(): ir_smodel = ov.convert_model(smodel, example_input=dummy_input) ov.save_model(ir_smodel, ir_smodel_path) @@ -431,18 +431,18 @@ based on ``speaker_encoder.voice_encoder.SpeakerEncoder`` class methods from speaker_encoder.hparams import sampling_rate, mel_window_step, partials_n_frames from speaker_encoder import audio - - + + def compute_partial_slices(n_samples: int, rate, min_coverage): """ Computes where to split an utterance waveform and its corresponding mel spectrogram to obtain partial utterances of each. Both the waveform and the mel spectrogram slices are returned, so as to make each partial utterance waveform correspond to its spectrogram. - + The returned ranges may be indexing further than the length of the waveform. It is recommended that you pad the waveform with zeros up to wav_slices[-1].stop. - + :param n_samples: the number of samples in the waveform :param rate: how many partial utterances should occur per second. Partial utterances must cover the span of the entire utterance, thus the rate should not be lower than the inverse @@ -458,14 +458,14 @@ based on ``speaker_encoder.voice_encoder.SpeakerEncoder`` class methods utterances. """ assert 0 < min_coverage <= 1 - + # Compute how many frames separate two partial utterances samples_per_frame = int((sampling_rate * mel_window_step / 1000)) n_frames = int(np.ceil((n_samples + 1) / samples_per_frame)) frame_step = int(np.round((sampling_rate / rate) / samples_per_frame)) assert 0 < frame_step, "The rate is too high" assert frame_step <= partials_n_frames, "The rate is too low, it should be %f at least" % (sampling_rate / (samples_per_frame * partials_n_frames)) - + # Compute the slices wav_slices, mel_slices = [], [] steps = max(1, n_frames - partials_n_frames + frame_step + 1) @@ -474,17 +474,17 @@ based on ``speaker_encoder.voice_encoder.SpeakerEncoder`` class methods wav_range = mel_range * samples_per_frame mel_slices.append(slice(*mel_range)) wav_slices.append(slice(*wav_range)) - + # Evaluate whether extra padding is warranted or not last_wav_range = wav_slices[-1] coverage = (n_samples - last_wav_range.start) / (last_wav_range.stop - last_wav_range.start) if coverage < min_coverage and len(mel_slices) > 1: mel_slices = mel_slices[:-1] wav_slices = wav_slices[:-1] - + return wav_slices, mel_slices - - + + def embed_utterance( wav: np.ndarray, smodel: ov.CompiledModel, @@ -496,7 +496,7 @@ based on ``speaker_encoder.voice_encoder.SpeakerEncoder`` class methods Computes an embedding for a single utterance. The utterance is divided in partial utterances and an embedding is computed for each. The complete utterance embedding is the L2-normed average embedding of the partial utterances. - + :param wav: a preprocessed utterance waveform as a numpy array of float32 :param smodel: compiled speaker encoder model. :param return_partials: if True, the partial embeddings will also be returned along with @@ -521,7 +521,7 @@ based on ``speaker_encoder.voice_encoder.SpeakerEncoder`` class methods max_wave_length = wav_slices[-1].stop if max_wave_length >= len(wav): wav = np.pad(wav, (0, max_wave_length - len(wav)), "constant") - + # Split the utterance into partials and forward them through the model mel = audio.wav_to_mel_spectrogram(wav) mels = np.array([mel[s] for s in mel_slices]) @@ -529,11 +529,11 @@ based on ``speaker_encoder.voice_encoder.SpeakerEncoder`` class methods mels = torch.from_numpy(mels).to(torch.device("cpu")) output_layer = smodel.output(0) partial_embeds = smodel(mels)[output_layer] - + # Compute the utterance embedding from the partial embeddings raw_embed = np.mean(partial_embeds, axis=0) embed = raw_embed / np.linalg.norm(raw_embed, 2) - + if return_partials: return embed, partial_embeds, wav_slices return embed @@ -573,14 +573,14 @@ function to OpenVINO IR format. BASE_MODEL_NAME = "net_g" onnx_net_g_path = Path(OUTPUT_DIR / (BASE_MODEL_NAME + "_fp32")).with_suffix(".onnx") ir_net_g_path = Path(OUTPUT_DIR / (BASE_MODEL_NAME + "ir")).with_suffix(".xml") - + dummy_input_1 = torch.randn(1, 1024, 81) dummy_input_2 = torch.randn(1, 256) - + # define forward as infer net_g.forward = net_g.infer - - + + if not ir_net_g_path.exists(): ir_net_g_model = ov.convert_model(net_g, example_input=(dummy_input_1, dummy_input_2)) ov.save_model(ir_net_g_model, ir_net_g_path) @@ -592,7 +592,7 @@ function to OpenVINO IR format. /opt/home/k8sworker/ci-ai/cibuilds/jobs/ov-notebook/jobs/OVNotebookOps/builds/835/archive/.workspace/scm/ov-notebook/.venv/lib/python3.8/site-packages/torch/jit/_trace.py:1303: TracerWarning: Output nr 1. of the traced function does not match the corresponding output of the Python function. Detailed error: Tensor-likes are not close! - + Mismatched elements: 25885 / 25920 (99.9%) Greatest absolute difference: 0.11462387628853321 at index (0, 0, 1782) (up to 1e-05 allowed) Greatest relative difference: 71139.34281225452 at index (0, 0, 3236) (up to 1e-05 allowed) @@ -612,22 +612,22 @@ Define function for synthesizing. def synthesize_audio(src, tgt): wav_tgt, _ = librosa.load(tgt, sr=hps.data.sampling_rate) wav_tgt, _ = librosa.effects.trim(wav_tgt, top_db=20) - + g_tgt = embed_utterance(wav_tgt, compiled_smodel) g_tgt = torch.from_numpy(g_tgt).unsqueeze(0) - + # src wav_src, _ = librosa.load(src, sr=hps.data.sampling_rate) wav_src = np.expand_dims(wav_src, axis=0) - + output_layer = compiled_cmodel.output(0) c = compiled_cmodel(wav_src)[output_layer] c = c.transpose((0, 2, 1)) - + output_layer = compiled_ir_net_g_model.output(0) tgt_audio = compiled_ir_net_g_model((c, g_tgt))[output_layer] tgt_audio = tgt_audio[0][0] - + return tgt_audio And now we can check inference using only IR models. @@ -635,13 +635,13 @@ And now we can check inference using only IR models. .. code:: ipython3 result_wav_names = [] - + with torch.no_grad(): for line in tqdm(zip(srcs, tgts)): src, tgt = line - + output_audio = synthesize_audio(src, tgt) - + timestamp = time.strftime("%m-%d_%H-%M", time.localtime()) result_name = f"{timestamp}.wav" result_wav_names.append(result_name) @@ -666,7 +666,7 @@ Source audio (source of text): .. code:: ipython3 import IPython.display as ipd - + ipd.Audio(srcs[0]) @@ -674,7 +674,7 @@ Source audio (source of text): .. raw:: html - +