LoginSignup
5

More than 5 years have passed since last update.

Google ColaboratoryのTensorflowを1.12にする。

Last updated at Posted at 2019-02-07

ColaboratolyのTensorflowが1.13.0rcになっていた!!

image.png

Colaboratolyで訓練して、結果のモデルをローカルPCで動かしているのでバージョンを合わせたいが、pipで検索しても1.13が無い。

(tf-gpu) C:\>pip search tensorflow
tensorflow (1.12.0)  - TensorFlow is an open source machine learning framework for
                       everyone.

Googleさん、導入早すぎる。。。

Tensorflowのバージョンを変更する


# cuda10がインストールされているが、1.12ではcuda9が対応バージョンなのでcuda10を削除 
# https://www.tensorflow.org/install/source#tested_build_configurations
!apt-get --purge remove cuda*
!apt autoremove

# cuda9のインストール
# ColaboratolyのUbuntuは18.04だけど16.04のcuda9で大丈夫!
!wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb
!apt-key add /var/cuda-repo-*/7fa2af80.pub
!apt-get update
!apt-get install cuda-9-0

# 1.12のGPU版をインストール
!pip uninstall -y tensorflow
!pip install tensorflow-gpu==1.12.0

まあまあ時間がかかるので、ひたすら待ちます。
この後に訓練したモデルを作って、ローカルPCの1.12で動かしたら正常にpredict出来ました。

※CUDA9.0を入れ替えないとImportError: libcudart.so.9.0: cannot open shared object file: No such file or directoryになります。

(蛇足)tf-nightlyを試してみた

tf-nightlyが1.13の先行したものだが、colab(1.13)で作ったモデルをローカルPCに持ってきてtf-nightly(1.13)で動かしてもダメでした。

ValueError: Tensor("Placeholder:0", shape=(), dtype=float32) must be from the same graph as Tensor("total:0", shape=(), dtype=resource).

これがmodel.predict()で発生して、原因の切り分けが出来なかったので諦めました。
placeholder:0なので変数だとわかるか、total:0って何?というのとdtype=resourceはどこにも指定してないタイプだったので、どこが悪いのか見当もつきませんでした。

読んだページ

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
5