matplotlibでNimbus Roman No9 Lを使う
でグラフの文字をNimbus Roman No9 L
にしたい
フォントのインストール
$ sudo apt -y install fonts-texgyre
使用するコード
test.mplstyle
は空のテキスト
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt with plt.style.context('test.mplstyle'): x = np.linspace(0,3,20) y = x**2 + 1 plt.plot(x, y, "r-") plt.xlabel("x") plt.ylabel("y") plt.savefig("test.pdf")
プロットしてみる
この時点ではフォント設定を変更していないのでデフォルトのフォントが使用される
$ python3 plot.py $ pdffonts test.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- DejaVuSans Type 3 Custom yes no no 14 0
フォントを変える
font.serifにNimbus Roman No9 L
を指定
$ vim test.mplstyle font.serif : Nimbus Roman No9 L font.family : serif
して実行
$ python3 plot.py ... UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans ... $ pdffonts test.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- DejaVuSans Type 3 Custom yes no no 14 0
serif
が見つからないらしい
font.familyに直接フォントを指定
$ vim test.mplstyle font.family : Nimbus Roman No9 L
して実行
$ python3 plot.py ... UserWarning: findfont: Font family ['Nimbus Roman No9 L'] not found. Falling back to DejaVu Sans ... $ pdffonts test.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- DejaVuSans Type 3 Custom yes no no 14 0
Nimbus Roman No9 L
が見つからない
Nimbus Roman No9 Lはインストールされているのか確認
インストールはされている
$ fc-list | grep Nimbus /usr/share/fonts/type1/gsfonts/n021024l.pfb: Nimbus Roman No9 L:style=Medium Italic /usr/share/fonts/type1/gsfonts/n021004l.pfb: Nimbus Roman No9 L:style=Medium /usr/share/fonts/type1/gsfonts/n022003l.pfb: Nimbus Mono L:style=Regular /usr/share/fonts/type1/gsfonts/n021023l.pfb: Nimbus Roman No9 L:style=Regular Italic /usr/share/fonts/type1/gsfonts/n019063l.pfb: Nimbus Sans L:style=Regular Condensed Italic /usr/share/fonts/type1/gsfonts/n019064l.pfb: Nimbus Sans L:style=Bold Condensed Italic /usr/share/fonts/type1/gsfonts/n022023l.pfb: Nimbus Mono L:style=Regular Oblique /usr/share/fonts/type1/gsfonts/n019043l.pfb: Nimbus Sans L:style=Regular Condensed /usr/share/fonts/type1/gsfonts/n019044l.pfb: Nimbus Sans L:style=Bold Condensed /usr/share/fonts/type1/gsfonts/n021003l.pfb: Nimbus Roman No9 L:style=Regular /usr/share/fonts/type1/gsfonts/n019023l.pfb: Nimbus Sans L:style=Regular Italic /usr/share/fonts/type1/gsfonts/n022004l.pfb: Nimbus Mono L:style=Bold /usr/share/fonts/type1/gsfonts/n019024l.pfb: Nimbus Sans L:style=Bold Italic /usr/share/fonts/type1/gsfonts/n019004l.pfb: Nimbus Sans L:style=Bold /usr/share/fonts/type1/gsfonts/n022024l.pfb: Nimbus Mono L:style=Bold Oblique /usr/share/fonts/type1/gsfonts/n019003l.pfb: Nimbus Sans L:style=Regular
matplotlibのキャッシュを削除
$ rm -rf ~/.cache/matplotlib
ここでもう一度プロットするもNimbus Roman No9 L
が見つからない
$ python3 plot.py ... UserWarning: findfont: Font family ['Nimbus Roman No9 L'] not found. Falling back to DejaVu Sans ... $ pdffonts test.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- DejaVuSans Type 3 Custom yes no no 14 0
texモードをONにする
$ vim test.mplstyle text.usetex : true font.serif : Nimbus Roman No9 L font.family : serif
DejaVuではなくなったが、Nimbus Romanでもない
$ python3 plot.py ... UserWarning: findfont: Font family ['Nimbus Roman No9 L'] not found. Falling back to DejaVu Sans ... $ pdffonts test.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- CMMI10 Type 1 Builtin yes no no 17 0 CMR10 Type 1 Builtin yes no no 13 0
なんとなくTimesにしてみたら
$ vim test.mplstyle text.usetex : true font.serif : Times font.family : serif
縦軸、横軸の文字(x
、y
)がNimbus Romanになった
$ python3 plot.py $ pdffonts test.pdf name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- CMMI10 Type 1 Builtin yes no no 17 0 NimbusRomNo9L-Regu Type 1 Custom yes no no 13 0
texモードをOFFにする
$ vim test.mplstyle text.usetex : false font.family : Times
DejaVu
$ python3 plot.py ... UserWarning: findfont: Font family ['Nimbus Roman No9 L'] not found. Falling back to DejaVu Sans ... name type encoding emb sub uni object ID ------------------------------------ ----------------- ---------------- --- --- --- --------- DejaVuSans Type 3 Custom yes no no 14 0
まとめ
matplotlibでNimbus Roman No9 Lを使用するときは
fonts-texgyre
をインストールして、matplotlibのフォント設定を
text.usetex : true font.serif : Times font.family : serif
にする
Ubuntu16.04にTheanoをインストールする
Ubuntu16.04でのDeepLearning用環境構築
で構築した環境にTheanoをPython3用に追加する
インストール
$ python3 --version Python 3.5.2 $ sudo apt-get -y install \ python3-dev \ libopenblas-dev $ pip3 install --user --upgrade pip $ pip3 install --user numpy scipy nose sphinx pydot-ng $ pip3 install --user theano
確認
ubuntu14.04 theanoとかgpgpu環境構築メモ - 備忘録とか日常とか
のcheck.py
をpython3用に書き換えて実行する
変更点
print
=>print()
xrange
=>range
$ THEANO_FLAGS=floatX=float32,device=gpu python3 ~/check.py ... Used the gpu
続 GPGPU用マシンにCUDAをインストール - まんぼう日記
も実行してみる
$ THEANO_FLAGS=floatX=float32,device=gpu python3 ~/.local/lib/python3.5/site-packages/theano/misc/check_blas.py ... We executed 10 calls to gemm with a and b matrices of shapes (5000, 5000) and (5000, 5000). Total execution time: 0.39s on GPU.
まとめ
動いた!!
References
Ubuntu16.04でのDeepLearning用環境構築
Ubuntuのインストール前に,SecureBootを無効にしておいた方が良いかもしれない
本記事では,途中で気づいたのでその時に無効にした
構成
ハードウェア
ソフトウェア
初期設定
ネットワーク
$ sudo apt-get -y install resolvconf $ sudo nmcli con mod eno1 ipv4.method manual $ sudo nmcli con mod eno1 ipv4.address 192.168.1.23/24 $ sudo nmcli con mod eno1 ipv4.dns 192.168.1.1 $ sudo nmcli con mod eno1 ipv4.gateway 192.168.1.1 $ sudo nmcli con down eno1 && sudo nmcli con up eno1
アップデート
$ sudo apt-get update $ sudo apt-get -y upgrade $ sudo apt-get -y dist-upgrade
OpenSSHのインストール
$ sudo apt-get -y install openssh-server $ sudo systemctl start sshd $ sudo systemctl enable sshd
CUDA
確認
以下のコマンドで,何も出てこないことを確認する
$ sudo dpkg -l | grep nvidia $ sudo dpkg -l | grep cuda
Nvidiaドライバのインストール
リポジトリ(Proprietary GPU Drivers : “Graphics Drivers” team)
を登録して,ドライバをインストールする
途中で,secure bootを無効にするかを聞かれたが,無効にせずに続行した
$ sudo add-apt-repository ppa:graphics-drivers/ppa $ sudo apt-get update $ sudo apt-get -y install nvidia-370
再起動し,GPUが認識されているかを確認すると下のメッセージが表示され,GPUが認識されなかった
$ sudo reboot $ nvidia-smi NVIDIA-SMI has failed because it couldn\'t communicate with the NVIDIA driver
BIOSでSecure Bootを無効化(Boot->Secure Boot
で,OS Type
をOther OS
に変更)すると認識できるようになった
$ nvidia-smi Mon Jan 16 17:24:34 2017 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 370.28 Driver Version: 370.28 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 1080 Off | 0000:05:00.0 On | N/A | | 43% 37C P8 9W / 220W | 52MiB / 8110MiB | 0% Default | +-------------------------------+----------------------+----------------------+ | 1 GeForce GTX 1080 Off | 0000:06:00.0 Off | N/A | | 43% 32C P8 8W / 220W | 1MiB / 8113MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 1176 G /usr/lib/xorg/Xorg 50MiB | +-----------------------------------------------------------------------------+
CUDA本体のインストール
CUDA 8.0 Downloads | NVIDIA DeveloperでLinux -> x86_64 -> Ubuntu -> 16.04 -> runfile(local)
の順に進み,Downloadからダウンロードし,指示通りにインストールする
debパッケージを使用すると,下のエラーが出たのでrunfileを使用することにしている
$ sudo apt-get update (省略) W: Invalid 'Date' entry in Release file /var/lib/apt/lists/partial/developer.download.nvidia.com_compute_cuda_repos_ubuntu1604_x86%5f64_Release
$ chmod u+x cuda_8.0.44_linux-run $ sudo ./cuda_8.0.44_linux-run Do you accept the previously read EULA? accept/decline/quit: accept Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48? (y)es/(n)o/(q)uit: n Install the CUDA 8.0 Toolkit? (y)es/(n)o/(q)uit: y Enter Toolkit Location [ default is /usr/local/cuda-8.0 ]: Do you want to install a symbolic link at /usr/local/cuda? (y)es/(n)o/(q)uit: y Install the CUDA 8.0 Samples? (y)es/(n)o/(q)uit: y Enter CUDA Samples Location [ default is "ホームディレクトリ" ]: ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work. To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file: sudo <CudaInstaller>.run -silent -driver Logfile is /tmp/cuda_install_1804.log
メッセージ通りに,以下のコマンドでインストールする
$ sudo ./cuda_8.0.44_linux-run -silent -driver $ sudo reboot
パスを通す
$ echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc $ echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc $ source ~/.bashrc $ sudo ldconfig $ which nvcc
インストールの確認
ホームディレクトリにインストールしたサンプルコードを実行する
$ sudo apt-get install mesa-common-dev freeglut3-dev $ cd NVIDIA_CUDA-8.0_Samples/5_Simulations/nbody $ make $ ./nbody -benchmark -numbodies=256000 -device=0 Run "nbody -benchmark [-numbodies=<numBodies>]" to measure performance. -fullscreen (run n-body simulation in fullscreen mode) -fp64 (use double precision floating point values for simulation) -hostmem (stores simulation data in host memory) -benchmark (run benchmark to measure performance) -numbodies=<N> (number of bodies (>= 1) to run in simulation) -device=<d> (where d=0,1,2.... for the CUDA device to use) -numdevices=<i> (where i=(number of CUDA devices > 0) to use for simulation) -compare (compares simulation results running once on the default GPU and once on the CPU) -cpu (run n-body simulation on the CPU) -tipsy=<file.bin> (load a tipsy model file for simulation) NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled. > Windowed mode > Simulation data stored in video memory > Single precision floating point simulation > 1 Devices used for simulation gpuDeviceInit() CUDA Device [0]: "GeForce GTX 1080 > Compute 6.1 CUDA device: [GeForce GTX 1080] number of bodies = 256000 256000 bodies, total time for 10 iterations: 2365.614 ms = 277.036 billion interactions per second = 5540.718 single-precision GFLOP/s at 20 flops per interaction
Python
$ python --version Python 2.7.12 $ sudo apt-get -y install python-pip python-dev
cuDNN
NVIDIA cuDNN | NVIDIA DeveloperからcuDNN v5.1 (Jan 20, 2017), for CUDA 8.0のcuDNN v5.1 Library for Linuxをダウンロードする(要登録)
$ tar xf cudnn-8.0-linux-x64-v5.1.tgz $ sudo mv cuda/include/cudnn.h /usr/local/cuda/include $ sudo mv cuda/lib64/libcudnn* /usr/local/cuda/lib64/
TensorFlow
Bazelのインストール
Installing Bazel - Bazelを参考にインストールを行う.
$ sudo apt-get -y install openjdk-8-jdk $ echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list $ curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - $ sudo apt-get update $ sudo apt-get -y install bazel
TensorFlow本体のインストール
cuDNNのバージョンを確認しておく.今回は5.1.5
.
$ ls /usr/local/cuda/lib64/ | grep libcudnn libcudnn.so libcudnn.so.5 libcudnn.so.5.1.5 libcudnn_static.a
./configure
のところでcuDNNのバージョンに5.1
とかを入れると,下のエラーがでたので気をつけるInvalid path to cuDNN toolkit. Neither of the following two files can be found: /usr/local/cuda-8.0/lib64/libcudnn.so.5.0 /usr/local/cuda-8.0/libcudnn.so.5.0 .5.0
$ sudo apt-get -y install python-numpy $ git clone https://github.com/tensorflow/tensorflow $ sudo mv tensorflow /usr/local/src/ $ cd /usr/local/src/tensorflow
./configure
する
$ ./configure Please specify the location of python. [Default is /usr/bin/python]: Please specify optimization flags to use during compilation [Default is -march=native]: Do you wish to use jemalloc as the malloc implementation? [Y/n] jemalloc enabled Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] No Google Cloud Platform support will be enabled for TensorFlow Do you wish to build TensorFlow with Hadoop File System support? [y/N] No Hadoop File System support will be enabled for TensorFlow Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] No XLA support will be enabled for TensorFlow Found possible Python library paths: /usr/local/lib/python2.7/dist-packages /usr/lib/python2.7/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python2.7/dist-packages] Using python library path: /usr/local/lib/python2.7/dist-packages Do you wish to build TensorFlow with OpenCL support? [y/N] No OpenCL support will be enabled for TensorFlow
CUDAサポートはy
にする
Do you wish to build TensorFlow with CUDA support? [y/N] y CUDA support will be enabled for TensorFlow Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
CUDAのバージョンを指定
Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0 Please specify the location where CUDA toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:
cuDNNのバージョンを指定
Please specify the Cudnn version you want to use. [Leave empty to use system default]: 5.1.5 Please specify the location where cuDNN 5.1.5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size.
GTX 1018を使用するので6.1
を指定
[Default is: "3.5,5.2"]: 6.1 INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes. ....... INFO: All external dependencies fetched successfully. Configuration finished
ビルド
$ bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package $ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg $ sudo pip install /tmp/tensorflow_pkg/tensorflow-0.12.1-cp27-cp27mu-linux_x86_64.whl
テストコードを動かしてみる
チュートリアル(Deep MNIST for Experts | TensorFlow) のコードがTensorFlowを遊び倒す! 2-1. MNIST For Experts - Platinum Data Blog by BrainPad にいい感じでまとまっているので,これを実行する.
そのままだとエラーが出たので
- 4行目を
import input_data
からfrom tensorflow.examples.tutorials.mnist import input_data
に変更する strides...
の後のコメント直前に紛れ込んでいる全角スペースを消す
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], # 真ん中2つが縦横のストライド padding='SAME')
テストコードを実行
$ time python test_mnist.py 2017-01-31 15:54:53: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally 2017-01-31 15:54:53: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally 2017-01-31 15:54:53: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally 2017-01-31 15:54:53: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally 2017-01-31 15:54:53: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes. Extracting MNIST_data/train-images-idx3-ubyte.gz Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes. Extracting MNIST_data/train-labels-idx1-ubyte.gz Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes. Extracting MNIST_data/t10k-images-idx3-ubyte.gz Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes. Extracting MNIST_data/t10k-labels-idx1-ubyte.gz 2017-01-31 15:55:05: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 2017-01-31 15:55:05: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 2017-01-31 15:55:05: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. 2017-01-31 15:55:05: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations. 2017-01-31 15:55:07: I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate (GHz) 1.7335 pciBusID 0000:06:00.0 Total memory: 7.92GiB Free memory: 7.81GiB 2017-01-31 15:55:07: W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x3f8d150 2017-01-31 15:55:07: I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 1 with properties: name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate (GHz) 1.7335 pciBusID 0000:05:00.0 Total memory: 7.92GiB Free memory: 7.81GiB 2017-01-31 15:55:07: I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 1 2017-01-31 15:55:07: I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y Y 2017-01-31 15:55:07: I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 1: Y Y 2017-01-31 15:55:07: I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:06:00.0) 2017-01-31 15:55:07: I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:05:00.0) (省略) step 19700, training accuracy 1 step 19800, training accuracy 1 step 19900, training accuracy 1 2017-01-31 16:07:51: W tensorflow/core/common_runtime/bfc_allocator.cc:217] Ran out of memory trying to allocate 3.90GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory is available. test accuracy 0.9933 real 1m52.055s user 2m30.684s sys 0m34.948s
一応GPUを使って動いてそう.
Caffe
Caffe | Installation: Ubuntuに書いている通りに依存関係をインストールする
$ sudo apt-get -y install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler $ sudo apt-get -y install --no-install-recommends libboost-all-dev $ sudo apt-get -y install libatlas-base-dev libopenblas-dev
その他必要なものをインストール
$ sudo apt-get -y install cmake $ sudo apt-get -y install liblmdb-dev libgflags-dev libgoogle-glog-dev doxygen $ sudo apt-get -y install python-skimage
Caffe | Installationの通りにビルドする
$ git clone https://github.com/BVLC/caffe $ sudo mv caffe /usr/local/src/ $ cd /usr/local/src/caffe $ mkdir build $ cd build $ cmake .. $ make all -j$(nproc) $ make pycaffe -j$(nproc) $ make install
テスト
$ make runtest $ make pytest
テストコードを動かしてみる
Caffe | LeNet MNIST Tutorialの通りに実行する
$ cd /usr/local/src/caffe $ ./data/mnist/get_mnist.sh $ ./examples/mnist/create_mnist.sh
学習用のスクリプトを動かす
$ ./examples/mnist/train_lenet.sh
学習中にnvidia-smi
してみるとGPUが使用されていることがわかる
$ nvidia-smi +-----------------------------------------------------------------------------+ | NVIDIA-SMI 370.28 Driver Version: 370.28 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 1080 Off | 0000:05:00.0 Off | N/A | | 43% 42C P2 36W / 220W | 2MiB / 8111MiB | 0% Default | +-------------------------------+----------------------+----------------------+ | 1 GeForce GTX 1080 Off | 0000:06:00.0 Off | N/A | | 43% 45C P2 99W / 220W | 245MiB / 8113MiB | 72% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 1 1320 C ./build/tools/caffe 243MiB | +-----------------------------------------------------------------------------+
インストール
よくわからなかったので,とりあえずシンボリックリンクを貼ってパスを通しておく
$ sudo ln -s /usr/local/src/caffe/build/install /usr/local/caffe
~/.bashrc
でパスを通す
$ vim ~/.bashrc export PATH='/usr/local/caffe/bin:$PATH' export LD_LIBRARY_PATH='/usr/local/caffe/lib:$LD_LIBRARY_PATH' export PYTHONPATH="/usr/local/caffe/python:$PYTHONPATH"
Chainer
依存関係のインストール
$ sudo apt-get install libhdf5-dev python-5py
ダウンロード
$ git clone https://github.com/pfnet/chainer.git $ sudo mv chainer /usr/local/src/
ビルド
README.md
を参考に,以下の作業を行う
cuDNNを参照できるように~/.bashrc
に追加する
$ export CFLAGS=-I/usr/local/cuda/include $ export LDFLAGS=-L/usr/local/cuda/lib64 $ export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
依存関係をインストール
$ sudo pip install cython pillow h5py
chainer本体をインストール
$ cd /usr/local/src/chainer $ sudo CUDA_PATH=/usr/local/cuda pip install -e .
確認
$ python >>> import chainer >>>
サンプルを動かす
$ python /usr/local/src/chainer/examples/mnist/train_mnist.py --gpu 0 GPU: 0 # unit: 1000 # Minibatch-size: 100 # epoch: 20 Downloading from http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz... Downloading from http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz... Downloading from http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz... Downloading from http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz... epoch main/loss validation/main/loss main/accuracy validation/main/accuracy elapsed_time 1 0.190653 0.0928411 0.9429 0.97 12.4203 2 0.0732004 0.0702411 0.9773 0.9784 14.8764 3 0.0492653 0.0659305 0.984616 0.9805 17.2205 4 0.0347082 0.0761442 0.988432 0.98 19.5639 5 0.0270766 0.0734653 0.991231 0.9775 21.9413 6 0.0251563 0.072476 0.991882 0.9805 24.2833 7 0.0199481 0.0731711 0.993382 0.9806 26.6206 8 0.0196817 0.10124 0.993565 0.9754 28.953 9 0.0164322 0.0876729 0.994548 0.9809 31.2958 10 0.0154422 0.122923 0.995282 0.9742 33.6844 11 0.0168969 0.110708 0.994832 0.9767 36.0464 12 0.0107279 0.0856068 0.996665 0.9813 38.3777 13 0.0117293 0.0990945 0.996215 0.9795 40.7093 14 0.00978297 0.120509 0.996566 0.9777 43.0557 15 0.0117472 0.107208 0.996866 0.9789 45.4293 16 0.0113395 0.0992631 0.996682 0.981 47.7726 17 0.00929236 0.0937098 0.997383 0.9828 50.1157 18 0.0103718 0.104585 0.997149 0.9796 52.4636 19 0.00638133 0.0990586 0.997999 0.981 54.8122 20 0.00843088 0.105776 0.997666 0.9823 57.1418
を実行中にnvidia-smi
で確認する
$ nvidia-smi +-----------------------------------------------------------------------------+ | NVIDIA-SMI 370.28 Driver Version: 370.28 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 1080 Off | 0000:05:00.0 Off | N/A | | 43% 42C P0 45W / 220W | 2MiB / 8111MiB | 0% Default | +-------------------------------+----------------------+----------------------+ | 1 GeForce GTX 1080 Off | 0000:06:00.0 Off | N/A | | 43% 36C P2 41W / 220W | 117MiB / 8113MiB | 0% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 1 3023 C python 115MiB | +-----------------------------------------------------------------------------+
最後に
とりあえず,インストールとサンプルの実行はできた
References
virtualenvにMedpyをインストールする
virtualenvにMedpyをインストールした際の備忘録
実行環境は
* CentOS7
* Python2.7.10 (Python2.7.10をソースからインストールする)
仮想環境作成
$ mkvirtualenv --python /opt/python2.7.10/bin/python2.7 --no-site-packages medpy
numpyのインストール
(medpy)$ pip install numpy Successfully installed numpy-1.10.1
scipyのインストール
gcc,必要なライブラリのインストール
$ sudo dnf -y install gcc-g++ $ sudo dnf -y install atlas-devel lapack-devel blas-devel
scipyをインストール
(medpy)$ pip install scipy Successfully installed scipy-0.16.1
nibabelのインストール
MedPyで
- NifTi - Neuroimaging Informatics Technology Initiative (.nii, nii.gz)
- Analyze (plain, SPM99, SPM2) (.hdr/.img, .img.gz)
などを読み込むのに必要
(medpy)$ pip install nibabel Successfully installed nibabel-2.0.2
pydicomのインストール
MedPyでDicomを読み込むのに必要
(medpy)$ pip install pydicom Successfully installed pydicom-0.9.9
ITKのインストール
MedPyで
- NifTi - Neuroimaging Informatics Technology Initiative (.nii, nii.gz)
- Analyze (plain, SPM99, SPM2) (.hdr/.img, .img.gz)
- Dicom - Digital Imaging and Communications in Medicine (.dcm, .dicom)
- Itk/Vtk MetaImage (.mhd, .mha/.raw)
- Nrrd - Nearly Raw Raster Data (.nhdr, .nrrd)
などを読み込むのに必要
CentOS7へのリポジトリの追加方法まとめを参考にEPELを追加し,インストールする
$ sudo yum --enablerepo=epel -y install itk-devel
MedPyのインストール
(medpy)$ pip install medpy Successfully installed medpy-0.2.2
virtualenvにmatplotlibをインストールする
matplotlibをvirtualenvにインストールした際の備忘録
実行環境は
* CentOS7
* Python2.7.10 (Python2.7.10をソースからインストールする)
仮想環境作成
$ mkvirtualenv --python /opt/python2.7.10/bin/python2.7 --no-site-packages plot $ workon plot
numpyのインストール
(plot)$ pip install numpy Successfully installed numpy-1.9.3
matplotlibのインストール
必要なライブラリをインストール
$ sudo yum -y install agg tk-devel $ sudo yum -y install libpng-devel
matplotlibのインストール
(plot)$ pip install matplotlib Successfully installed cycler-0.9.0 matplotlib-1.5.0 pyparsing-2.0.5 python-dateutil-2.4.2 pytz-2015.7 six-1.10.0
show()しても何も表示されない
matplotlibrc
の場所を確認する
$ workon plot (plot)$ python >>> import matplotlib >>> matplotlib.matplotlib_fname() u'${PYENV}/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc' >>> quit()
matplotlib(36行目)のbackendを書き換える
$ vi matplotlibrc backend : tkagg
これでも動かなければmatplotlibを再インストールする
(plot)$ pip uninstall matplotlib (plot)$ pip --no-cache-dir install matplotlib
CentOS7にPyCharmをインストールする
CentOS7へのPyCharmのインストール方法
アップデートも同じ方法でできる
ダウンロード
Python IDE & Django IDE for Web developers : JetBrains PyCharm
のGet PyCharm Nowに移動して
- 有料版を使用する場合はDownload Professional
(JetBrainsのIDEをアカデミックライセンスで使用する) - 無料版を使用する場合はDownload Community
からダウンロードする.
(今回は無料版のpycharm-community-4.5.4.tar.gz
をダウンロードした)
インストール
ダウンロードしたファイルを解凍するだけ
$ tar -xf pycharm-community-4.5.4.tar.gz $ sudo mv pycharm-community-4.5.4 /opt/pycharm
初回起動・初期設定
$ cd /opt/pycharm/bin $ ./pycharm.sh
初期設定では
とした
IDEの設定
File -> Settings -> Editor -> General -> Appearance
- Show line numbers
- Show whitespaces
Samba上にプロジェクトを置く場合
External file changes sync may be slow
を表示させないために
File -> Settings -> Appearance & Behavior -> Notifications
からFile Watcher MessagesをNo popupにする
ショートカットの作成 (GNOME3)
pycharm.desktop
を作成する
#!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application Name=PyCharm Community Edition Icon=/opt/pycharm/bin/pycharm.png Exec="/opt/pycharm/bin/pycharm.sh" %f Comment=Develop with pleasure! Categories=Development;IDE; Terminal=false StartupWMClass=jetbrains-pycharm-ce OnlyShowIn=Old;
NIPYをvirtualenvにインストールする方法
NIPYをFedora22にインストールした際の備忘録
virtualenvはここでインストールした状態のものを使用した.
仮想環境作成
$ mkvirtualenv --no-site-packages nipy $ workon nipy (nipy)$ pip install --upgrade pip
nibabelのインストール
(nipy)$ pip install nibabel Successfully installed nibabel-2.0.1
numpyのインストール
(nipy)$ pip install numpy Successfully installed numpy-1.9.2
scipyのインストール
gccのインストール
$ sudo dnf -y install gcc-g++
scipyに必要なライブラリをインストール
$ sudo dnf -y install atlas-devel lapack-devel blas-devel
scipyをインストール
(nipy)$ pip install scipy Successfully installed scipy-0.16.0
sympyをインストール
(nipy)$ pip install sympy Successfully installed sympy-0.7.6.1
nipyをインストール
(nipy)$ pip install nipy Successfully installed nipy-0.3.0