私的AI研究会 > OpenModelZoo3

Open Model Zoo Demos を動かす3

 OpenVINO™ Toolkit に付属するデモソフトを動かしてアプリケーションで推論エンジンを使用する方法を調べる。その3

※ 最終更新:2021/05/16 

Image Inpainting Python Demo

 GMCNN によるイメージ インペインティング。画像の穴を埋めるために適切なピクセル情報を推定する。

使用する事前トレーニング済みモデル

デモの実行

▲ 「2021.3」
  • 実行時のディレクトリ: /opt/intel/openvino_2021/deployment_tools/open_model_zoo/demos/image_inpainting_demo/python/ ^ 実行ファイル    : python3 image_inpainting_demo.py
  • 「-h」オプションを指定してアプリケーションを実行すると、次の使用法メッセージが表示される。
    $ python3 image_inpainting_demo.py' -h
    usage: image_inpainting_demo.py [-h] -m MODEL [-i INPUT] [-d DEVICE]
                                    [-p PARTS] [-mbw MAX_BRUSH_WIDTH]
                                    [-ml MAX_LENGTH] [-mv MAX_VERTEX] [--no_show]
                                    [-o OUTPUT] [-ac C C C] [-ar]
    
    Options:
      -h, --help            Show this help message and exit.
      -m MODEL, --model MODEL
                            Required. Path to an .xml file with a trained model.
      -i INPUT, --input INPUT
                            path to image.
      -d DEVICE, --device DEVICE
                            Optional. Specify the target device to infer on; CPU,
                            GPU, FPGA, HDDL or MYRIAD is acceptable. The demo will
                            look for a suitable plugin for device specified.
                            Default value is CPU
      -p PARTS, --parts PARTS
                            Optional. Number of parts to draw mask. Ignored in GUI
                            mode
      -mbw MAX_BRUSH_WIDTH, --max_brush_width MAX_BRUSH_WIDTH
                            Optional. Max width of brush to draw mask. Ignored in
                            GUI mode
      -ml MAX_LENGTH, --max_length MAX_LENGTH
                            Optional. Max strokes length to draw mask. Ignored in
                            GUI mode
      -mv MAX_VERTEX, --max_vertex MAX_VERTEX
                            Optional. Max number of vertex to draw mask. Ignored
                            in GUI mode
      --no_show             Optional. Don't show output. Cannot be used in GUI
                            mode
      -o OUTPUT, --output OUTPUT
                            Optional. Save output to the file with provided
                            filename. Ignored in GUI mode
      -ac C C C, --auto_mask_color C C C
                            Optional. Use automatic (non-interactive) mode with
                            color mask.Provide color to be treated as mask (3 RGB
                            components in range of 0...255). Cannot be used
                            together with -ar.
      -ar, --auto_mask_random
                            Optional. Use automatic (non-interactive) mode with
                            random mask for inpainting (with parameters set by -p,
                            -mbw, -mk and -mv). Cannot be used together with -ac.

  • 実行例 1「CPU」表示された元画像をマウスで消去(ペイント)したのち、「Enter」キーを押して処理開始すると可能な限り元画像を再生表示する。

    $ python3 image_inpainting_demo.py -m ~/model/public/FP32/gmcnn-places2-tf.xml -i ~/Images/car_m.jpg
    • 消去するブラシのサイズは変更できる。
    • PCの環境によってはマウスのブラシ消去ができない場合がある。
  • 実行例1 2「CPU」ランダムマスク(元画像を入力してランダムなパターンで画像を変更したのち元画像に戻す)
    $ python3 image_inpainting_demo.py -m ~/model/public/FP32/gmcnn-places2-tf.xml -i ~/Images/car_m.jpg -ar
    • 元画像を入力しているので処理結果に説得力が乏しい。
    • 加工済みの画像から元画像を推定する下記を試す。
  • 実行例 3「CPU」マスクの色指定(マスクで修正された画像を入力し元画像を推定する)
    $ python3 image_inpainting_demo.py -m ~/model/public/FP32/gmcnn-places2-tf.xml -i ~/Images/prants_ed_m.png -ac 255 255 255
    • 適当に画像微修正を入れたものを入力画像として元画像を推定する。

実用例

  1. 元画像
  2. 家の前の標識を消す
  3. 推論エンジンで画像を修正する
    $ python3 image_inpainting_demo.py -m ~/model/public/FP32/gmcnn-places2-tf.xml -i ~/Images/landscape_ed.png -ac 255 255 255
    左が標識を消した入力画像、右が推論エンジンで処理した画像。結構実用になりそう。

Colorization Python Demo

 ニューラル ネットワークを使用してモノクロビデオの色付けをする。

使用する事前トレーニング済みモデル

デモの実行

