LoginSignup
36
31

More than 3 years have passed since last update.

TensorFlow 1.14.0 をWindows10にインストールしたときのトラブル対応方法

Last updated at Posted at 2019-08-11

この記事は

TensorFlowをWindows10にインストールしました。
かなり苦労したのでメモを残します。

※2019/11/30 誤字を修正しました。
※2020/04/19 リンクを修正しました。

環境

  • OS Windows10 Home
  • Python 3.6.8
  • TensorFlow 1.14.0
  • CUDA 10.0
  • cuDNN v7.6.2 (July 22, 2019), for CUDA 10.0
  • numpy 1.16.4
  • GPU NVIDIA GeForce 940M(Windows8を10にアップグレードした機種なので古い型番です。)

test.py の作成

正常動作確認に使用するファイルtest.pyを作成します。

test.py
import tensorflow as tf

print(tf.__version__)
print(tf.keras.__version__)

Python をインストール

Pythonのインストールについては、詳しくは書きません。
https://www.python.org/downloads/ からダウンロードして、
インストールします。

Python3.7系は、TensorFlow未対応です。
Python3.6系をインストールしてください。

TensorFlow をインストール

下記のコマンドでインストールします。

> pip install tensorflow-gpu==1.14

ちなみに、TensorFlow 1.14を選択した理由は、

> pip search tensorflow-gpu

を実行したときに出てきた一番最新のバージョンだったためです。

Windowsを再起動して、動作確認のため、動作確認のためtest.pyを実行します。

> python test.py

CUDA をインストール

CUDAがインストールされていないため、下記のようなエラーが表示されます。

例外が発生しました: ImportError
Could not find 'cudart64_100.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 10.0 from this URL: https://developer.nvidia.com/cuda-90-download-archive
  File "D:\usr\python\ml\tensorfolw.py", line 1, in <module>
    import tensorflow as tf

※ちなみにこのメッセージ、CUDA 10.0 が必要と言いつつ、リンク先はCUDA 9.0 です。注意してください。

https://developer.nvidia.com/cuda-toolkit-archive から「cuda_10.0.130_411.31_win10.exe」をダウンロードします。
「cuda_10.0.130_411.31_win10.exe」をダブルクリックしてインストールします。

私の環境では、古いバージョンがインストールされていたので「Visual Studio Integration」が失敗してインストールが止まりました。
これの対処についての詳細は、下で書きます。

インストールの正常終了後、Windowsを再起動して、動作確認のためtest.pyを実行します。

> python test.py

cuDNN をインストール

cuDNNがインストールされていないため、下記のようなエラーが表示されます。

例外が発生しました: ImportError
Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Note that installing cuDNN is a separate step from installing CUDA, and this DLL is often found in a different directory from the CUDA DLLs. You may install the necessary DLL by downloading cuDNN 7 from this URL: https://developer.nvidia.com/cudnn
  File "D:\usr\python\ml\tensorfolw.py", line 1, in <module>
    import tensorflow as tf

cuDNNをhttps://developer.nvidia.com/cudnn からダウンロードします。
※要アカウント作成・英語の質問あり

ダウンロード時は、インストールしたCUDAのバージョンと同じものを選択します。
CUDA 10.0をインストールしているので、
「Download cuDNN v7.6.2 (July 22, 2019), for CUDA 10.0」を選択しました。
この時にダウンロードしたファイルは、「cudnn-10.0-windows10-x64-v7.6.2.24.zip」でした。
ダウンロードしたファイル「cudnn-10.0-windows10-x64-v7.6.2.24.zip」を展開し、中にあるCUDAディレクトリを任意のディレクトリに置きます。

CUDAを置いたディレクトリをシステム環境変数に設定します。
※CUDAディレクトリを「c:\tf\」に置いた場合を想定。

環境変数 path
CUDNN_PATH c:\tf\CUDA
PATHの最後に追加 c:\tf\CUDA\bin

Windowsを再起動して、動作確認のためtest.pyを実行します。

> python test.py

numpy の再インストール

TensorFlowで対応していないバージョンのため、下記のような警告が出ています。

D:\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as
a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
D:\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as
a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
D:\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as
a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
D:\Python\Python36\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as
a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])

~ 略 ~

※pythonは、Dドライブにインストールしています。

この時、numpyは 「1.17.0」をインストールしていました。

https://github.com/tensorflow/tensorflow/issues/31249を参照すると、numpyのバージョンは、「1.16.4」が対応しているようです。
以下のように、再インストールします。

> pip uninstall numpy
> pip install numpy==1.16.4

動作確認のため、動作確認のためtest.pyを実行します。

> python test.py

やっと、error・warningが表示されなくなりました。

「Visual Studio Integration」が失敗する場合

私の環境では、元々CUDA 9.0 がインストールされていたため、CUDA 10.0 をインストールすると失敗します。
新しいバージョンをインストールするためには、NVIDIAのドライバ・ツールをとことんアンインストールしないとダメなようです。

削除対象は以下です。
- NVIDIA ディスプレイドライバ
- 「プログラムと機能」でNVIDIAとついているものすべて

NVIDIA ディスプレイドライバ の削除

私の環境の場合、「NVIDIA GeForce 940M」なので、これを「Windows 基本ディスプレイ アダプター」に変更します。

  1. 「デバイス マネージャ」から「ディスクプレイ アダプタ」を展開します。
  2. 「NVIDIA GeForce 940M」を右クリックして、「ドライバの更新」をクリックします。
  3. 「コンピュータを参照してドライバ ソフトウェアを検索」をクリックします。
  4. 「コンピュータ上の利用可能なドライバの一覧から選択します」をクリックします。
  5. 「互換性のあるハードウェアを表示」のチェックを外します。
  6. 「(標準ディスプレイ)」にある「Windows 基本ディスプレイ アダプター」を選択して「次へ」をクリックします。
  7. 「警告」が表示されるので「次へ」をクリックします。

「プログラムと機能」でNVIDIAとついているものすべて

「プログラムと機能」からは、削除できないものがあるので「Revo Uninstaller」というツールを使用します。

  1. https://www.revouninstaller.com/revo-uninstaller-free-download から「Revo Uninstaller FREEWARE」をダウンロードします。
  2. ダウンロードしたファイルをダブルクリックして、Revo Uninstallerをインストールします。
  3. Revo Uninstallerを実行して、NVIDIAとついているものすべてを削除します。
  4. 「C:\Program Files\NVIDIA Corporation」を削除します。
  5. 「C:\Program Files (x86)\NVIDIA Corporation」を削除します。

再起動して、CUDA のインストールを始めます。

最後に

CUDAやcuDNNの新しいバージョンをインストールすることは、非常に大変でした。
TensorFlow 2.0 のStable版が出るころには、もっと楽な手順が確立されていること祈ります。

36
31
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
36
31