conda paddleHub 一键安装
2022-02-09 本文已影响0人
LCSan
步骤
1、window环境下先安装miniconda x64
2、运行下面脚本安装,启动服务
3、python测试验证
install.bat脚本
@echo off
:M
cls
echo ┌─────────────────────────────────────────────────────────────────────┐
echo │ │
echo │ 操作选项: │
echo │ 1.安装环境 │
echo │ 2.启动服务 │
echo │ │
echo └─────────────────────────────────────────────────────────────────────┘
cd %~dp0
%~d0
set env=pphub
set /p main=输入命令选项:
if %main% EQU 1 goto install
if %main% EQU 2 goto server
goto M
:install
conda create -n %env% python=3.7 && conda activate %env% && pip install --upgrade paddlepaddle -i https://mirror.baidu.com/pypi/simple && pip install --upgrade paddlehub -i https://mirror.baidu.com/pypi/simple
goto M
:server
conda activate %env% && hub serving start -m chinese_ocr_db_crnn_mobile
goto M
python测试图片ocr识别
import requests
import json
import base64
file_path = r"C:\Users\Administrator\Desktop\微信截图_20220209192322.png"
with open(file_path,"rb") as f:
data = f.read()
data = base64.b64encode(data).decode('utf8')
data = {'images':[data]}
headers = {"Content-type": "application/json"}
url = "http://127.0.0.1:8866/predict/chinese_ocr_db_crnn_mobile"
r = requests.post(url=url, headers=headers, data=json.dumps(data))
# 打印预测结果
print(r.json())
附:
paddleHub 模型库:https://www.paddlepaddle.org.cn/hubsearch?filter=en_category