▲ 「2021.3」
  • 実行時のディレクトリ: /opt/intel/openvino_2021/deployment_tools/open_model_zoo/demos/colorization_demo/python/
  • 実行ファイル    : python3 colorization_demo.py
  • 「-h」オプションを指定してアプリケーションを実行すると、次の使用法メッセージが表示される。
    $ python3 colorization_demo.py -h
    usage: colorization_demo.py [-h] -m MODEL [-d DEVICE] -i "<path>" [--no_show]
                                [-v] [-u UTILIZATION_MONITORS]
    
    Options:
      -h, --help            Help with the script.
      -m MODEL, --model MODEL
                            Required. Path to .xml file with pre-trained model.
      -d DEVICE, --device DEVICE
                            Optional. Specify target device for infer: CPU, GPU,
                            FPGA, HDDL or MYRIAD. Default: CPU
      -i "<path>", --input "<path>"
                            Required. Input to process.
      --no_show             Optional. Disable display of results on screen.
      -v, --verbose         Optional. Enable display of processing logs on screen.
      -u UTILIZATION_MONITORS, --utilization_monitors UTILIZATION_MONITORS
                            Optional. List of monitors to show initially.
  • 実行例「CPU」
    $ python3 colorization_demo.py -m ~/model/public/FP32/colorization-v2.xml -i ~/Videos/mono03.mp4
    $ python3 colorization_demo.py -m ~/model/public/FP32/colorization-v2.xml -i ~/Videos/mono01.mp4

Image Deblurring Python* Demo

 手ぶれやそのほかの要因で起こるボケ画像を修正する。
 このサンプルデモは「2021.3」で追加になった。インストールされたディレクトリで実行する。

使用する事前トレーニング済みモデル

デモの実行

▲ 「2021.3」
  • 実行時のディレクトリ: /opt/intel/openvino_2021/inference_engine/demos/deblurring_demo/python
  • 実行ファイル    : python3 deblurring_demo.py
  • 「-h」オプションを指定してアプリケーションを実行すると、次の使用法メッセージが表示される。
    mizutu@ubuntu2004dk2:/opt/intel/openvino_2021/inference_engine/demos/deblurring_demo/python$ python3 deblurring_demo.py -h
    usage: deblurring_demo.py [-h] -m MODEL -i INPUT [-d DEVICE]
                              [-nireq NUM_INFER_REQUESTS] [-nstreams NUM_STREAMS]
                              [-nthreads NUM_THREADS] [--loop] [-o OUTPUT]
                              [-limit OUTPUT_LIMIT] [--no_show]
                              [-u UTILIZATION_MONITORS]
    
    Options:
      -h, --help            Show this help message and exit.
      -m MODEL, --model MODEL
                            Required. Path to an .xml file with a trained model.
      -i INPUT, --input INPUT
                            Required. An input to process. The input must be a
                            single image, a folder of images or anything that
                            cv2.VideoCapture can process.
      -d DEVICE, --device DEVICE
                            Optional. Specify the target device to infer on; CPU,
                            GPU, FPGA, HDDL or MYRIAD is acceptable. The demo will
                            look for a suitable plugin for device specified.
                            Default value is CPU.
    
    Inference options:
      -nireq NUM_INFER_REQUESTS, --num_infer_requests NUM_INFER_REQUESTS
                            Optional. Number of infer requests
      -nstreams NUM_STREAMS, --num_streams NUM_STREAMS
                            Optional. Number of streams to use for inference on
                            the CPU or/and GPU in throughput mode (for HETERO and
                            MULTI device cases use format
                            <device1>:<nstreams1>,<device2>:<nstreams2> or just
                            <nstreams>).
      -nthreads NUM_THREADS, --num_threads NUM_THREADS
                            Optional. Number of threads to use for inference on
                            CPU (including HETERO cases).
    
    Input/output options:
      --loop                Optional. Enable reading the input in a loop.
      -o OUTPUT, --output OUTPUT
                            Optional. Name of output to save.
      -limit OUTPUT_LIMIT, --output_limit OUTPUT_LIMIT
                            Optional. Number of frames to store in output. If 0 is
                            set, all frames are stored.
      --no_show             Optional. Don't show output.
      -u UTILIZATION_MONITORS, --utilization_monitors UTILIZATION_MONITORS
                            Optional. List of monitors to show initially.
  • 実行例「CPU」
    mizutu@ubuntu2004dk2:/opt/intel/openvino_2021/inference_engine/demos/deblurring_demo/python$ python3 deblurring_demo.py -i ~/Images/desk.png -m ~/model/public/FP32/deblurgan-v2.xml --loop
    [ INFO ] Initializing Inference Engine...
    [ INFO ] Loading network...
    [ INFO ] Reading network from IR...
    [ INFO ] Loading network to CPU plugin...
    [ INFO ] Starting inference...
    To close the application, press 'CTRL+C' here or switch to the output window and press ESC key
    Latency: 311.6 ms
    FPS: 3.2
    mizutu@ubuntu2004dk2:/opt/intel/openvino_2021/inference_engine/demos/deblurring_demo/python$ python3 deblurring_demo.py -i ~/Images/deblurred_image.png -m ~/model/public/FP32/deblurgan-v2.xml --loop
    [ INFO ] Initializing Inference Engine...
    [ INFO ] Loading network...
    [ INFO ] Reading network from IR...
    [ INFO ] Loading network to CPU plugin...
    [ INFO ] Starting inference...
    To close the application, press 'CTRL+C' here or switch to the output window and press ESC key
    Latency: 307.8 ms
    FPS: 3.2

