Skip to content

Instantly share code, notes, and snippets.

@ashwinrayaprolu
Created April 20, 2019 06:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwinrayaprolu/7245a37b86e5fd1920f8e4409e276132 to your computer and use it in GitHub Desktop.
Save ashwinrayaprolu/7245a37b86e5fd1920f8e4409e276132 to your computer and use it in GitHub Desktop.
OpenVINO Ubuntu Xenial, Virtualbox and Vagrant Install, Intel NCS2 (Neural Compute Stick 2)

#OpenVINO Ubuntu Xenial, Virtualbox and Vagrant Install, Intel NCS2 (Neural Compute Stick 2)

Prerequsites

Download Latest VirtualBox from [https://www.virtualbox.org/wiki/Downloads] https://www.virtualbox.org/wiki/Downloads

Make sure to download extension pack

Oracle VM VirtualBox Extension Pack

Download and Install Vagrant from

[https://www.vagrantup.com/downloads.html] https://www.vagrantup.com/downloads.html

First step is to setup VM.

vagrant up

Vagrant is configured to apply all usb filters required to access Neural Compute Stick 1 and 2 inside Virtualbox Ubuntu Xenial VM

This will create VM on your host machine with name "OpenVinoVM"

This will also automatically download OpenVINO to /home/vagrant/openvino

Setup

Install OpenVINO Dependencies

cd /home/vagrant/openvino/l_openvino_toolkit_p_2019.1.094/ && sudo ./install_openvino_dependencies.sh

Install OpenVINO

cd /home/vagrant/openvino/l_openvino_toolkit_p_2019.1.094/ && sudo ./install.sh

This will have multiple manual steps like accepting license and selecting kind of installation

Default installation path the download configured in Vagrantfile /opt/intel/openvino_2019.1.094

Setup Vars

source /opt/intel/openvino_2019.1.094/bin/setupvars.sh

echo "source /opt/intel/openvino_2019.1.094/bin/setupvars.sh" >> /home/vagrant/.bashrc

Install UDEV Rules

THese are required for USB to be activated and used

sh /opt/intel/openvino_2019.1.094/install_dependencies/install_NCS_udev_rules.sh

Update UDEV Rules are below

sudo vi /etc/udev/rules.d/97-myriad-usbboot.rules

I modified MODE to 666 from 660. OpenVINO has 660 as default.

SUBSYSTEM=="usb", ATTRS{idProduct}=="2150", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1" SUBSYSTEM=="usb", ATTRS{idProduct}=="2485", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1" SUBSYSTEM=="usb", ATTRS{idProduct}=="f63b", ATTRS{idVendor}=="03e7", GROUP="users", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"

Reload UDEV

sudo udevadm control --reload-rules && sudo udevadm trigger && sudo ldconfig

Configure Model Optimizer

cd /opt/intel/openvino_2019.1.094/deployment_tools/model_optimizer/install_prerequisites && sudo ./install_prerequisites.sh

If you dont want to run optimizer for all different kind of model you can choose specific optimizer

Example: sudo ./install_prerequisites_caffe.sh ( For Caffe Model) Example: sudo ./install_prerequisites_tf.sh ( For Tensorflow Model)

Verify if USB is attached

Type lsusb

You should see some USB device with vendor id like

Bus 002 Device 002: ID 03e7:2485

Finally Test

cd /opt/intel/openvino_2019.1.094/deployment_tools/demo && ./demo_squeezenet_download_convert_run.sh

This should print something like this

Image /opt/intel/openvino_2019.1.094/deployment_tools/demo/car.png

classid probability label
817 0.8363345 sports car, sport car
511 0.0946488 convertible
479 0.0419131 car wheel
751 0.0091071 racer, race car, racing car
436 0.0068161 beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon
656 0.0037564 minivan
586 0.0025741 half track
717 0.0016069 pickup, pickup truck
864 0.0012027 tow truck, tow car, wrecker
581 0.0005882 grille, radiator grille

total inference time: 11.7261708 Average running time of one iteration: 11.7261708 ms

Throughput: 85.2793311 FPS

Downloading Public Model and Running Test

cd /opt/intel/openvino_2019.1.094/deployment_tools/tools/model_downloader/

List public models that are known to work with OpenVINO

python3 downloader.py --print_all

Download a specific model, say GoogLeNet V2

Make sure vagrant has access to folder

sudo chmod -R 777 /opt/intel/openvino_2019.1.094/deployment_tools/tools/model_downloader/

python3 downloader.py --name googlenet-v2

Convert Pretained Model to IR ( Intermediate Represenation. This can run on multiple hardware)

cd /opt/intel/openvino_2019.1.094/deployment_tools/tools/model_downloader/classification/googlenet/v2/caffe

Use model optimizer to convert googlenet.caffemodel to IR

/opt/intel/openvino_2019.1.094/deployment_tools/model_optimizer/mo.py --data_type FP16 --input_model googlenet-v2.caffemodel --input_proto googlenet-v2.prototxt

Deploy the converted IR model onto Intel NCS 2 using the toolkit's IE API

cd /opt/intel/openvino_2019.1.094/deployment_tools/inference_engine/samples/python_samples

Download a test image from the internet

sudo wget -N https://upload.wikimedia.org/wikipedia/commons/b/b6/Felis_catus-cat_on_snow.jpg

Run an inference on this image using a built-in sample code

python3 classification_sample/classification_sample.py -m /opt/intel/openvino_2019.1.094/deployment_tools/tools/model_downloader/classification/googlenet/v2/caffe/./googlenet-v2.xml -i Felis_catus-cat_on_snow.jpg -d MYRIAD

This should give results like

Image Felis_catus-cat_on_snow.jpg

classid probability
173 0.4843750
54 0.2985840
7 0.1647949
200 0.0359497
66 0.0035839
10 0.0024872
473 0.0024281
84 0.0016794
198 0.0014591
152 0.0006762

Next write up will be on Image Classification Using OpenCV and OpenVINO

# -*- mode: ruby -*-
# vi: set ft=ruby :
# Look for more boxes here
# https://app.vagrantup.com/boxes/search?utf8=✓&sort=downloads&provider=&q=Ubuntu
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
def usbfilter_exists(vendor_id, product_id)
#
# Determine if a usbfilter with the provided Vendor/Product ID combination
# already exists on this VM.
#
# TODO: Use a more reliable way of retrieving this information.
#
# NOTE: The "machinereadable" output for usbfilters is more
# complicated to work with (due to variable names including
# the numeric filter index) so we don't use it here.
#
machine_id_filepath = ".vagrant/machines/default/virtualbox/id"
machine_name = "OpenVinoVM"
if not File.exists? machine_id_filepath
# VM hasn't been created yet.
return false
end
vm_info = `VBoxManage showvminfo OpenVinoVM`
#filter_match = "VendorId: #{vendor_id}\nProductId: #{product_id}\n"
filter_match = "VendorId: #{vendor_id.sub('0x','')}\n"
if vm_info.include? filter_match
#print ("Not adding below usb filter !!. Its is already added \n")
#print (filter_match)
else
print ("Adding below usb filter !! \n")
print (filter_match)
end
#return vm_info.match(/"VendorId:[ ]*#{vendor_id}\nProductId:[ ]*#{product_id}\n/i)
return vm_info.include? filter_match
end
def better_usbfilter_add(vb, priority, vendor_id, product_id, filter_name)
#
# This is a workaround for the fact VirtualBox doesn't provide
# a way for preventing duplicate USB filters from being added.
#
# TODO: Implement this in a way that it doesn't get run multiple
# times on each Vagrantfile parsing.
#
if not usbfilter_exists(vendor_id, product_id)
vb.customize ["usbfilter", "add", priority,
"--target", :id,
"--name", filter_name,
"--vendorid", vendor_id
]
end
end
# Docstring to install download OpenVINO and Run Some Updates
$OpenVinoScript = <<CNTRLSCRIPT
echo "Updating System"
sudo apt-get -y update && sudo apt-get -y upgrade
echo "Installing Developer Tools"
sudo apt-get -y install build-essential cmake unzip pkg-config
echo "Installing Libraries for Video and Image"
sudo apt-get -y install libjpeg-dev libpng-dev libtiff-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get -y install libxvidcore-dev libx264-dev
echo "Installing Packages that is used to for Numerical Optimization for OpenCV"
sudo apt-get -y install libatlas-base-dev gfortran
echo "Installing Python Developmental Headers"
sudo apt-get -y install python3-dev
mkdir -p /home/vagrant/pip && cd /home/vagrant/pip && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && sudo python get-pip.py
echo "Installing OpenVINO as defined here https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux.html "
mkdir -p /home/vagrant/openvino && cd /home/vagrant/openvino && wget -q --show-progress http://registrationcenter-download.intel.com/akdlm/irc_nas/15382/l_openvino_toolkit_p_2019.1.094.tgz && tar -xvzf l_openvino_toolkit_p_2019.1.094.tgz
CNTRLSCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# https://vagrantcloud.com/ubuntu
config.vm.box = "ubuntu/xenial64"
config.vm.box_url = "https://app.vagrantup.com/ubuntu/boxes/xenial64/versions/20190411.0.0/providers/virtualbox.box"
config.vm.network "private_network", type: "dhcp"
# Forward ports
#config.vm.network "forwarded_port", guest: 8080, host: 8080 # web server
#config.vm.network "forwarded_port", guest: 5432, host: 5432 # Postgres
config.vm.provider "virtualbox" do |v|
v.name = "OpenVinoVM"
v.memory = 4096
v.cpus = 2
v.customize ['modifyvm', :id, '--usb', 'on']
# USB 2 Controller : --usbehci
# USB 3 Controller : --usbxhci
v.customize ["modifyvm", :id, "--usbxhci", "on"]
better_usbfilter_add(v, "0", "0x040e", "0x2485", "Modivius1")
better_usbfilter_add(v, "1", "0x03e7", "0x2485", "Modivius2")
#v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'Modivius1', '--vendorid', '0x040e']
#v.customize ['usbfilter', 'add', '1', '--target', :id, '--name', 'Modivius2', '--vendorid', '0x03e7']
end
# If true, then any SSH connections made will enable agent forwarding.
# config.ssh.forward_agent = true
# Share additional folders to the guest VM.
# config.vm.synced_folder "data", "/data"
# Bash provision script
#config.vm.provision "shell", path: "provision/setup.sh"
# Upload user's ssh key into box so it can be used for downloading stuff from stash
ssh_key_path = "~/.ssh/"
config.vm.provision "shell", inline: "mkdir -p /home/vagrant/.ssh"
config.vm.provision "file", source: "#{ ssh_key_path + 'id_rsa' }", destination: "/home/vagrant/.ssh/id_rsa"
config.vm.provision "file", source: "#{ ssh_key_path + 'id_rsa.pub' }", destination: "/home/vagrant/.ssh/id_rsa.pub"
config.vm.provision "shell", inline: $OpenVinoScript
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment