OpenVINO 2022.1 GPU、NCS2の設定

OpenVINO 2022.1 RuntimeだけをインストールしてもGPUやNCS2のドライバは自動的には入らないので、インストールする必要があります。

GPUの場合

インストールディレクトリに移動して下記のコマンドを実行します。

cd install_dependencies

sudo -E ./install_NEO_OCL_driver.sh

Add OpenCL user to video group のメッセージが表示されますが、無視して進めてください。

NCS2の場合

cd install_dependencies

sudo -E ./install_NCS_udev_rules.sh

これで完了です。

Sampleアプリケーションを実行する

ドライバがインストールできれば、サンプルアプリケーションで動作を試すことが可能です。

下記のサンプルビルドを実行して、同じようにclassification_sample_asyncを実行してみます。

まずは、classification_sample_asyncに-hを付けて実行します。

$ ./classification_sample_async -m public/alexnet/FP16/alexnet.xml -h
[ INFO ] OpenVINO Runtime version ......... 2022.1.0
[ INFO ] Build ........... 2022.1.0-7019-cdb9bec7210-releases/2022/1
[ INFO ] 

classification_sample_async [OPTION]
Options:

    -h                      Print a usage message.
    -m "<path>"             Required. Path to an .xml file with a trained model.
    -i "<path>"             Required. Path to a folder with images or path to an image files: a .ubyte file for LeNet and a .bmp file for the other networks.
    -d "<device>"           Optional. Specify the target device to infer on (the list of available devices is shown below). Default value is CPU. Use "-d HETERO:<comma_separated_devices_list>" format to specify HETERO plugin. Sample will look for a suitable plugin for device specified.
[E:] [BSL] found 0 ioexpander device

Available target devices:  CPU  GNA  GPU  MYRIAD

一番下にAvailable target devices: CPU GNA GPU MYRIAD とありますが、これらが実行できるデバイスとなります。MYRIADはNCS2のことです。GNAはIntelのAIアクセラレーターですが、ここでは扱いません。

まずはCPUでの実行を行ってみます。

$ ./classification_sample_async -m public/alexnet/FP16/alexnet.xml -i apple.jpg
[ INFO ] OpenVINO Runtime version ......... 2022.1.0
[ INFO ] Build ........... 2022.1.0-7019-cdb9bec7210-releases/2022/1
[ INFO ] 
[ INFO ] Parsing input parameters
[ INFO ] Files were added: 1
[ INFO ]     apple.jpg
[ INFO ] Loading model files:
[ INFO ] public/alexnet/FP16/alexnet.xml
[ INFO ] model name: AlexNet
[ INFO ]     inputs
[ INFO ]         input name: data
[ INFO ]         input type: f32
[ INFO ]         input shape: {1, 3, 227, 227}
[ INFO ]     outputs
[ INFO ]         output name: prob
[ INFO ]         output type: f32
[ INFO ]         output shape: {1, 1000}
[ INFO ] Read input images
[ WARNING ] Image is resized from (300, 300) to (227, 227)
[ INFO ] Set batch size 1
[ INFO ] model name: AlexNet
[ INFO ]     inputs
[ INFO ]         input name: data
[ INFO ]         input type: u8
[ INFO ]         input shape: {1, 227, 227, 3}
[ INFO ]     outputs
[ INFO ]         output name: prob
[ INFO ]         output type: f32
[ INFO ]         output shape: {1, 1000}
[ INFO ] Loading model to the device CPU
[ INFO ] Create infer request
[ INFO ] Start inference (asynchronous executions)
[ INFO ] Completed 1 async request execution
[ INFO ] Completed 2 async request execution
[ INFO ] Completed 3 async request execution
[ INFO ] Completed 4 async request execution
[ INFO ] Completed 5 async request execution
[ INFO ] Completed 6 async request execution
[ INFO ] Completed 7 async request execution
[ INFO ] Completed 8 async request execution
[ INFO ] Completed 9 async request execution
[ INFO ] Completed 10 async request execution
[ INFO ] Completed async requests execution

Top 10 results:

Image apple.jpg

classid probability
------- -----------
957     0.9949166  
950     0.0017935  
989     0.0013619  
948     0.0009567  
951     0.0007669  
952     0.0001433  
949     0.0000239  
988     0.0000107  
940     0.0000079  
990     0.0000050  

次にGPUで実行してみます。

$ ./classification_sample_async -m public/alexnet/FP16/alexnet.xml -i apple.jpg -d GPU
[ INFO ] OpenVINO Runtime version ......... 2022.1.0
[ INFO ] Build ........... 2022.1.0-7019-cdb9bec7210-releases/2022/1
[ INFO ] 
[ INFO ] Parsing input parameters
[ INFO ] Files were added: 1
[ INFO ]     apple.jpg
[ INFO ] Loading model files:
[ INFO ] public/alexnet/FP16/alexnet.xml
[ INFO ] model name: AlexNet
[ INFO ]     inputs
[ INFO ]         input name: data
[ INFO ]         input type: f32
[ INFO ]         input shape: {1, 3, 227, 227}
[ INFO ]     outputs
[ INFO ]         output name: prob
[ INFO ]         output type: f32
[ INFO ]         output shape: {1, 1000}
[ INFO ] Read input images
[ WARNING ] Image is resized from (300, 300) to (227, 227)
[ INFO ] Set batch size 1
[ INFO ] model name: AlexNet
[ INFO ]     inputs
[ INFO ]         input name: data
[ INFO ]         input type: u8
[ INFO ]         input shape: {1, 227, 227, 3}
[ INFO ]     outputs
[ INFO ]         output name: prob
[ INFO ]         output type: f32
[ INFO ]         output shape: {1, 1000}
[ INFO ] Loading model to the device GPU
[ INFO ] Create infer request
[ INFO ] Start inference (asynchronous executions)
[ INFO ] Completed 1 async request execution
[ INFO ] Completed 2 async request execution
[ INFO ] Completed 3 async request execution
[ INFO ] Completed 4 async request execution
[ INFO ] Completed 5 async request execution
[ INFO ] Completed 6 async request execution
[ INFO ] Completed 7 async request execution
[ INFO ] Completed 8 async request execution
[ INFO ] Completed 9 async request execution
[ INFO ] Completed 10 async request execution
[ INFO ] Completed async requests execution

Top 10 results:

Image apple.jpg

classid probability
------- -----------
957     0.9951172  
950     0.0019550  
989     0.0013666  
948     0.0010319  
951     0.0008130  
952     0.0001484  
949     0.0000246  
988     0.0000116  
940     0.0000083  
990     0.0000054  

Loading model to the device GPU と表示されているので、GPUが使用されています。

次にNCS2を使用してみます。

$ ./classification_sample_async -m public/alexnet/FP16/alexnet.xml -i apple.jpg -d MYRIAD
[ INFO ] OpenVINO Runtime version ......... 2022.1.0
[ INFO ] Build ........... 2022.1.0-7019-cdb9bec7210-releases/2022/1
[ INFO ] 
[ INFO ] Parsing input parameters
[ INFO ] Files were added: 1
[ INFO ]     apple.jpg
[ INFO ] Loading model files:
[ INFO ] public/alexnet/FP16/alexnet.xml
[ INFO ] model name: AlexNet
[ INFO ]     inputs
[ INFO ]         input name: data
[ INFO ]         input type: f32
[ INFO ]         input shape: {1, 3, 227, 227}
[ INFO ]     outputs
[ INFO ]         output name: prob
[ INFO ]         output type: f32
[ INFO ]         output shape: {1, 1000}
[ INFO ] Read input images
[ WARNING ] Image is resized from (300, 300) to (227, 227)
[ INFO ] Set batch size 1
[ INFO ] model name: AlexNet
[ INFO ]     inputs
[ INFO ]         input name: data
[ INFO ]         input type: u8
[ INFO ]         input shape: {1, 227, 227, 3}
[ INFO ]     outputs
[ INFO ]         output name: prob
[ INFO ]         output type: f32
[ INFO ]         output shape: {1, 1000}
[ INFO ] Loading model to the device MYRIAD
[ INFO ] Create infer request
[ INFO ] Start inference (asynchronous executions)
[ INFO ] Completed 1 async request execution
[ INFO ] Completed 2 async request execution
[ INFO ] Completed 3 async request execution
[ INFO ] Completed 4 async request execution
[ INFO ] Completed 5 async request execution
[ INFO ] Completed 6 async request execution
[ INFO ] Completed 7 async request execution
[ INFO ] Completed 8 async request execution
[ INFO ] Completed 9 async request execution
[ INFO ] Completed 10 async request execution
[ INFO ] Completed async requests execution

Top 10 results:

Image apple.jpg

classid probability
------- -----------
957     0.9951172  
950     0.0018311  
989     0.0014277  
948     0.0009985  
951     0.0007782  
952     0.0001509  
7       0.0000000  
3       0.0000000  
8       0.0000000  
1       0.0000000  

Loading model to the device MYRIAD となっており、NCS2がちゃんと使われています。

みなさんもいろいろなサンプルやデモで試してみてください。