LoginSignup
4
7

More than 3 years have passed since last update.

[備忘録] Tensorflowに関して

Last updated at Posted at 2020-09-23

はじめに

これまでTensorflow(Keras)を使ってみて、わかったことを整理しておきたいとと思います。

1. 仮想環境でのTensorflowの設置

Tensorflowを仮想環境に設置する時、Anacondaのconda命令とPythonのpip命令を使うケースに分けられます。それぞれの特徴について、下記の表に整理します。

項目 conda pip
設置コマンド conda install -c anaconda tensorflow-gpu pip install --upgrade tensorflow
メリット CUDA, cuDNNも一緒に自動的に設置される。超便利! 2020.09時点でTensorflow 2.3
pip install -r requirement.txtが大変便利
デメリット 2020.09時点でTensorflow 2.1が最新Version.
tensorflow-estimatorのVerisonが2.3になっているケースがある。[2] その時は、conda install tensorflow-estimator==2.1.0で、tensorflow-estimator version 2.1を手動で設置
CUDA, CuDNNを自分で設置する必要がある。
pip設置のTensorflowのPerformaceがconda設置より悪いと言われている [1]

2. Tensorflow 2.0 with Keras

Tensorflow 2.0になったとき、変更点がいくつありました。

項目 Tensorflow 1.X Tensorflow 2.X
設置 TensorflowとKerasを別々設置 Tensorflowだけ設置
import 部分 import tensorflow as tf
import keras
import tensorflow as tf 
import tf.keras

3. Google Colabで、TensorflowのVersionを変更する方法

2020年9月の時点で、Google ColabでのTensorflowのVersionは2.3です。しかし、ローカルマシンのTensoflowのVersionが2.1だとしましょう。その時、Google ColabのTensorflowのVersionを2.3から2.1に変更する必要があります。

#Google Colabに入力
#Downgrade tensorflow

!pip install tensorflow-gpu==2.1
import tensorflow as tf
print(tf.__version__)

4.参考資料

  1. Stop Installing Tensorflow using pip for performance sake!
  2. AttributeError: module 'tensorflow' has no attribute 'compat'
4
7
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
4
7