windows10

Wndows10+WSL+TensorFlow

今回は古いCPUでもTensorFlowを動かしてみようということで

TensorFlow1.5をインストールします。

TensorFlow1.6からはAVX対応のCPUでしか動かないようです。

 IT用語辞典 e-Words
Intel AVXとは - IT用語辞典
http://e-words.jp/w/Intel_AVX.html
Intel AVX【Intel Advanced Vector Extensions】とは、Intel社のマイクロプロセッサ(MPU/CPU)に内蔵された拡張命令セットの一つで、複数のデータに一度に同じ演算を行うことができるSIMD方式の処理を実行するためのもの。2011年に登場したSandy Bridgeマイクロアーキ...

WSLについては過去記事参照

Ubuntu上にTensorFlow+GPUの環境を構築していきます。

まずはPythonのインストールから

Pythonは3.6以降だとTensorFlow1.5がインストールできないのでPythonは3.5にします。

そしてPython3.5はそのままだと面倒なので

2.7系をインストールしたのちpyenvで3.5をインストールします。(めんどい。。。)

$ sudo apt-get install python
$ python -V
Python 2.7.15rc1

pyenvのインストール

$ cd ~/
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ mkdir -p .pyenv/versions .pyenv/shims

 

環境変数の設定 ~/.bash_profile

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
eval "$(pyenv init -)"
$ source ~/.bash_profile

インストールシェルの実行

$ sudo .pyenv/plugins/python-build/install.sh

TensorFlowの作業用ディレクトリ作成

$ mkdir tf
$cd tf

Pythonのコンパイルに必要なライブラリをインストールします。

$ sudo apt-get install gcc make libssl-dev libbz2-dev zlib1g-dev
$ sudo apt-get install libreadline-dev 
$ sudo apt-get install libsqlite3-dev

更新

$ sudo apt-get update

 

Python3.5.6のインストール

$ pyenv install -v 3.5.6

確認

$ pyenv versions
* system (set by ~/.pyenv/version)
3.5.6

 

$ pyenv local 3.5.6
$ python -V
Python 3.5.6

うまく反映されていない場合はハッシュを再構築してください

$ pyenv rehash

 

CUDAのインストール

ppaリポジトリを追加してインストールします。

$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt-get install nvidia-390
$ sudo apt-get install nvidia-cuda-toolkit

 

↓以下の方法だとうまく行かなかったので上記の方法でやりなおしました。

CUDA Toolkit Archiveから9.1をダウンロードします。

※Ubuntuのバージョンは17.04を選択してます。

2019年3月時点でのWSLではIPC connect call failerのエラーがでると思いますので

以下のコマンドで代用してください。

$ curl -sL http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub | sudo apt-key add

さらにバージョン指定でインストールします。

$ sudo apt-get install cuda-9-0

 

続いてcuDNNをインストールします。

ここからファイルをファイルをダウンロードしますがアカウントが必要です。

私はGoogleアカウントでログインしました。

CUDA9.1向けの

libcudnn7_7.1.3.16-1+cuda9.1_amd64.deb

libcudnn7-dev_7.1.3.16-1+cuda9.1_amd64.deb

をダウンロードします。

それぞれのパッケージをインストールします。

$ sudo dpkg -i libcudnn7_7.1.3.16-1+cuda9.1_amd64.deb
$ sudo dpkg -i libcudnn7-dev_7.1.3.16-1+cuda9.1_amd64.deb

 

$ pip install tensorflow-gpu==1.5.0

 

以上で古いCPUでもtensorflowでGPUを使って学習が可能になります。