LoginSignup
0
1

More than 5 years have passed since last update.

機械学習実装時のコード(gpu、chainer、ubuntu)

Last updated at Posted at 2018-09-22

事前にインスールするもの(python3系)

numpy, pandas, scipy, matplotlib, numba, chainer, sklearn をpip3で。
他に
tkiinterを、sudo apt-get -y install python3-tk

gpu関連

1秒ごとにgpuの使用状況を表示
nvidia-smi -l 1

gpuを稼働するには、コードもgpu対応のものに書き換えないといけない。
https://qiita.com/ikeyasu/items/246515375b34e9fb4846

GPUで実行するには
Chainクラスはto_gpuメソッドを持ち、この引数にGPU IDを指定すると、指定したGPU IDのメモリ上にネットワークの全パラメータを転送します。こうしておくと、前進計算も学習の際のパラメータ更新なども全部GPU上で行われるようになります。GPU IDとして-1を使うと、すなわちこれはCPUを意味します。

chainer に GPU 計算をさせるときは model を GPU に移してから optimizer と紐付ける
http://buq.hateblo.jp/entry/2016/02/16/222006

numpy配列とcupy配列の変換は「cupy」の関数
・cupy ⇒ numpy配列へ変換:cupy.asnumpy
・numpy ⇒ cupy配列へ変換:cupy.asarray
を使うとできます。
https://qiita.com/samacoba/items/d18e6cf09f544477aff4

pythonでgpuを駆動させるとき

python3 ****.py -gpu 0
を実行

ほかに

「Chainer v4 ビギナー向けチュートリアル」
https://qiita.com/mitmul/items/1e35fba085eb07a92560
「Deep LearningフレームワークChainerのアドベントカレンダー」
https://qiita.com/advent-calendar/2017/chainer
「TensorFlow Advent Calendar 2016」
https://qiita.com/advent-calendar/2016/tensorflow

0
1
0

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
0
1