網頁

2018年10月17日 星期三

ubuntu 16.04 install tensorflow

$ sudo apt update
$ sudo apt install python3-dev python3-pip
$ sudo pip3 install -U virtualenv
$ virtualenv --system-site-packages -p python3 ./venv
$ source ./venv/bin/activate
$ pip install --upgrade pip
$ pip list
$ pip install --upgrade tensorflow
$ python -c "import tensorflow as tf; print(tf.__version__)"
有顯示版本代表安裝完成
$ pip install tensorflow-gpu (要先安裝cuDNN,驗證版本cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2)
$ deactivate

TensorFlow from source in Ubuntu 18
https://medium.com/@isaaclascasas/tensorflow-from-source-in-ubuntu-18-4b5dcca910b9?fbclid=IwAR1-E-n7KStl8gPjriDEe4QZtXKZSJfQUK86q6DZRQLhp3Vj9_0qbwYA0MI

如果有顯示Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA,在跑CPU版本的tensorflow時要加入下面兩行API

$ import os
$ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

由於tensorflow默認分佈是在沒有CPU擴展的情況下構建的,例如SSE4.1,SSE4.2,AVX,AVX2,FMA等。默認版本(來自pip install tensorflow的版本)旨在與儘可能多的CPU兼容。若是用GPU版本的話,就不必在乎這個問題發生。

如果有顯示ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
$ ~/~/.zshrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
$ source ~/.zshrc

如果出現Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'
$ pip install tf-nightly  
$ pip install tf-nightly-gpu

沒有留言:

張貼留言