1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

なるべく簡単にtensorflowでGPUを使いたい

Posted at

はじめに

tensorflowでGPUを使用するためには、使用するtensorflowのバージョンに合わせて、CUDAやCuDNNをダウンロードしなくてはいけない。(いちいち画面操作でダウンロードしに行くのはめんどい....)
そこで、コマンドのみで簡単に行う方法をいくつか見たので自分でアレンジして実際にやっていきます

やり方

やり方については↓のファイルを保存して実行するだけです

environment.yml
name: tf_gpu #作りたい環境の名前
channels:
  - conda-forge
dependencies:
  - python=3.9
  - cudatoolkit=11.2 #tensorflowのverにあわせて
  - cudnn=8.1 #tensorflowのverにあわせて
  - pip
  - pip:
    - tensorflow==2.10.1
    - numpy==1.20.3  

Windowsで使いたいのでtensorflowは2.10までを使用します。
理由としてはTensorFlow公式にも記載している通りTensorflow2.10がWindowsでGPUをサポートする最後のバージョンだからです

実行

では実行して環境を作りましょう。
↓のコマンドを先ほどのファイルを置いてあるディレクトリで実行すればいいだけです

conda env create -f environment.yml

環境ができたら↓のコマンドでGPUが使用できるか確認します

check.py
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))

↓のように1と表示されればOKです

Num GPUs Available:  1

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?