theano版本的xnor源码使用(使用cpu)

来源:互联网 发布:logstash 性能优化 编辑:程序博客网 时间:2024/06/01 17:51

1下载xnor源码

theano-xnor-net的github地址:

https://github.com/iefiac/theano-xnor-net

下载后文件如下:

2安装依赖的工具

sudo apt-get install python-dev

sudo apt-get install python-pip

sudo apt-get install python-nose

sudo apt-get install g++

sudo apt-get install git

3安装numpy和scipy

3.1 numpy:

sudo pip install numpy

这样做估计pip速度会很慢,中间会掉线导致下载失败。使用国内镜像源进行安装:

可以在使用pip的时候加参数-i 地址
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库。

几个镜像库:

新版ubuntu要求使用https源,要注意。
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/

所以:pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider

3.2安装scipy:pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider

3.3先检测numpy:python -c "import numpy;numpy.test()"

     后检测scipy   :python -c "import scipy;scipy.test()"

无error且出现ok字样说明成功,否则需要卸载重新安装:

sudo apt-get remove python-numpy

sudo apt-get remove python-scipy

4安装theano:

sudo pip install Theano 

注意上边的Theano是大写,下边的是小写

测试:python -c "import theano;theano.test()"

通过说明theano安装好了

5安装Lasagne:

Lasagne的github地址:https://github.com/Lasagne/Lasagne#installation

pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/master/requirements.txt

pip install https://github.com/Lasagne/Lasagne/archive/master.zip

pip下载费劲可以使用国内的镜像源或者使用源码编译的方法也可以。

6安装pylearn2:

Pylearn2地址:http://deeplearning.net/software/pylearn2/#download-and-installation

6.1下载:git clone git://github.com/lisa-lab/pylearn2.git

进入polearn2目录,一般在home下,不行就搜:

     sudo python setup.py develop

 或  sudo python setup.py develop --user

6.2设置Pylearn2的数据地址

cd home

gedit .bashrc

文件名前的点表示是隐藏文件

在文件后面加上

export PYLEARN2_DATA_PATH=数据的路径

我的是export PYLEARN2_DATA_PATH=/home/qqq/pylearn2/data

7使用mnist训练文件:

7.1必须将格式改为float32

打开终端,直接输入:sudo gedit ~/.theanorc

[global]

floatX=float32

device=cpu

保存退出

7.2需要编译opencv

7.3启动训练:进入train目录:bash train_mnist.sh

   训练后生成.npz文件,记住该文件的路径。

8.test文件使用:

python test/mnist_test.py --model <model file path> --no <no of images to test>   --mode <fixed OR float>

python 文件名              --model 模型路径           --no 检测的数量(mnist最大10000)--mode 默认float

可先使用python 文件名寻求帮助

mnist使用:

python mnist_test.py  --model mnist_allxnor_mlp.npz --no 10000 

0 0