环境准备
python 版本需要是 3.6 至 3.10。pip 版本需要是 20.2.2 或更高。本地安装的是 python 3.6,pip 版本升级到了 21.3.1。
python --version >>Python 3.6.4 pip3 --version >>pip 20.1 from d:\program files\python36\lib\site-packages\pip (python 3.6) pip install -U pip >>Successfully installed pip-21.3.1
安装PaddlePaddle
python -m pip install paddlepaddle==2.4.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
安装 PaddleHub
pip install --upgrade paddlehub -i https://pypi.tuna.tsinghua.edu.cn/simple
验证
python >>> import paddle >>> paddle.utils.run_check() Running verify PaddlePaddle program ... PaddlePaddle works well on 2 CPUs. PaddlePaddle is installed successfully! Let's start deep learning with PaddlePaddle now. >>> exit()
示例代码
import os import paddlehub as hub humanseg = hub.Module(name='deeplabv3p_xception65_humanseg') path = 'G:/Library/Desktop/images/' files = os.listdir(path) print(files) imgs = [] for img in files: imgs.append(path + img) results = humanseg.segmentation(data={'image':imgs},visualization=True,output_dir=path+'result')
执行脚本,结果报错:ModuleNotFoundError: No module named 'scipy'。安装 scipy 之后再次执行,报出错误:SyntaxError: future feature annotations is not defined。本地的 python 环境保持了好几年了,看来飞桨官网说的也过时了啊,升级到 python 3.10,需要重新安装 PaddleHub 和 PaddlePaddle。然后再次执行脚本。
原图:163KB
处理后:1.76MB
标签:files,python,PaddlePaddle,3.6,pip,path,百度 From: https://www.cnblogs.com/fallTakeMan/p/16993383.html