{"id":640,"date":"2023-06-28T23:05:02","date_gmt":"2023-06-28T13:05:02","guid":{"rendered":"https:\/\/www.samontab.com\/web\/?p=640"},"modified":"2023-06-29T01:00:08","modified_gmt":"2023-06-28T15:00:08","slug":"how-to-build-openvino-2023-0-in-ubuntu-22-04-2-lts-and-run-an-example","status":"publish","type":"post","link":"https:\/\/www.samontab.com\/web\/2023\/06\/how-to-build-openvino-2023-0-in-ubuntu-22-04-2-lts-and-run-an-example\/","title":{"rendered":"How to build OpenVINO 2023.0 in Ubuntu 22.04.2 LTS and run an example"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Intel has recently released the new OpenVINO 2023.0 with major new features such as macOS ARM64 support, support for Python 3.11, the ability to directly run models without converting them, and many more performance gains and new features. I&#8217;ll show you here how to compile it for Ubuntu 22.04.2 LTS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First we need to make sure we have the latest updates installed in the OS:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo apt-get update\nsudo apt-get upgrade\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Now we need to install some build tools in case you don&#8217;t have them installed:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo apt-get install build-essential git cmake\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Now we get the OpenVINO 2023.0 source code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncd ~\ngit clone --recursive --branch releases\/2023\/0 https:\/\/github.com\/openvinotoolkit\/openvino.git openvino-2023.0\ncd openvino-2023.0\ngit submodule update --init --recursive\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">There are some OpenVINO dependencies that need to be installed first. These require you to have access to sudo in order to install them using the provided script, like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nsudo .\/install_build_dependencies.sh\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">After that&#8217;s finished we are ready to install some python requirements, configure OpenVINO, and build it with OpenCV support:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\npip install -r src\/bindings\/python\/src\/compatibility\/openvino\/requirements-dev.txt\nmkdir build\ncd build\ncmake -DENABLE_PYTHON=ON -DENABLE_OPENCV=ON -DCMAKE_INSTALL_PREFIX=install ..\nmake -j`nproc`\nmake install\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">OpenVINO 2023.0 is now installed. You can test that it&#8217;s working properly by running this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncd ~\/openvino-2023.0\/bin\/intel64\n.\/hello_query_device\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">You should see at least a CPU device in there.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[ INFO ] Build ................................. 2023.0.0-11004-caae459f547-releases\/2023\/0\n[ INFO ]  \n[ INFO ] Available devices:  \n[ INFO ] CPU\n[ INFO ]        SUPPORTED_PROPERTIES:\netc...<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now we will install the OpenVINO development tools, such as the model optimizer, with this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\npip install openvino-dev==2023.0.0\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">These scripts are now installed at ~\/.local\/bin which is not in the path, so we need to add it there:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nexport PATH=$PATH:~\/.local\/bin\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This will only work for the current terminal. If you want to make this change permanent, just add that previous line to the end of the ~\/.bashrc file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we can use the tools. You can for example list all the available models for download like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nomz_downloader --print_all\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">OK, now let&#8217;s download a model, convert it to the OpenVINO Intermediate Representation format (IR), and run an inference on it. We are going to classify this image (you can use any image you want):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"a6a16e\" data-has-transparency=\"false\" style=\"--dominant-color: #a6a16e;\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"739\" src=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2023\/06\/puppy-gb71fd9d99_1280-1024x739.webp\" alt=\"\" class=\"wp-image-642 not-transparent\" srcset=\"https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2023\/06\/puppy-gb71fd9d99_1280-1024x739.webp 1024w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2023\/06\/puppy-gb71fd9d99_1280-300x217.webp 300w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2023\/06\/puppy-gb71fd9d99_1280-768x554.webp 768w, https:\/\/www.samontab.com\/web\/wp-content\/uploads\/2023\/06\/puppy-gb71fd9d99_1280-jpg.webp 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ncd ~\/openvino-2023.0\/bin\/intel64\nomz_downloader --name alexnet\nomz_converter --name alexnet\n.\/classification_sample_async -m public\/alexnet\/FP32\/alexnet.xml -i image.jpg\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The result we get is the top 10 classes that it thinks the image represents:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nTop 10 results:\n\nImage image.jpg\n\nclassid probability\n------- -----------\n207     0.8424635  \n208     0.1065520  \n222     0.0185891  \n219     0.0128466  \n257     0.0080099  \n216     0.0044186  \n175     0.0013159  \n212     0.0008337  \n244     0.0008299  \n194     0.0007491 \n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This means that the object with <strong>class ID 207<\/strong> has a probability of <strong>84.2%<\/strong> to be there in the photo. Let&#8217;s see what object that is. These IDs are based on the Imagenet 1000 class list, that you can see <a rel=\"noreferrer noopener\" href=\"https:\/\/deeplearning.cms.waikato.ac.nz\/user-guide\/class-maps\/IMAGENET\/\" target=\"_blank\">here<\/a> for example. We&#8217;re going to grab a txt version of this list and grep it to see the contents:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nwget https:\/\/gist.githubusercontent.com\/yrevar\/942d3a0ac09ec9e5eb3a\/raw\/238f720ff059c1f82f368259d1ca4ffa5dd8f9f5\/imagenet1000_clsidx_to_labels.txt\ncat imagenet1000_clsidx_to_labels.txt | grep 207\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">And the answer is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n 207: &#039;golden retriever&#039;,\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">So there you go, OpenVINO is installed, and it successfully classified the image as being a <strong>golden retriever<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Intel has recently released the new OpenVINO 2023.0 with major new features such as macOS ARM64 support, support for Python 3.11, the ability to directly run models without converting them, and many more performance gains and new features. I&#8217;ll show you here how to compile it for Ubuntu 22.04.2 LTS. First we need to make [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,21,24,75],"tags":[11,68,25],"class_list":["post-640","post","type-post","status-publish","format-standard","hentry","category-computer-vision","category-open-source","category-openvino","category-ubuntu","tag-installation","tag-open-source","tag-openvino"],"_links":{"self":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/640","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/comments?post=640"}],"version-history":[{"count":0,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/posts\/640\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/media?parent=640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/categories?post=640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.samontab.com\/web\/wp-json\/wp\/v2\/tags?post=640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}