Image Processing C++ Demo

 元の低解像度のイメージから高解像度のイメージを再構築するスーパー解像度(super resolution)のデモと、手ぶれやそのほかの要因で起こるボケ画像を修正する(deblurring)デモの選択したタイプでイメージ処理を行う。  このサンプルデモは「2021.4」で追加になった。インストールされたディレクトリで実行する。
 Super Resolution C++ Demo は廃止になった。

対応する事前トレーニング済みモデル

デモの実行

▲ 「2021.4」
  • 実行時のディレクトリ: ~/omz_demos_build/intel64/Release
  • 実行ファイル    : ./image_processing_demo
  • 「-h」オプションを指定してアプリケーションを実行すると、次の使用法メッセージが表示される。
    $ ./image_processing_demo -h
    [ INFO ] InferenceEngine: 	IE version ......... 2021.4
    	Build ........... 0
    
    image_processing_demo_async [OPTION]
    Options:
    
        -h                        Print a usage message.
        -at "<type>"              Required. Type of the network, either 'sr' for Super Resolution task or 'deblur' for Deblurring
        -i "<path>"               Required. An input to process. The input must be a single image, a folder of images, video file or camera id.
        -m "<path>"               Required. Path to an .xml file with a trained model.
        -o "<path>"               Optional. Name of the output file(s) to save.
        -limit "<num>"            Optional. Number of frames to store in output. If 0 is set, all frames are stored.
          -l "<absolute_path>"    Required for CPU custom layers. Absolute path to a shared library with the kernel implementations.
              Or
          -c "<absolute_path>"    Required for GPU custom kernels. Absolute path to the .xml file with the kernel descriptions.
        -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. The demo will look for a suitable plugin for a specified device.
        -pc                       Optional. Enables per-layer performance report.
        -nireq "<integer>"        Optional. Number of infer requests. If this option is omitted, number of infer requests is determined automatically.
        -nthreads "<integer>"     Optional. Number of threads.
        -nstreams                 Optional. Number of streams to use for inference on the CPU or/and GPU in throughput mode (for HETERO and MULTI device cases use format <device1>:<nstreams1>,<device2>:<nstreams2> or just <nstreams>)
        -loop                     Optional. Enable reading the input in a loop.
        -no_show                  Optional. Do not show processed video.
        -output_resolution        Optional. Specify the maximum output window resolution in (width x height) format. Example: 1280x720. Input frame size used by default.
        -u                        Optional. List of monitors to show initially.
    [E:] [BSL] found 0 ioexpander device
    
    Available target devices:  CPU  GNA
  • 実行例「CPU」
$ ./image_processing_demo -i ~/Images/image-low.bmp -m ~/model/intel/FP32/single-image-super-resolution-1033.xml -at sr
[ INFO ] InferenceEngine: 	IE version ......... 2021.4
	Build ........... 0
[ INFO ] Parsing input parameters
[ INFO ] Reading input
[ INFO ] Loading Inference Engine
[ INFO ] Device info: 
[ INFO ] 	CPU
	MKLDNNPlugin version ......... 2021.4
	Build ........... 0
Loading network files
[ INFO ] Batch size is forced to 1.
[ INFO ] Loading model to the device
[ WARN:0] global ../opencv/modules/highgui/src/window.cpp (661) createTrackbar UI/Trackbar(Orig/Diff | Res@Image Processing Demo - Super Resolution (press A for help)): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback.
$ ./image_processing_demo -i ~/Images/girl.bmp -m ~/model/intel/FP32/single-image-super-resolution-1033.xml -at sr
[ INFO ] InferenceEngine: 	IE version ......... 2021.4
	Build ........... 0
[ INFO ] Parsing input parameters
[ INFO ] Reading input
[ INFO ] Loading Inference Engine
[ INFO ] Device info: 
[ INFO ] 	CPU
	MKLDNNPlugin version ......... 2021.4
	Build ........... 0
Loading network files
[ INFO ] Batch size is forced to 1.
[ INFO ] Loading model to the device

Hello Query Device Python* Sample

 使用可能なすべての推論エンジン デバイスを照会し、サポートされているメトリックと既定の構成値を出力する。
 このサンプルでは、デバイス API のクエリ機能の使用方法を示す。

デモの実行

更新履歴

参考資料

オフィシャルサイト


Last-modified: 2021-08-19 (木) 14:09:16