Linux下安裝miniconda
- 在官網(wǎng)下載miniconda3
- 執(zhí)行:bash Miniconda3-latest-Linux-x86_64.sh 之后跟隨提示步驟,安裝過程中可以自動(dòng)添加路徑到配置文件,也可以之后進(jìn)行配置。在這期間輸入 yes no ?。ㄔ谶@里我是之后配置的所以執(zhí)行3)
- 將其添加到大環(huán)境變量中去
-vim ~/.bashrc
-export PATH=~/anaconda3/bin:$PATH
-source ~/.bashrc
創(chuàng)建虛擬環(huán)境并安裝theano (主要參考官網(wǎng)教程http://deeplearning.net/software/theano/install_ubuntu.html)
- 基于python2.7創(chuàng)建一個(gè)名為theano的環(huán)境: conda create --name theano python=2.7
- 進(jìn)入虛擬環(huán)境: source activate theano
-
-使用pip安裝:pip install Theano-使用conda安裝:conda install numpy scipy mkl pip install parameterized conda install theano pygpu - Install and configure the GPU drivers (這一步我沒有嘗試,因?yàn)楸緛砭桶惭b好了)
- 配置theanoGPU環(huán)境
vim ~/.theanorc
在空白文件中添加
[global]
floatX = float32
device = gpu3
[lib]
cnmem = 0.6 意味著有百分之60的顯存分給當(dāng)前終端 - 也可以不用5,直接在運(yùn)行的時(shí)候使用命令:THEANO_FLAGS='device=cuda,floatX=float32'
(默認(rèn)為cuda0) - 測試
test.py 文件:
from theano import function, config, shared, tensor
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, tensor.Elemwise) and
('Gpu' not in type(x.op).__name__)
for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')
執(zhí)行:THEANO_FLAGS='device=cuda,floatX=float32' python test.py
結(jié)果:
···
Using cuDNN version 5105 on context None
Mapped name None to device cuda0: GeForce GTX 750 Ti (0000:07:00.0)
[GpuElemwise{exp,no_inplace}(<GpuArrayType<None>(float64, (False,))>), HostFromGpu(gpuarray)(GpuElemwise{exp,no_inplace}.0)]
Looping 1000 times took 1.697514 seconds
Result is [ 1.23178032 1.61879341 1.52278065 ..., 2.20771815 2.29967753
1.62323285]
Used the gpu
···
說明GPU配置使用成功
安裝過程中出現(xiàn)的一些亂七八糟的問題
-
ValueError: You are tring to use the old GPU back-end. It was removed from Theano . Use device=cuda* now. See https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29 for more information.
解決方法:
1: vim ~/.bashrc
2:添加如下命令:
export THEANO_FLAGS='mode=FAST_RUN,device=cpu,floatX=float32'
3:使修改的theano設(shè)置生效:
source ~/.bashrc -
ModuleNotFoundError: No module named'nose'
解決辦法:pip install nosey - /home/lyzhang/.miniconda3/envs/lyzhang2/lib/python2.7/site-packages/theano/scan_module/scan_perform_ext.py:76: UserWarning: The file scan_perform.c is not available. This donot happen normally. You are probably in a strangesetup. This mean Theano can not use the cython code for scan. If youwant to remove this warning, use the Theano flag'cxx=' (set to an empty string) to disable all ccode generation.
"The file scan_perform.c is not available. This do"
解決方法: 卸載原來安裝的theano:pip uninstall theano
重新用pip安裝:pip install theano
菜鳥一枚,有寫的不對的地方歡迎留言指正呀~~