LoginSignup
1
9

More than 3 years have passed since last update.

Surface Pro (Windows)で PlaidML をバックエンドに Keras を動かしてみた

Last updated at Posted at 2018-06-02

はじめに

新幹線の乗車中に Deep Learning を動かしたいときありませんか?今回は Surface Pro の Intel GPU (Open CL) を使った PlaidML バックエンドの Keras を動かしてみます。

Windows の Python は Anaconda を使ってます。(セットアップは以下の「Pythonのインストール」を参考にしてください)
https://qiita.com/kekekekenta/items/19972a45025a97330e21#pyhton%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB

PlaidMLの環境を整える

PlaidML用に環境を分けておきたいので、新たに環境を作成します。

C:\Users\kenta\Documents>conda create -n plaidml python=3.5
C:\Users\kenta\Documents>activate plaidml

plaidmlのサンプルプログラムを動かすためのパッケージとplaidmlをインストール。

(plaidml) C:\Users\kenta\Documents>conda install h5py imageio Pillow opencv
(plaidml) C:\Users\kenta\Documents>pip install pygame
(plaidml) C:\Users\kenta\Documents>pip install plaidml-keras

plaidmlのセットアップ。Surface ProなのでGPUとしては、Intel Graphics 540を選択。

(plaidml) C:\Users\kenta\Documents>plaidml-setup

PlaidML Setup (0.3.3)

Thanks for using PlaidML!

Some Notes:
  * Bugs and other issues: https://github.com/plaidml/plaidml
  * Questions: https://stackoverflow.com/questions/tagged/plaidml
  * Say hello: https://groups.google.com/forum/#!forum/plaidml-dev
  * PlaidML is licensed under the GNU AGPLv3

Default Config Devices:
   No devices.

Experimental Config Devices:
   opencl_intel_intel(r)_iris(tm)_graphics_540.0 : Intel(R) Corporation Intel(R) Iris(TM) Graphics 540 (OpenCL)
   opencl_cpu.0 : Intel(R) Corporation CPU (OpenCL)
   opencl_cpu.1 : Intel(R) Corporation CPU (OpenCL)

Using experimental devices can cause poor performance, crashes, and other nastiness.

Enable experimental device support? (y,n)[n]:y

Multiple devices detected (You can override by setting PLAIDML_DEVICE_IDS).
Please choose a default device:

   1 : opencl_intel_intel(r)_iris(tm)_graphics_540.0
   2 : opencl_cpu.0
   3 : opencl_cpu.1

Default device? (1,2,3)[1]:1

Selected device:
    opencl_intel_intel(r)_iris(tm)_graphics_540.0

PlaidML sends anonymous usage statistics to help guide improvements.
We'd love your help making it better.

Enable telemetry reporting? (y,n)[y]:y

Almost done. Multiplying some matrices...
Tile code:
  function (B[X,Z], C[Z,Y]) -> (A) { A[x,y : X,Y] = +(B[x,z] * C[z,y]); }
Whew. That worked.

Save settings to C:\Users\kenta\.plaidml? (y,n)[y]:y
Success!

サンプルプログラムの実行

サンプルプログラムを動かすためにplaidmlのgitリポジトリを取得。
(2020/10/4 @17ec084さんから提案があり、オリジナルのリポジトリ( https://github.com/plaidml/plaidvision.git )がリンク切れとのことで、forkされたと思われるリポジトリに変更しました。)

(plaidml) C:\Users\kenta\work>mkdir plaidml
(plaidml) C:\Users\kenta\work>cd plaidml
(plaidml) C:\Users\kenta\work\plaidml>git clone https://github.com/jbruestle/plaidvision.git
(plaidml) C:\Users\kenta\work\plaidml>cd plaidvision

サンプルプルグラムを動かしてみる。初回動作時は学習済みモデルをダウンロードするので少し時間がかかります。PlaidMLバックエンドで動いていることを確認。カメラ画像のリアルタイム分類で11fpsぐらいの速度。

(plaidml) C:\Users\kenta\work\plaidml\plaidvision>python ./plaidvision.py mobilenet
Using PlaidML backend.
INFO:plaidml:Opening device "opencl_intel_intel(r)_iris(tm)_graphics_540.0"
Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.6/mobilenet_1_0_224_tf.h5
17129472/17225924 [============================>.] - ETA: 0sDownloading data from https://s3.amazonaws.com/deep-learning-models/image-models/imagenet_class_index.json
24576/35363 [===================>..........] - ETA: 0s

試しに、KerasでTensorflow(CPU)バックエンドで動かしてみるとで動作確認してみる。カメラ画像のリアルタイム分類で2.6fpsぐらいの速度。

(plaidml) C:\Users\kenta\work\plaidml\plaidvision>activate py35
(py35) C:\Users\kenta\work\plaidml\plaidvision>python ./plaidvision.py mobilenet
Using TensorFlow backend.

さいごに

サンプルのカメラ画像のリアルタイム分類で4.2倍ぐらいの速度でしたが、自分で作った学習のプログラムだと速度が出ないので、もう少し調査が必要そうです。

参考URL

1
9
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
9