1.首先是安装前的准备工作:
由于安装过程中用到gcc 所以安装Development tools
命令:
yum groupinstall "Development tools"
提前安装python依赖包
命令:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

下载解压:
python setup.py install
安装工具
通过pip list 能输出版本号说明安装成功。
我在安装过程中提示缺少setuptools
在安装pip之前错误解决:
ImportError: No module named setuptools 解决方案
shell中输入:
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
以上工作完成后重新安装pip,进入pip目录执行命令python setup.py install
安成后输入pip list 有信息输出标识安装成功
但是安装完成之后下载包很慢,所以需要将连接修改为国内镜像地址,提高下载速度
几个主要的镜像源:
清华: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/
Linux系统下,在用修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]trusted-host=mirrors.aliyun.com
windows下,直接在user目录中创建一个pip目录,如:C:\Users\XXX\pip,新建文件pip.ini。内容和上边一样。
4.安装paddle
首先说一下paddlepaddle是什么?paddlepaddle是百度旗下深度学习开源平台。
pip install paddlepaddle
安装需要几分钟,需要下载所依赖的包。
上边的三个步骤需要没有任何错误的情况下,第四步安装成功的可能性会大一点。

由于安装过程中用到gcc 所以安装Development tools
命令:
yum groupinstall "Development tools"
提前安装python依赖包
命令:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
2.安装python
下载python,如果想要安装最新的可以到
https://www.python.org/ftp/python/这个网址找
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
tar vxf Python-2.7.11.tgz
cd Python-2.7.11.tgz
./configure --enable-shared --prefix=/usr/local
make && make install
注意: 如果编译时加上了--enable-shared,才会编译这个共享库 要是不加运行程序的时候提示找不到这个共享库。
如果忘记加--enable-shared这个参数会导致运行的时候提示找不到lib库。
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
(1)编辑 vi /etc/ld.so.conf
非root权限帐号登录,使用 sudo vi /etc/ld.so.conf 命令
添加上python2.7的lib库地址,如我的/usr/local/python27/lib,保存文件
(2)执行 /sbin/ldconfig -v命令,如果不是root权限帐号登录,就使用 sudo /sbin/ldconfig -v。这样 ldd 才能找到这个库,执行python2.7得时候就不会报错了
/etc/ld.so.conf:
这个文件记录了编译时使用的动态链接库的路径。
默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件
就像我指定了,/usr/local ,没有指定 --prefix=/usr 这样lib库就装到了/usr/local下,而又没有在/etc/ld.so.conf中添加/usr/local/lib,就会报错了,
下载python,如果想要安装最新的可以到
https://www.python.org/ftp/python/这个网址找
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
tar vxf Python-2.7.11.tgz
cd Python-2.7.11.tgz
./configure --enable-shared --prefix=/usr/local
make && make install
注意: 如果编译时加上了--enable-shared,才会编译这个共享库 要是不加运行程序的时候提示找不到这个共享库。
如果忘记加--enable-shared这个参数会导致运行的时候提示找不到lib库。
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
(1)编辑 vi /etc/ld.so.conf
非root权限帐号登录,使用 sudo vi /etc/ld.so.conf 命令
添加上python2.7的lib库地址,如我的/usr/local/python27/lib,保存文件
(2)执行 /sbin/ldconfig -v命令,如果不是root权限帐号登录,就使用 sudo /sbin/ldconfig -v。这样 ldd 才能找到这个库,执行python2.7得时候就不会报错了
/etc/ld.so.conf:
这个文件记录了编译时使用的动态链接库的路径。
默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件
就像我指定了,/usr/local ,没有指定 --prefix=/usr 这样lib库就装到了/usr/local下,而又没有在/etc/ld.so.conf中添加/usr/local/lib,就会报错了,
3.安装pip工具
官网:https://pypi.python.org/pypi/pip#downloads :
python setup.py install
安装工具
通过pip list 能输出版本号说明安装成功。
我在安装过程中提示缺少setuptools
在安装pip之前错误解决:
ImportError: No module named setuptools 解决方案
shell中输入:
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
以上工作完成后重新安装pip,进入pip目录执行命令python setup.py install
安成后输入pip list 有信息输出标识安装成功
但是安装完成之后下载包很慢,所以需要将连接修改为国内镜像地址,提高下载速度
几个主要的镜像源:
清华: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/
Linux系统下,在用修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
[global]index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]trusted-host=mirrors.aliyun.com
windows下,直接在user目录中创建一个pip目录,如:C:\Users\XXX\pip,新建文件pip.ini。内容和上边一样。
4.安装paddle
首先说一下paddlepaddle是什么?paddlepaddle是百度旗下深度学习开源平台。
pip install paddlepaddle
安装需要几分钟,需要下载所依赖的包。
上边的三个步骤需要没有任何错误的情况下,第四步安装成功的可能性会大一点。
表示paddle安装成功
运行一个房价预测训练模型:
import os
import paddle.v2 as paddle
import paddle.v2.dataset.uci_housing as uci_housing
with_gpu = os.getenv('WITH_GPU', '0') != '0'
def main():
# init
paddle.init(use_gpu=with_gpu, trainer_count=1)
# network config
x = paddle.layer.data(name='x', type=paddle.data_type.dense_vector(13))
y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear())
y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1))
cost = paddle.layer.square_error_cost(input=y_predict, label=y)
# Save the inference topology to protobuf.
inference_topology = paddle.topology.Topology(layers=y_predict)
with open("inference_topology.pkl", 'wb') as f:
inference_topology.serialize_for_inference(f)
# create parameters
parameters = paddle.parameters.create(cost)
# create optimizer
optimizer = paddle.optimizer.Momentum(momentum=0)
trainer = paddle.trainer.SGD(
cost=cost, parameters=parameters, update_equation=optimizer)
feeding = {'x': 0, 'y': 1}
# event_handler to print training and testing info
def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
print "Pass %d, Batch %d, Cost %f" % (
event.pass_id, event.batch_id, event.cost)
if isinstance(event, paddle.event.EndPass):
if event.pass_id % 10 == 0:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
trainer.save_parameter_to_tar(f)
result = trainer.test(
reader=paddle.batch(uci_housing.test(), batch_size=2),
feeding=feeding)
print "Test %d, Cost %f" % (event.pass_id, result.cost)
# training
trainer.train(
reader=paddle.batch(
paddle.reader.shuffle(uci_housing.train(), buf_size=500),
batch_size=2),
feeding=feeding,
event_handler=event_handler,
num_passes=30)
# inference
test_data_creator = paddle.dataset.uci_housing.test()
test_data = []
test_label = []
for item in test_data_creator():
test_data.append((item[0], ))
test_label.append(item[1])
if len(test_data) == 5:
break
# load parameters from tar file.
# users can remove the comments and change the model name
# with open('params_pass_20.tar', 'r') as f:
# parameters = paddle.parameters.Parameters.from_tar(f)
probs = paddle.infer(
output_layer=y_predict, parameters=parameters, input=test_data)
for i in xrange(len(probs)):
print "label=" + str(test_label[i][0]) + ", predict=" + str(probs[i][0])
if __name__ == '__main__':
main()
结果: