theano
一、搭建环境
安装:pip install theano==0.9.0
卸载:pip uninstall theano查看版本号:import theano
theano.__version__
设置gpu\cpu:
方法1:vim /root/.theanorc
[global]
model=FAST_RUN (该模式运行速度快)
device=cuda1 (或者gpu或cpu)
floatX=float32
[blas]
ldflags=-L/usr/lib/libblas.so
方法2:
THEANO_FLAGS=mode=FAST_RUN,device=cuda,floatX=float32 python test_new.py
备注:theano0.9以上版本,使用gpu新后端,device=gpu或cpu或cuda(新后端)
#test_theano_gpu.py测试gpu/cpu,https://www.cnblogs.com/shouhuxianjian/p/4590224.html
THEANO_FLAGS=mode=FAST_RUN,device=cuda,floatX=float32 python test_theano_gpu.py
<GpuArrayType<None>(float32, (False,))> 使用cpu
THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 python test_theano_gpu.py
<TensorType(float32, vector)> 使用cpu
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 python test_theano_gpu.py
<CudaNdarrayType(float32, vector)> 使用gpu
tensorflow和theano同时要使用GPU,如何设置?
如果.theanorc中device设置为gpu,那么tensorflow将无法使用GPU;
如果.theanorc中device设置为cuda,那么theano在第二次调用中将无法使用GPU;
因此,如果tensorflow和theano同时要使用GPU,.theanorc中device必须设置为cuda,而且指明哪一个cuda。如上面的device=cuda1。
与此同时,tensorflow不需要特别指定GPU。
pygpu安装:
git clone https://github.com/Theano/libgpuarray.git
cd libgpuarray
mkdir Build
cd Build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
make install
cd ..
python setup.py build
python setup.py install
sudo ldconfig
备注:有测试过pygpu==0.6.5与theano==0.9.0 或者pygpu==0.7.5与theano==1.0.0 OK.
pygpu版本如果为0.65,那么theano必须为0.9。如果为1.0,不兼容。无法成功import theano。
pygpu版本如果为0.75,那么theano必须为1.0。如果为0.9,不兼容。无法正常初始化pygpu。
例子:DeepAlgnmentNetwork: theano==0.9.0
error:immporting theano: AttributeError: 'module' object has no attribute 'find_graphviz'
解决方案:sudo pip uninstall -y pydot 或者 pip install pydot-ng
安装lasagne:https://github.com/Lasagne/Lasagne (深度框架)