1. 卸載
pip uninstall tensorflow
2.設(shè)置虛擬環(huán)境
(http://pythonguidecn.readthedocs.io/zh/latest/dev/virtualenvs.html)
【虛擬環(huán)境是一個(gè)將不同項(xiàng)目所需求的依賴分別放在獨(dú)立的地方的一個(gè)工具,它給這些工程創(chuàng)建虛擬的Python環(huán)境。在安裝TensorFlow之前可以先創(chuàng)建虛擬的Python環(huán)境用于安裝。優(yōu)點(diǎn)是:它解決了“項(xiàng)目X依賴于版本1.x,而項(xiàng)目Y需要項(xiàng)目4.x”的兩難問題,而且使你的全局site-packages目錄保持干凈和可管理】 ?
運(yùn)行
virtualenv ~/VENVs/tf
3.安裝TensorFlow
可直接運(yùn)行
pip install tensorflow_gpu
4.更換pip源到國內(nèi)鏡像,安裝TensorFlow
在網(wǎng)速很差的情況下,可更換pip源到國內(nèi)鏡像,運(yùn)行
pip install tensorflow_gpu -i http://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn
關(guān)于國內(nèi)鏡像,看到了這篇博客 http://blog.csdn.net/chenghuikai/article/details/55258957
(1)pip國內(nèi)的一些鏡像
阿里云 http://mirrors.aliyun.com/pypi/simple/
中國科技大學(xué) https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清華大學(xué) https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學(xué)技術(shù)大學(xué) http://pypi.mirrors.ustc.edu.cn/simple/
(2)修改源方法:
a.臨時(shí)使用:
可以在使用pip的時(shí)候在后面加上-i參數(shù),指定pip源
eg: pip install *** -i https://pypi.tuna.tsinghua.edu.cn/simple
b.永久修改:
Linux:
修改 ~/.pip/pip.conf (沒有就創(chuàng)建一個(gè)), 內(nèi)容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
windows:
直接在user目錄中創(chuàng)建一個(gè)pip目錄,如:C:\Users\xx\pip,新建文件pip.ini,內(nèi)容如下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
5. 在虛擬環(huán)境下運(yùn)行TensorFlow
先進(jìn)入虛擬環(huán)境
. ~/VENVs/tf/bin/activate
就會(huì)進(jìn)入到運(yùn)行TensorFlow的環(huán)境下,顯示為:(tf) [****]$
之后就正常運(yùn)行
python *.py
退出虛擬環(huán)境,運(yùn)行
deactivate
6. 安裝其他包,比如scikit-image
pip install scikit-image pillow
同樣,如果網(wǎng)速慢,可以運(yùn)行
pip install scikit-image pillow -i http://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn
7. 看服務(wù)器gpu使用情況:
nvidia-smi
8. 指定gpu:
http://www.cnblogs.com/darkknightzh/p/6591923.html
當(dāng)有多個(gè)GPU,tensorflow默認(rèn)全部使用。如果想只使用部分GPU,可以設(shè)置CUDA_VISIBLE_DEVICES。在調(diào)用python程序時(shí),可以使用
(1)終端執(zhí)行程序時(shí)設(shè)置使用的GPU
CUDA_VISIBLE_DEVICES=1,2 python my_script.py? ? ? ? ? ? (Devices 1, 2 will be visible; device 0,3 is masked)
CUDA_VISIBLE_DEVICES=""? ? ? ? ? ? (No GPU will be visible)
(2)python代碼中設(shè)置使用的GPU
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "2"
作為新手,要學(xué)習(xí)的還很多~~記錄下來方便以后查找