飞桨学习及部署

2021-02-20 20:20 阅读 993 views 次 飞桨学习及部署已关闭评论

笔记:

https://blog.csdn.net/guojiahuiEmily/article/details/113859105

部署:

centos安装python2.7:

https://www.cnblogs.com/harrymore/p/9024287.html

这里得变:
./configure --enable-optimizations --enable-shared --enable-unicode=ucs4
make && make altinstall

如果报错找不到so文件,执行

/sbin/ldconfig

还不行的话:

3. 使用命令whereis libpython2.7.so.1.0得到如下结果就说明

libpython2.7.so.1: /usr/local/lib/libpython2.7.so.1.0

4. 如果whereis没有结果,或者还有import错误,可以尝试如下操作:

在/etc/ld.so.conf中加入新行/usr/local/lib

/sbin/ldconfig

安装AI服务:

https://github.com/PaddlePaddle/Serving/blob/v0.4.0/README_CN.md

https://github.com/PaddlePaddle/Serving/blob/v0.4.0/README_CN.md

pip install paddle-serving-server==0.4.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install paddle-serving-app==0.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install paddle-serving-client==0.4.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
tar -xzf uci_housing.tar.gz

测试1:
python -m paddle_serving_server.serve --model uci_housing_model --thread 10 --port 9292

from paddle_serving_client import Client
import numpy as np

client = Client()
client.load_client_config("uci_housing_client/serving_client_conf.prototxt")
client.connect(["127.0.0.1:9292"])
data = [0.0337, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727,
        -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]
fetch_map = client.predict(feed={"x": np.array(data).reshape(1,13,1)}, fetch=["price"])
print(fetch_map)

测试2:

python2.7 -m paddle_serving_server.serve --model uci_housing_model --thread 10 --port 9292 --name uci

这么调用不行:
curl -H "Content-Type:application/json" -X POST -d '[0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332]' http://127.0.0.1:9292/uci/prediction



安装python3.6(失败,也可不用):

https://www.cnblogs.com/zimo-jing/p/11873413.html

这里得变:
./configure --enable-optimizations --enable-shared --prefix=/usr/local/python36

 

vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/python36/bin

ln -s  /usr/bin/python3  /usr/bin/python36

如果报错找不到so文件,执行

/sbin/ldconfig

还不行的话:

3. 使用命令whereis libpython2.7.so.1.0得到如下结果就说明

libpython2.7.so.1: /usr/local/lib/libpython2.7.so.1.0

4. 如果whereis没有结果,或者还有import错误,可以尝试如下操作:

在/etc/ld.so.conf中加入新行/usr/local/lib

/sbin/ldconfig


glibc-2.18.tar.gz
mkdir build && cd build

../configure  --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin



pip install paddlehub --upgrade -i https://mirror.baidu.com/pypi/simple 
hub run ernie_gen_couplet --input_text '风吹云乱天垂泪' --use_gpu False --beam_width 1
 

运行启动命令

```
$ hub serving start -m ernie_gen_couplet -p 8866
```
这样就完成了一个服务化API的部署,默认端口号为8866。

*NOTE: 如使用GPU预测,则需要在启动服务之前,请设置CUDAVISIBLEDEVICES环境变量,否则不用设置。*

### 4-2:发送预测请求

配置好服务端,以下数行代码即可实现发送预测请求,获取预测结果

```
import requests
import json

# 发送HTTP请求

data = {'texts':["人增福寿年增岁"],
'use_gpu':False, 'beam_width':1}
headers = {"Content-type": "application/json"}
url = "http://127.0.0.1:8866/predict/ernie_gen_couplet"
r = requests.post(url=url, headers=headers, data=json.dumps(data))

# 保存结果
results = r.json()["results"]
for result in results:
print(result)
```


py代码直接推理:

https://paddleinference.paddlepaddle.org.cn/quick_start/python_demo.html

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:飞桨学习及部署 | 文档
分类:电脑技术 标签:

评论已关闭!