* OV new package structure * Fixes * More fixes * Fixed code style in ngraph tests * Fixes * Paths to setupvars inside demo scripts * Fixed demo_security_barrier_camera.sh * Added setupvars.sh to old location as well * Fixed path * Fixed MO install path in .co * Fixed install of public headers * Fixed frontends installation * Updated DM config files * Keep opencv in the root * Improvements * Fixes for demo scripts * Added path to TBB * Fix for MO unit-tests * Fixed tests on Windows * Reverted arch * Removed arch * Reverted arch back: second attemp * System type * Fix for Windows * Resolve merge conflicts * Fixed path * Path for Windows * Added debug for Windows * Added requirements_dev.txt to install * Fixed wheel's setup.py * Fixed lin build * Fixes after merge * Fix 2 * Fixes * Frontends path * Fixed deployment manager * Fixed Windows * Added cldnn unit tests installation * Install samples * Fix samples * Fix path for samples * Proper path * Try to fix MO hardcodes * samples binary location * MO print * Added install for libopencv_c_wrapper.so * Added library destination * Fixed install rule for samples * Updated demo scripts readme.md * Samples * Keep source permissions for Python samples * Fixed python * Updated path to fast run scripts * Fixed C samples tests * Removed debug output * Small fixes * Try to unify prefix
8.9 KiB
Installing Model Optimizer Pre-Requisites
Before running the Model Optimizer, you must install the Model Optimizer pre-requisites for the framework that was used to train the model. This section tells you how to install the pre-requisites either through scripts or by using a manual process.
Using Configuration Scripts
You can either configure all three frameworks at the same time or install an individual framework. The scripts delivered with the tool install all required dependencies and provide the fastest and easiest way to configure the Model Optimizer.
To configure all three frameworks, go to the
<INSTALL_DIR>/tools/model_optimizer/install_prerequisites
directory and run:
- For Linux* OS:
install_prerequisites.sh
Note
: This command installs prerequisites globally. If you want to keep Model Optimizer in a separate sandbox, run the following commands instead:
virtualenv --system-site-packages -p python3 ./venv
source ./venv/bin/activate # sh, bash, ksh, or zsh
./install_prerequisites.sh
- For Windows* OS:
install_prerequisites.bat
To configure a specific framework, go to the
<INSTALL_DIR>/tools/model_optimizer/install_prerequisites
directory and run:
- For Caffe* on Linux:
install_prerequisites_caffe.sh
- For Caffe on Windows:
install_prerequisites_caffe.bat
- For TensorFlow* 1.x on Linux:
install_prerequisites_tf.sh
- For TensorFlow 1.x on Windows:
install_prerequisites_tf.bat
- For TensorFlow* 2.x on Linux:
install_prerequisites_tf2.sh
- For TensorFlow 2.x on Windows:
install_prerequisites_tf2.bat
- For MXNet* on Linux:
install_prerequisites_mxnet.sh
- For MXNet on Windows:
install_prerequisites_mxnet.bat
- For Kaldi* on Linux:
install_prerequisites_kaldi.sh
- For Kaldi on Windows:
install_prerequisites_kaldi.bat
- For ONNX* on Linux:
install_prerequisites_onnx.sh
- For ONNX on Windows:
install_prerequisites_onnx.bat
Important
: ONLY FOR CAFFE* By default, you do not need to install Caffe to create an Intermediate Representation for a Caffe model, unless you use Caffe for custom layer shape inference and do not write Model Optimizer extensions. To learn more about implementing Model Optimizer custom operations and the limitations of using Caffe for shape inference, see Custom Layers in Model Optimizer.
Using Manual Configuration Process
If you prefer, you can manually configure the Model Optimizer for one framework at a time.
- Go to the Model Optimizer directory:
cd <INSTALL_DIR>/tools/model_optimizer/
- Strongly recommended for all global Model Optimizer dependency installations:
Create and activate a virtual environment. While not required, this step is
strongly recommended since the virtual environment creates a Python*
sandbox, and dependencies for the Model Optimizer do not influence the
global Python configuration, installed libraries, or other components.
In addition, a flag ensures that system-wide Python libraries are available
in this sandbox. Skip this step only if you do want to install all the Model
Optimizer dependencies globally:
- Create a virtual environment:
virtualenv -p /usr/bin/python3.6 .env3 --system-site-packages
* Activate the virtual environment:
virtualenv -p /usr/bin/python3.6 .env3/bin/activate
- Install all dependencies or only the dependencies for a specific framework:
- To install dependencies for all frameworks except TensorFlow* 1.x:
pip3 install -r requirements.txt
Note
: TensorFlow 1.x and 2.x are incompatible. Use separate virtual environments if you want to install multiple TensorFlow versions.
* To install dependencies only for Caffe:
pip3 install -r requirements_caffe.txt
* To install dependencies only for TensorFlow 1.x:
pip3 install -r requirements_tf.txt
* To install dependencies only for TensorFlow 2.x:
pip3 install -r requirements_tf2.txt
* To install dependencies only for MXNet:
pip3 install -r requirements_mxnet.txt
* To install dependencies only for Kaldi:
pip3 install -r requirements_kaldi.txt
* To install dependencies only for ONNX:
pip3 install -r requirements_onnx.txt
Using the protobuf Library in the Model Optimizer for Caffe*
Click to expand
These procedures require:
- Access to GitHub and the ability to use git commands
- Microsoft Visual Studio* 2013 for Win64* (if using Windows*)
- C/C++
Model Optimizer uses the protobuf library to load trained Caffe models. By default, the library executes pure Python* language implementation, which is slow. These steps show how to use the faster C++ implementation of the protobuf library on Windows OS or Linux OS.
Using the protobuf Library on Linux* OS
To use the C++ implementation of the protobuf library on Linux, it is enough to set up the environment variable:
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
Using the protobuf Library on Windows* OS
On Windows, pre-built protobuf packages for Python versions 3.4, 3.5, 3.6,
and 3.7 are provided with the installation package and can be found in
the
<INSTALL_DIR>\tools\model_optimizer\install_prerequisites
folder. Please note that they are not installed with the
install_prerequisites.bat installation script due to possible issues
with pip, and you can install them at your own discretion. Make sure
that you install the protobuf version that matches the Python version
you use:
protobuf-3.6.1-py3.4-win-amd64.eggfor Python 3.4protobuf-3.6.1-py3.5-win-amd64.eggfor Python 3.5protobuf-3.6.1-py3.6-win-amd64.eggfor Python 3.6protobuf-3.6.1-py3.7-win-amd64.eggfor Python 3.7
To install the protobuf package:
- Open the command prompt as administrator.
- Go to the
install_prerequisitesfolder of the OpenVINO toolkit installation directory:
cd <INSTALL_DIR>\tools\model_optimizer\install_prerequisites
- Run the following command to install the protobuf for Python 3.6. If
you want to install the protobuf for Python 3.4, 3.5, or 3.7, replace
protobuf-3.6.1-py3.6-win-amd64.eggwith the corresponding file name from the list above.
python -m easy_install protobuf-3.6.1-py3.6-win-amd64.egg
If the Python version you use is lower than 3.4, you need to update it or build the library manually.
Building the protobuf Library on Windows* OS
Note
: These steps are optional. If you use Python version 3.4, 3.5, 3.6, or 3.7, you can install the protobuf library using the pre-built packages.
To compile the protobuf library from sources on Windows OS, do the following:
- Clone protobuf source files from GitHub:
git clone https://github.com/google/protobuf.git
cd protobuf
- Create a Visual Studio solution file. Run these commands:
cd C:\Path\to\protobuf\cmake\build
mkdir solution
cd solution C:\Path\to\protobuf\cmake\build\solution
cmake -G "Visual Studio 12 2013 Win64" ../..
- Change the runtime library option for
libprotobufandlibprotobuf-lite:
- Open the project's Property Pages dialog box
- Expand the C/C++ tab
- Select the Code Generation property page
- Change the Runtime Library property to Multi-thread DLL (/MD)
- Build the
libprotoc,protoc,libprotobuf, andlibprotobuf-liteprojects in the Release configuration. - Add a path to the build directory to the
PATHenvironment variable:
set PATH=%PATH%;C:\Path\to\protobuf\cmake\build\solution\Release
- Go to the
pythondirectory:
cd C:\Path\to\protobuf\python
- Use a text editor to open and change these
setup.pyoptions:
- Change from
libraries = ['protobuf']
tolibraries = ['libprotobuf', 'libprotobuf-lite'] - Change from
extra_objects = ['../src/.libs/libprotobuf.a', '../src/.libs/libprotobuf-lite.a']
toextra_objects = ['../cmake/build/solution/Release/libprotobuf.lib', '../cmake/build/solution/Release/libprotobuf-lite.lib']
- Build the Python package with the C++ implementation:
python setup.py build –cpp_implementation
- Install the Python package with the C++ implementation:
python3 -m easy_install dist/protobuf-3.6.1-py3.6-win-amd64.egg
- Set an environment variable to boost the protobuf performance:
set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp