DOCS shift to rst - OpenVINO™ Samples and Get Started with C++ Samples (#16577)

This commit is contained in:
Maciej Smyk 2023-03-27 18:26:47 +02:00 committed by GitHub
parent 9863b32792
commit 6e99b48ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 383 additions and 307 deletions

View File

@ -32,69 +32,91 @@
openvino_inference_engine_samples_benchmark_app_README
openvino_inference_engine_tools_benchmark_tool_README
@endsphinxdirective
The OpenVINO™ samples are simple console applications that show how to utilize specific OpenVINO API capabilities within an application. They can assist you in executing specific tasks such as loading a model, running inference, querying specific device capabilities, etc.
If you installed OpenVINO Runtime via archive files, sample applications for С, and C++, and Python are created in the following directories:
* `<INSTALL_DIR>/samples/c`
* `<INSTALL_DIR>/samples/cpp`
* `<INSTALL_DIR>/samples/python`
If you installed OpenVINO via PyPI, download [the OpenVINO repository](https://github.com/openvinotoolkit/openvino/) and use samples from `samples/python`.
* ``<INSTALL_DIR>/samples/c``
* ``<INSTALL_DIR>/samples/cpp``
* ``<INSTALL_DIR>/samples/python``
If you installed OpenVINO via PyPI, download `the OpenVINO repository <https://github.com/openvinotoolkit/openvino/>`__ and use samples from ``samples/python``.
The applications include:
- **Speech Sample** - Acoustic model inference based on Kaldi neural networks and speech feature vectors.
- [Automatic Speech Recognition C++ Sample](../../samples/cpp/speech_sample/README.md)
- [Automatic Speech Recognition Python Sample](../../samples/python/speech_sample/README.md)
- **Hello Classification Sample** Inference of image classification networks like AlexNet and GoogLeNet using Synchronous Inference Request API. Input of any size and layout can be set to an infer request which will be pre-processed automatically during inference (the sample supports only images as inputs and supports Unicode paths).
- [Hello Classification C++ Sample](../../samples/cpp/hello_classification/README.md)
- [Hello Classification C Sample](../../samples/c/hello_classification/README.md)
- [Hello Classification Python Sample](../../samples/python/hello_classification/README.md)
- **Hello NV12 Input Classification Sample** Input of any size and layout can be provided to an infer request. The sample transforms the input to the NV12 color format and pre-process it automatically during inference. The sample supports only images as inputs.
- [Hello NV12 Input Classification C++ Sample](../../samples/cpp/hello_nv12_input_classification/README.md)
- [Hello NV12 Input Classification C Sample](../../samples/c/hello_nv12_input_classification/README.md)
- **Hello Query Device Sample** Query of available OpenVINO devices and their metrics, configuration values.
- [Hello Query Device C++ Sample](../../samples/cpp/hello_query_device/README.md)
- [Hello Query Device Python* Sample](../../samples/python/hello_query_device/README.md)
- **Hello Reshape SSD Sample** Inference of SSD networks resized by ShapeInfer API according to an input size.
- [Hello Reshape SSD C++ Sample**](../../samples/cpp/hello_reshape_ssd/README.md)
- [Hello Reshape SSD Python Sample**](../../samples/python/hello_reshape_ssd/README.md)
- **Image Classification Sample Async** Inference of image classification networks like AlexNet and GoogLeNet using Asynchronous Inference Request API (the sample supports only images as inputs).
- [Image Classification Async C++ Sample](../../samples/cpp/classification_sample_async/README.md)
- [Image Classification Async Python* Sample](../../samples/python/classification_sample_async/README.md)
- **OpenVINO Model Creation Sample** Construction of the LeNet model using the OpenVINO model creation sample.
- [OpenVINO Model Creation C++ Sample](../../samples/cpp/model_creation_sample/README.md)
- [OpenVINO Model Creation Python Sample](../../samples/python/model_creation_sample/README.md)
- **Benchmark Samples** - Simple estimation of a model inference performance
- [Sync Benchmark C++ Sample](../../samples/cpp/benchmark/sync_benchmark/README.md)
- [Sync Benchmark Python* Sample](../../samples/python/benchmark/sync_benchmark/README.md)
- [Throughput Benchmark C++ Sample](../../samples/cpp/benchmark/throughput_benchmark/README.md)
- [Throughput Benchmark Python* Sample](../../samples/python/benchmark/throughput_benchmark/README.md)
- [Bert Benchmark Python* Sample](../../samples/python/benchmark/bert_benchmark/README.md)
- :doc:`Automatic Speech Recognition C++ Sample <openvino_inference_engine_samples_speech_sample_README>`
- :doc:`Automatic Speech Recognition Python Sample <openvino_inference_engine_ie_bridges_python_sample_speech_sample_README>`
- **Hello Classification Sample** Inference of image classification networks like AlexNet and GoogLeNet using Synchronous Inference Request API. Input of any size and layout can be set to an infer request which will be pre-processed automatically during inference (the sample supports only images as inputs and supports Unicode paths).
- :doc:`Hello Classification C++ Sample <openvino_inference_engine_samples_hello_classification_README>`
- :doc:`Hello Classification C Sample <openvino_inference_engine_ie_bridges_c_samples_hello_classification_README>`
- :doc:`Hello Classification Python Sample <openvino_inference_engine_ie_bridges_python_sample_hello_classification_README>`
- **Hello NV12 Input Classification Sample** Input of any size and layout can be provided to an infer request. The sample transforms the input to the NV12 color format and pre-process it automatically during inference. The sample supports only images as inputs.
- :doc:`Hello NV12 Input Classification C++ Sample <openvino_inference_engine_samples_hello_nv12_input_classification_README>`
- :doc:`Hello NV12 Input Classification C Sample <openvino_inference_engine_ie_bridges_c_samples_hello_nv12_input_classification_README>`
- **Hello Query Device Sample** Query of available OpenVINO devices and their metrics, configuration values.
- :doc:`Hello Query Device C++ Sample <openvino_inference_engine_samples_hello_query_device_README>`
- :doc:`Hello Query Device Python* Sample <openvino_inference_engine_ie_bridges_python_sample_hello_query_device_README>`
- **Hello Reshape SSD Sample** Inference of SSD networks resized by ShapeInfer API according to an input size.
- :doc:`Hello Reshape SSD C++ Sample** <openvino_inference_engine_samples_hello_reshape_ssd_README>`
- :doc:`Hello Reshape SSD Python Sample** <openvino_inference_engine_ie_bridges_python_sample_hello_reshape_ssd_README>`
- **Image Classification Sample Async** Inference of image classification networks like AlexNet and GoogLeNet using Asynchronous Inference Request API (the sample supports only images as inputs).
- :doc:`Image Classification Async C++ Sample <openvino_inference_engine_samples_classification_sample_async_README>`
- :doc:`Image Classification Async Python* Sample <openvino_inference_engine_ie_bridges_python_sample_classification_sample_async_README>`
- **OpenVINO Model Creation Sample** Construction of the LeNet model using the OpenVINO model creation sample.
- :doc:`OpenVINO Model Creation C++ Sample <openvino_inference_engine_samples_model_creation_sample_README>`
- :doc:`OpenVINO Model Creation Python Sample <openvino_inference_engine_ie_bridges_python_sample_model_creation_sample_README>`
- **Benchmark Samples** - Simple estimation of a model inference performance
- :doc:`Sync Benchmark C++ Sample <openvino_inference_engine_samples_sync_benchmark_README>`
- :doc:`Sync Benchmark Python* Sample <openvino_inference_engine_ie_bridges_python_sample_sync_benchmark_README>`
- :doc:`Throughput Benchmark C++ Sample <openvino_inference_engine_samples_throughput_benchmark_README>`
- :doc:`Throughput Benchmark Python* Sample <openvino_inference_engine_ie_bridges_python_sample_throughput_benchmark_README>`
- :doc:`Bert Benchmark Python* Sample <openvino_inference_engine_ie_bridges_python_sample_bert_benchmark_README>`
- **Benchmark Application** Estimates deep learning inference performance on supported devices for synchronous and asynchronous modes.
- [Benchmark C++ Tool](../../samples/cpp/benchmark_app/README.md)
- :doc:`Benchmark C++ Tool <openvino_inference_engine_samples_benchmark_app_README>`
Note that the Python version of the benchmark tool is currently available only through the :doc:`OpenVINO Development Tools installation <openvino_docs_install_guides_install_dev_tools>`. It is not created in the samples directory but can be launched with the following command: ``benchmark_app -m <model> -i <input> -d <device>``. For more information, check the :doc:`Benchmark Python Tool <openvino_inference_engine_tools_benchmark_tool_README>` documentation.
.. note::
Note that the Python version of the benchmark tool is currently available only through the [OpenVINO Development Tools installation](../install_guides/installing-model-dev-tools.md). It is not created in the samples directory but can be launched with the following command:
`benchmark_app -m <model> -i <input> -d <device>`
For more information, check the [Benchmark Python Tool](../../tools/benchmark_tool/README.md) documentation.
All C++ samples support input paths containing only ASCII characters, except for the Hello Classification Sample, that supports Unicode.
> **NOTE**: All C++ samples support input paths containing only ASCII characters, except for the Hello Classification Sample, that supports Unicode.
Media Files Available for Samples
#################################
## Media Files Available for Samples
To run the sample applications, you can use images and videos from the media files collection available `here <https://storage.openvinotoolkit.org/data/test_data>`__ .
To run the sample applications, you can use images and videos from the media files collection available at https://storage.openvinotoolkit.org/data/test_data.
Samples that Support Pre-Trained Models
#######################################
## Samples that Support Pre-Trained Models
To run the sample, you can use :doc:`public <omz_models_group_public>` or :doc:`Intel's <omz_models_group_intel>` pre-trained models from the Open Model Zoo. The models can be downloaded using the :doc:`Model Downloader <omz_tools_downloader>`.
To run the sample, you can use [public](@ref omz_models_group_public) or [Intel's](@ref omz_models_group_intel) pre-trained models from the Open Model Zoo. The models can be downloaded using the [Model Downloader](@ref omz_tools_downloader).
Build the Sample Applications
#############################
## Build the Sample Applications
.. _build-samples-linux:
### <a name="build-samples-linux"></a>Build the Sample Applications on Linux
Build the Sample Applications on Linux
++++++++++++++++++++++++++++++++++++++
The officially supported Linux build environment is the following:
@ -102,76 +124,100 @@ The officially supported Linux build environment is the following:
* GCC 7.5.0 (for Ubuntu 18.04) or GCC 9.3.0 (for Ubuntu 20.04)
* CMake version 3.10 or higher
> **NOTE**: For building samples from the open-source version of OpenVINO toolkit, see the [build instructions on GitHub](https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/build.md).
.. note::
For building samples from the open-source version of OpenVINO toolkit, see the `build instructions on GitHub <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/build.md>`__ .
To build the C or C++ sample applications for Linux, go to the `<INSTALL_DIR>/samples/c` or `<INSTALL_DIR>/samples/cpp` directory, respectively, and run the `build_samples.sh` script:
```sh
build_samples.sh
```
To build the C or C++ sample applications for Linux, go to the ``<INSTALL_DIR>/samples/c`` or ``<INSTALL_DIR>/samples/cpp`` directory, respectively, and run the ``build_samples.sh`` script:
.. code-block:: sh
build_samples.sh
Once the build is completed, you can find sample binaries in the following folders:
* C samples: `~/openvino_c_samples_build/<architecture>/Release`
* C++ samples: `~/openvino_cpp_samples_build/<architecture>/Release`
where the <architecture> is the output of `uname -m`, for example, `intel64`, `armhf`, or `aarch64`.
* C samples: ``~/openvino_c_samples_build/<architecture>/Release``
* C++ samples: ``~/openvino_cpp_samples_build/<architecture>/Release`` where the <architecture> is the output of ``uname -m``, for example, ``intel64``, ``armhf``, or ``aarch64``.
You can also build the sample applications manually:
> **NOTE**: If you have installed the product as a root user, switch to root mode before you continue: `sudo -i`
.. note::
1. Navigate to a directory that you have write access to and create a samples build directory. This example uses a directory named `build`:
```sh
mkdir build
```
> **NOTE**: If you run the Image Classification verification script during the installation, the C++ samples build directory is created in your home directory: `~/openvino_cpp_samples_build/`
If you have installed the product as a root user, switch to root mode before you continue: ``sudo -i`` .
1. Navigate to a directory that you have write access to and create a samples build directory. This example uses a directory named ``build``:
.. code-block:: sh
mkdir build
.. note::
If you run the Image Classification verification script during the installation, the C++ samples build directory is created in your home directory: ``~/openvino_cpp_samples_build/``
2. Go to the created directory:
```sh
cd build
```
.. code-block:: sh
cd build
3. Run CMake to generate the Make files for release or debug configuration. For example, for C++ samples:
- For release configuration:
```sh
cmake -DCMAKE_BUILD_TYPE=Release <INSTALL_DIR>/samples/cpp
```
- For debug configuration:
```sh
cmake -DCMAKE_BUILD_TYPE=Debug <INSTALL_DIR>/samples/cpp
```
4. Run `make` to build the samples:
```sh
make
```
- For release configuration:
For the release configuration, the sample application binaries are in `<path_to_build_directory>/<architecture>/Release/`;
for the debug configuration — in `<path_to_build_directory>/<architecture>/Debug/`.
.. code-block:: sh
cmake -DCMAKE_BUILD_TYPE=Release <INSTALL_DIR>/samples/cpp
- For debug configuration:
### <a name="build-samples-windows"></a>Build the Sample Applications on Microsoft Windows
.. code-block:: sh
cmake -DCMAKE_BUILD_TYPE=Debug <INSTALL_DIR>/samples/cpp
4. Run ``make`` to build the samples:
.. code-block:: sh
make
For the release configuration, the sample application binaries are in ``<path_to_build_directory>/<architecture>/Release/``;
for the debug configuration — in ``<path_to_build_directory>/<architecture>/Debug/``.
.. _build-samples-windows:
Build the Sample Applications on Microsoft Windows
++++++++++++++++++++++++++++++++++++++++++++++++++
The recommended Windows build environment is the following:
* Microsoft Windows 10
* Microsoft Visual Studio 2019
* CMake version 3.10 or higher
> **NOTE**: If you want to use Microsoft Visual Studio 2019, you are required to install CMake 3.14 or higher.
.. note::
To build the C or C++ sample applications on Windows, go to the `<INSTALL_DIR>\samples\c` or `<INSTALL_DIR>\samples\cpp` directory, respectively, and run the `build_samples_msvc.bat` batch file:
```sh
build_samples_msvc.bat
```
If you want to use Microsoft Visual Studio 2019, you are required to install CMake 3.14 or higher.
To build the C or C++ sample applications on Windows, go to the ``<INSTALL_DIR>\samples\c`` or ``<INSTALL_DIR>\samples\cpp`` directory, respectively, and run the ``build_samples_msvc.bat`` batch file:
.. code-block:: sh
build_samples_msvc.bat
By default, the script automatically detects the highest Microsoft Visual Studio version installed on the machine and uses it to create and build a solution for a sample code
Once the build is completed, you can find sample binaries in the following folders:
* C samples: `C:\Users\<user>\Documents\Intel\OpenVINO\openvino_c_samples_build\<architecture>\Release`
* C++ samples: `C:\Users\<user>\Documents\Intel\OpenVINO\openvino_cpp_samples_build\<architecture>\Release`
where the <architecture> is the output of `echo %PROCESSOR_ARCHITECTURE%`, for example, `intel64` (AMD64), or `arm64`.
You can also build a generated solution manually. For example, if you want to build C++ sample binaries in Debug configuration, run the appropriate version of the
Microsoft Visual Studio and open the generated solution file from the `C:\Users\<user>\Documents\Intel\OpenVINO\openvino_cpp_samples_build\Samples.sln`
directory.
* C samples: ``C:\Users\<user>\Documents\Intel\OpenVINO\openvino_c_samples_build\<architecture>\Release``
* C++ samples: ``C:\Users\<user>\Documents\Intel\OpenVINO\openvino_cpp_samples_build\<architecture>\Release`` where the <architecture> is the output of ``echo PROCESSOR_ARCHITECTURE%``, for example, ``intel64`` (AMD64), or ``arm64``.
### <a name="build-samples-macos"></a>Build the Sample Applications on macOS
You can also build a generated solution manually. For example, if you want to build C++ sample binaries in Debug configuration, run the appropriate version of the Microsoft Visual Studio and open the generated solution file from the ``C:\Users\<user>\Documents\Intel\OpenVINO\openvino_cpp_samples_build\Samples.sln`` directory.
.. _build-samples-macos:
Build the Sample Applications on macOS
++++++++++++++++++++++++++++++++++++++
The officially supported macOS build environment is the following:
@ -179,112 +225,131 @@ The officially supported macOS build environment is the following:
* Clang compiler from Xcode 10.1 or higher
* CMake version 3.13 or higher
> **NOTE**: For building samples from the open-source version of OpenVINO toolkit, see the [build instructions on GitHub](https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/build.md).
.. note::
To build the C or C++ sample applications for macOS, go to the `<INSTALL_DIR>/samples/c` or `<INSTALL_DIR>/samples/cpp` directory, respectively, and run the `build_samples.sh` script:
```sh
build_samples.sh
```
For building samples from the open-source version of OpenVINO toolkit, see the `build instructions on GitHub <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/build.md>`__ .
To build the C or C++ sample applications for macOS, go to the ``<INSTALL_DIR>/samples/c`` or ``<INSTALL_DIR>/samples/cpp`` directory, respectively, and run the ``build_samples.sh`` script:
.. code-block:: sh
build_samples.sh
Once the build is completed, you can find sample binaries in the following folders:
* C samples: `~/openvino_c_samples_build/<architecture>/Release`
* C++ samples: `~/openvino_cpp_samples_build/<architecture>/Release`
* C samples: ``~/openvino_c_samples_build/<architecture>/Release``
* C++ samples: ``~/openvino_cpp_samples_build/<architecture>/Release``
You can also build the sample applications manually:
> **NOTE**: If you have installed the product as a root user, switch to root mode before you continue: `sudo -i`
.. note::
> **NOTE**: Before proceeding, make sure you have OpenVINO™ environment set correctly. This can be done manually by
```sh
cd <INSTALL_DIR>/
source setupvars.sh
```
If you have installed the product as a root user, switch to root mode before you continue: ``sudo -i``
1. Navigate to a directory that you have write access to and create a samples build directory. This example uses a directory named `build`:
```sh
mkdir build
```
> **NOTE**: If you ran the Image Classification verification script during the installation, the C++ samples build directory was already created in your home directory: `~/openvino_cpp_samples_build/`
.. note::
Before proceeding, make sure you have OpenVINO™ environment set correctly. This can be done manually by
.. code-block:: sh
cd <INSTALL_DIR>/
source setupvars.sh
1. Navigate to a directory that you have write access to and create a samples build directory. This example uses a directory named ``build``:
.. code-block:: sh
mkdir build
.. note::
If you ran the Image Classification verification script during the installation, the C++ samples build directory was already created in your home directory: ``~/openvino_cpp_samples_build/``
2. Go to the created directory:
```sh
cd build
```
.. code-block:: sh
cd build
3. Run CMake to generate the Make files for release or debug configuration. For example, for C++ samples:
- For release configuration:
```sh
cmake -DCMAKE_BUILD_TYPE=Release <INSTALL_DIR>/samples/cpp
```
- For debug configuration:
```sh
cmake -DCMAKE_BUILD_TYPE=Debug <INSTALL_DIR>/samples/cpp
```
4. Run `make` to build the samples:
```sh
make
```
For the release configuration, the sample application binaries are in `<path_to_build_directory>/<architecture>/Release/`;
for the debug configuration — in `<path_to_build_directory>/<architecture>/Debug/`.
- For release configuration:
## Get Ready for Running the Sample Applications
.. code-block:: sh
### Get Ready for Running the Sample Applications on Linux
cmake -DCMAKE_BUILD_TYPE=Release <INSTALL_DIR>/samples/cpp
- For debug configuration:
Before running compiled binary files, make sure your application can find the
OpenVINO Runtime libraries.
Run the `setupvars` script to set all necessary environment variables:
```sh
source <INSTALL_DIR>/setupvars.sh
```
.. code-block:: sh
#### (Optional) Set Environment Variables Permanently
cmake -DCMAKE_BUILD_TYPE=Debug <INSTALL_DIR>/samples/cpp
4. Run ``make`` to build the samples:
.. code-block:: sh
make
For the release configuration, the sample application binaries are in ``<path_to_build_directory>/<architecture>/Release/``; for the debug configuration — in ``<path_to_build_directory>/<architecture>/Debug/``.
Get Ready for Running the Sample Applications
#############################################
Get Ready for Running the Sample Applications on Linux
++++++++++++++++++++++++++++++++++++++++++++++++++++++
Before running compiled binary files, make sure your application can find the OpenVINO Runtime libraries. Run the ``setupvars`` script to set all necessary environment variables:
.. code-block:: sh
source <INSTALL_DIR>/setupvars.sh
(Optional) Set Environment Variables Permanently
------------------------------------------------
The OpenVINO environment variables are removed when you close the shell. As an option, you can permanently set the environment variables as follows:
1. Open the `.bashrc` file in `<user_home_directory>`:
```sh
vi <user_home_directory>/.bashrc
```
1. Open the ``.bashrc`` file in ``<user_home_directory>``:
.. code-block:: sh
vi <user_home_directory>/.bashrc
2. Add this line to the end of the file:
```sh
source /opt/intel/openvino_2022/setupvars.sh
```
3. Save and close the file: press the **Esc** key, type `:wq` and press the **Enter** key.
4. To test your change, open a new terminal. You will see `[setupvars.sh] OpenVINO environment initialized`.
.. code-block:: sh
source /opt/intel/openvino_2022/setupvars.sh
You are ready to run sample applications. To learn about how to run a particular
sample, read the sample documentation by clicking the sample name in the samples
list above.
3. Save and close the file: press the **Esc** key, type ``:wq`` and press the **Enter** key.
4. To test your change, open a new terminal. You will see ``[setupvars.sh] OpenVINO environment initialized``.
### Get Ready for Running the Sample Applications on Windows
You are ready to run sample applications. To learn about how to run a particular sample, read the sample documentation by clicking the sample name in the samples list above.
Before running compiled binary files, make sure your application can find the
OpenVINO Runtime libraries.
Use the `setupvars` script, which sets all necessary environment variables:
```sh
<INSTALL_DIR>\setupvars.bat
```
Get Ready for Running the Sample Applications on Windows
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
To debug or run the samples on Windows in Microsoft Visual Studio, make sure you
have properly configured **Debugging** environment settings for the **Debug**
and **Release** configurations. Set correct paths to the OpenCV libraries, and
debug and release versions of the OpenVINO Runtime libraries.
For example, for the **Debug** configuration, go to the project's
**Configuration Properties** to the **Debugging** category and set the `PATH`
variable in the **Environment** field to the following:
Before running compiled binary files, make sure your application can find the OpenVINO Runtime libraries. Use the ``setupvars`` script, which sets all necessary environment variables:
```sh
PATH=<INSTALL_DIR>\runtime\bin;%PATH%
```
where `<INSTALL_DIR>` is the directory in which the OpenVINO toolkit is installed.
.. code-block:: sh
<INSTALL_DIR>\setupvars.bat
You are ready to run sample applications. To learn about how to run a particular
sample, read the sample documentation by clicking the sample name in the samples
list above.
To debug or run the samples on Windows in Microsoft Visual Studio, make sure you have properly configured **Debugging** environment settings for the **Debug** and **Release** configurations. Set correct paths to the OpenCV libraries, and debug and release versions of the OpenVINO Runtime libraries. For example, for the **Debug** configuration, go to the project's **Configuration Properties** to the **Debugging** category and set the ``PATH`` variable in the **Environment** field to the following:
.. code-block:: sh
PATH=<INSTALL_DIR>\runtime\bin;%PATH%
where ``<INSTALL_DIR>`` is the directory in which the OpenVINO toolkit is installed.
You are ready to run sample applications. To learn about how to run a particular sample, read the sample documentation by clicking the sample name in the samples list above.
See Also
########
* :doc:`OpenVINO Runtime User Guide <openvino_docs_OV_UG_OV_Runtime_User_Guide>`
@endsphinxdirective
## See Also
* [OpenVINO Runtime User Guide](openvino_intro.md)

3
docs/_static/images/dog.png vendored Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1d49a45dd5cbace188cfdc23a2aeff441c2187f1610c9720b91ea6fbbb232387
size 150582

View File

@ -1,42 +1,54 @@
# Get Started with C++ Samples {#openvino_docs_get_started_get_started_demos}
@sphinxdirective
The guide presents a basic workflow for building and running C++ code samples in OpenVINO. Note that these steps will not work with the Python samples.
To get started, you must first install OpenVINO Runtime, install OpenVINO Development tools, and build the sample applications. See the <a href="#prerequisites-samples">Prerequisites</a> section for instructions.
To get started, you must first install OpenVINO Runtime, install OpenVINO Development tools, and build the sample applications. See the :ref:`Prerequisites <prerequisites-samples>` section for instructions.
Once the prerequisites have been installed, perform the following steps:
1. <a href="#download-models">Use Model Downloader to download a suitable model.</a>
2. <a href="#convert-models-to-intermediate-representation">Convert the model with Model Optimizer.</a>
3. <a href="#download-media">Download media files to run inference.</a>
4. <a href="#run-image-classification">Run inference with the Image Classification sample application and see the results.</a>
1. :ref:`Use Model Downloader to download a suitable model <download-models>`.
2. :ref:`Convert the model with Model Optimizer <convert-models-to-intermediate-representation>`.
3. :ref:`Download media files to run inference <download-media>`.
4. :ref:`Run inference with the Image Classification sample application and see the results <run-image-classification>`.
## <a name="prerequisites-samples"></a>Prerequisites
.. _prerequisites-samples:
### Install OpenVINO Runtime
Prerequisites
#############
Install OpenVINO Runtime
++++++++++++++++++++++++
To use sample applications, install OpenVINO Runtime via one of the following distribution channels (other distributions do not include sample files):
* Archive files (recommended) - [Linux](@ref openvino_docs_install_guides_installing_openvino_from_archive_linux) | [Windows](@ref openvino_docs_install_guides_installing_openvino_from_archive_windows) | [macOS](@ref openvino_docs_install_guides_installing_openvino_from_archive_macos)
* [APT](@ref openvino_docs_install_guides_installing_openvino_apt) or [YUM](@ref openvino_docs_install_guides_installing_openvino_yum) for Linux
* Docker image - [Linux](@ref openvino_docs_install_guides_installing_openvino_docker_linux) | [Windows](@ref openvino_docs_install_guides_installing_openvino_docker_windows)
* [Build from source](https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/build.md)
* Archive files (recommended) - :doc:`Linux <openvino_docs_install_guides_installing_openvino_from_archive_linux>` | :doc:`Windows <openvino_docs_install_guides_installing_openvino_from_archive_windows>` | :doc:`macOS <openvino_docs_install_guides_installing_openvino_from_archive_macos>`
* :doc:`APT <openvino_docs_install_guides_installing_openvino_apt>` or :doc:`YUM <openvino_docs_install_guides_installing_openvino_yum>` for Linux
* Docker image - :doc:`Linux <openvino_docs_install_guides_installing_openvino_docker_linux>` | :doc:`Windows <openvino_docs_install_guides_installing_openvino_docker_windows>`
* `Build from source <https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/build.md>`__
Make sure that you also [install OpenCV](https://github.com/opencv/opencv/wiki/BuildOpenCV4OpenVINO), as it's required for running sample applications.
Make sure that you also `install OpenCV <https://github.com/opencv/opencv/wiki/BuildOpenCV4OpenVINO>`__ , as it's required for running sample applications.
### Install OpenVINO Development Tools
Install OpenVINO Development Tools
++++++++++++++++++++++++++++++++++
To install OpenVINO Development Tools, follow the [instructions for C++ developers on the Install OpenVINO Development Tools page](../install_guides/installing-model-dev-tools.md#cpp_developers). This guide uses the `googlenet-v1` model from the Caffe framework, therefore, when you get to Step 4 of the installation, run the following command to install OpenVINO with the Caffe requirements:
To install OpenVINO Development Tools, follow the :doc:`instructions for C++ developers on the Install OpenVINO Development Tools page <openvino_docs_install_guides_install_dev_tools>`. This guide uses the ``googlenet-v1`` model from the Caffe framework, therefore, when you get to Step 4 of the installation, run the following command to install OpenVINO with the Caffe requirements:
.. code-block:: sh
``` sh
pip install openvino-dev[caffe]
```
### Build Samples
To build OpenVINO samples, follow the build instructions for your operating system on the [OpenVINO Samples](../OV_Runtime_UG/Samples_Overview.md) page. The build will take about 5-10 minutes, depending on your system.
Build Samples
+++++++++++++
## <a name="download-models"></a> Step 1: Download the Models
To build OpenVINO samples, follow the build instructions for your operating system on the :doc:`OpenVINO Samples <openvino_docs_OV_UG_Samples_Overview>` page. The build will take about 5-10 minutes, depending on your system.
.. _download-models:
Step 1: Download the Models
###########################
You must have a model that is specific for your inference task. Example model types are:
@ -46,34 +58,37 @@ You must have a model that is specific for your inference task. Example model ty
You can use one of the following options to find a model suitable for OpenVINO:
- Download public or Intel pre-trained models from [Open Model Zoo](@ref model_zoo) using [Model Downloader tool](@ref omz_tools_downloader)
- Download public or Intel pre-trained models from :doc:`Open Model Zoo <model_zoo>` using :doc:`Model Downloader tool <omz_tools_downloader>`
- Download from GitHub, Caffe Zoo, TensorFlow Zoo, etc.
- Train your own model with machine learning tools
This guide uses OpenVINO Model Downloader to get pre-trained models. You can use one of the following commands to find a model with this method:
* List the models available in the downloader.
``` sh
.. code-block:: sh
omz_info_dumper --print_all
```
* Use `grep` to list models that have a specific name pattern (e.g. `ssd-mobilenet`, `yolo`). Replace `<model_name>` with the name of the model.
``` sh
* Use ``grep`` to list models that have a specific name pattern (e.g. ``ssd-mobilenet``, ``yolo``). Replace ``<model_name>`` with the name of the model.
.. code-block:: sh
omz_info_dumper --print_all | grep <model_name>
```
* Use Model Downloader to download models. Replace `<models_dir>` with the directory to download the model to and `<model_name>` with the name of the model.
``` sh
* Use Model Downloader to download models. Replace ``<models_dir>`` with the directory to download the model to and ``<model_name>`` with the name of the model.
.. code-block:: sh
omz_downloader --name <model_name> --output_dir <models_dir>
```
This guide used the following model to run the Image Classification Sample:
|Model Name | Code Sample or Demo App |
|-----------------------------------------------|------------------------------------------|
|`googlenet-v1` | Image Classification Sample |
@sphinxdirective
+------------------+-----------------------------+
| Model Name | Code Sample or Demo App |
+==================+=============================+
| ``googlenet-v1`` | Image Classification Sample |
+------------------+-----------------------------+
.. dropdown:: Click to view how to download the GoogleNet v1 Caffe model
@ -147,25 +162,24 @@ This guide used the following model to run the Image Classification Sample:
========= Replacing text in /Users/username/models/public/googlenet-v1/googlenet-v1.prototxt =========
@endsphinxdirective
.. _convert-models-to-intermediate-representation:
## <a name="convert-models-to-intermediate-representation"></a>Step 2: Convert the Model with Model Optimizer
Step 2: Convert the Model with Model Optimizer
##############################################
In this step, your trained models are ready to run through the Model Optimizer to convert them to the IR (Intermediate Representation) format. For most model types, this is required before using OpenVINO Runtime with the model.
Models in the IR format always include an `.xml` and `.bin` file and may also include other files such as `.json` or `.mapping`. Make sure you have these files together in a single directory so OpenVINO Runtime can find them.
Models in the IR format always include an ``.xml`` and ``.bin`` file and may also include other files such as ``.json`` or ``.mapping``. Make sure you have these files together in a single directory so OpenVINO Runtime can find them.
REQUIRED: `model_name.xml`
REQUIRED: `model_name.bin`
OPTIONAL: `model_name.json`, `model_name.mapping`, etc.
REQUIRED: ``model_name.xml``
REQUIRED: ``model_name.bin``
OPTIONAL: ``model_name.json``, ``model_name.mapping``, etc.
This tutorial uses the public GoogleNet v1 Caffe model to run the Image Classification Sample. See the example in the Download Models section of this page to learn how to download this model.
The googlenet-v1 model is downloaded in the Caffe format. You must use Model Optimizer to convert the model to IR.
Create an `<ir_dir>` directory to contain the model's Intermediate Representation (IR).
@sphinxdirective
Create an ``<ir_dir>`` directory to contain the model's Intermediate Representation (IR).
.. tab:: Linux
@ -185,22 +199,19 @@ Create an `<ir_dir>` directory to contain the model's Intermediate Representatio
mkdir ~/ir
@endsphinxdirective
To save disk space for your IR file, you can apply [weights compression to FP16](../MO_DG/prepare_model/FP16_Compression.md). To generate an IR with FP16 weights, run Model Optimizer with the `--compress_to_fp16` option.
To save disk space for your IR file, you can apply :doc:`weights compression to FP16 <openvino_docs_MO_DG_FP16_Compression>`. To generate an IR with FP16 weights, run Model Optimizer with the ``--compress_to_fp16`` option.
Generic Model Optimizer script:
``` sh
mo --input_model <model_dir>/<model_file>
```
.. code-block:: sh
The IR files produced by the script are written to the `<ir_dir>` directory.
mo --input_model <model_dir>/<model_file>
The IR files produced by the script are written to the ``<ir_dir>`` directory.
The command with most placeholders filled in and FP16 precision:
@sphinxdirective
.. tab:: Linux
.. code-block:: sh
@ -219,95 +230,93 @@ The command with most placeholders filled in and FP16 precision:
mo --input_model ~/models/public/googlenet-v1/googlenet-v1.caffemodel --compress_to_fp16 --output_dir ~/ir
@endsphinxdirective
.. _download-media:
## <a name="download-media"></a> Step 3: Download a Video or a Photo as Media
Step 3: Download a Video or a Photo as Media
############################################
Most of the samples require you to provide an image or a video as the input to run the model on. You can get them from sites like [Pexels](https://pexels.com) or [Google Images](https://images.google.com).
Most of the samples require you to provide an image or a video as the input to run the model on. You can get them from sites like `Pexels <https://pexels.com>`__ or `Google Images <https://images.google.com>`__ .
As an alternative, OpenVINO also provides several sample images and videos for you to run code samples and demo applications:
- [Sample images and video](https://storage.openvinotoolkit.org/data/test_data/)
- [Sample videos](https://github.com/intel-iot-devkit/sample-videos)
- `Sample images and video <https://storage.openvinotoolkit.org/data/test_data/>`__
- `Sample videos <https://github.com/intel-iot-devkit/sample-videos>`__
## <a name="run-image-classification"></a>Step 4: Run Inference on a Sample
.. _run-image-classification:
Step 4: Run Inference on a Sample
##################################
To run the **Image Classification** code sample with an input image using the IR model:
1. Set up the OpenVINO environment variables:
@sphinxdirective
.. tab:: Linux
.. code-block:: sh
source <INSTALL_DIR>/setupvars.sh
.. tab:: Windows
.. code-block:: bat
<INSTALL_DIR>\setupvars.bat
.. tab:: macOS
.. code-block:: sh
source <INSTALL_DIR>/setupvars.sh
@endsphinxdirective
.. tab:: Linux
.. code-block:: sh
source <INSTALL_DIR>/setupvars.sh
.. tab:: Windows
.. code-block:: bat
<INSTALL_DIR>\setupvars.bat
.. tab:: macOS
.. code-block:: sh
source <INSTALL_DIR>/setupvars.sh
2. Go to the code samples release directory created when you built the samples earlier:
@sphinxdirective
.. tab:: Linux
.. code-block:: sh
cd ~/openvino_cpp_samples_build/intel64/Release
.. tab:: Windows
.. code-block:: bat
cd %USERPROFILE%\Documents\Intel\OpenVINO\openvino_samples_build\intel64\Release
.. tab:: macOS
.. code-block:: sh
cd ~/openvino_cpp_samples_build/intel64/Release
@endsphinxdirective
.. tab:: Linux
.. code-block:: sh
cd ~/openvino_cpp_samples_build/intel64/Release
.. tab:: Windows
.. code-block:: bat
cd %USERPROFILE%\Documents\Intel\OpenVINO\openvino_samples_build\intel64\Release
.. tab:: macOS
.. code-block:: sh
cd ~/openvino_cpp_samples_build/intel64/Release
3. Run the code sample executable, specifying the input media file, the IR for your model, and a target device for performing inference:
@sphinxdirective
.. tab:: Linux
.. tab:: Linux
.. code-block:: sh
classification_sample_async -i <path_to_media> -m <path_to_model> -d <target_device>
.. tab:: Windows
.. code-block:: bat
classification_sample_async.exe -i <path_to_media> -m <path_to_model> -d <target_device>
.. tab:: macOS
.. code-block:: sh
classification_sample_async -i <path_to_media> -m <path_to_model> -d <target_device>
Examples
++++++++
.. code-block:: sh
Running Inference on CPU
------------------------
classification_sample_async -i <path_to_media> -m <path_to_model> -d <target_device>
The following command shows how to run the Image Classification Code Sample using the `dog.bmp <https://storage.openvinotoolkit.org/data/test_data/images/224x224/dog.bmp>`__ file as an input image, the model in IR format from the ``ir`` directory, and the CPU as the target hardware:
.. tab:: Windows
.. code-block:: bat
classification_sample_async.exe -i <path_to_media> -m <path_to_model> -d <target_device>
.. tab:: macOS
.. code-block:: sh
classification_sample_async -i <path_to_media> -m <path_to_model> -d <target_device>
@endsphinxdirective
### Examples
#### Running Inference on CPU
The following command shows how to run the Image Classification Code Sample using the [dog.bmp](https://storage.openvinotoolkit.org/data/test_data/images/224x224/dog.bmp) file as an input image, the model in IR format from the `ir` directory, and the CPU as the target hardware:
@sphinxdirective
.. tab:: Linux
.. code-block:: sh
@ -326,15 +335,11 @@ The following command shows how to run the Image Classification Code Sample usin
./classification_sample_async -i ~/Downloads/dog.bmp -m ~/ir/googlenet-v1.xml -d CPU
@endsphinxdirective
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:
<img src="https://storage.openvinotoolkit.org/data/test_data/images/224x224/dog.bmp">
.. image:: _static/images/dog.png
@sphinxdirective
.. code-block:: sh
.. code-block:: sh
Top 10 results:
@ -353,15 +358,15 @@ When the sample application is complete, you are given the label and confidence
216 0.0057589 clumber, clumber spaniel
154 0.0052615 Pekinese, Pekingese, Peke
@endsphinxdirective
The following example shows how to run the same sample using GPU as the target device.
#### Running Inference on GPU
Running Inference on GPU
------------------------
> **NOTE**: Running inference on Intel® Processor Graphics (GPU) requires [additional hardware configuration steps](../install_guides/configurations-for-intel-gpu.md), as described earlier on this page. Running on GPU is not compatible with macOS.
.. note::
Running inference on Intel® Processor Graphics (GPU) requires :doc:`additional hardware configuration steps <openvino_docs_install_guides_configurations_for_intel_gpu>`, as described earlier on this page. Running on GPU is not compatible with macOS.
@sphinxdirective
.. tab:: Linux
.. code-block:: sh
@ -374,11 +379,13 @@ The following example shows how to run the same sample using GPU as the target d
.\classification_sample_async.exe -i %USERPROFILE%\Downloads\dog.bmp -m %USERPROFILE%\Documents\ir\googlenet-v1.xml -d GPU
Other Demos and Samples
#######################
See the :doc:`Samples <openvino_docs_OV_UG_Samples_Overview>` page for more sample applications. Each sample page explains how the application works and shows how to run it. Use the samples as a starting point that can be adapted for your own application.
OpenVINO also provides demo applications for using off-the-shelf models from :doc:`Open Model Zoo <model_zoo>`. Visit :doc:`Open Model Zoo Demos <omz_demos>` if you'd like to see even more examples of how to run model inference with the OpenVINO API.
@endsphinxdirective
## Other Demos and Samples
See the [Samples](../OV_Runtime_UG/Samples_Overview.md) page for more sample applications. Each sample page explains how the application works and shows how to run it. Use the samples as a starting point that can be adapted for your own application.
OpenVINO also provides demo applications for using off-the-shelf models from [Open Model Zoo](@ref model_zoo). Visit [Open Model Zoo Demos](@ref omz_demos) if you'd like to see even more examples of how to run model inference with the OpenVINO API.

View File

@ -161,9 +161,10 @@ To build the C++ or C sample applications for Linux, run the `build_samples.sh`
/usr/share/openvino/samples/c/build_samples.sh
@endsphinxdirective
For more information, refer to <a href="openvino_docs_OV_UG_Samples_Overview.html#build-samples-linux">Build the Sample Applications on Linux</a>.
For more information, refer to :ref:`Build the Sample Applications on Linux <build-samples-linux>`.
@endsphinxdirective
### Uninstalling OpenVINO Runtime