文章首发及后续更新:https://mwhls.top/4083.html,无图/无目录/格式错误/更多相关请至首发页查看。
新的更新内容请到mwhls.top查看。
欢迎提出任何疑问及批评,非常感谢!
安装 numpy:pip install numpy
安装 PDRS (PaddleRS):
pip install -r requirements.txt
apt-get updateapt-get install -y gccpip install -r requirements.txt
apt-get install -y g++pip install -r requirements.txtpython -m pip install paddlepaddle-gpu==2.3.0 -i https://mirror.baidu.com/pypi/simplepython -m pip install paddlepaddle==2.2.2 -i https://mirror.baidu.com/pypi/simplepython setup.py install
Downgrade the protobuf package to 3.20.x or lower.python setup.py install
ImportError: libGL.so.1: cannot open shared object file: No such file or directoryapt install libgl1-mesa-glxpython setup.py install
ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directoryapt-get install libglib2.0-0python setup.py installroot
└─ code
├─ datasets
│ └─ infer
│ ├─ before.png
│ ├─ label_no_use.png
│ └─ later.png
├─ inference_model
│ ├─ .success
│ ├─ model.pdiparams
│ ├─ model.pdiparams.info
│ ├─ model.pdmodel
│ ├─ model.yml
│ └─ pipeline.yml
├─ main.py
├─ predict.py
└─ startup.py# modified from: https://aistudio.baidu.com/aistudio/projectdetail/4184759
from paddlers.deploy import Predictor
import numpy as np
from PIL import Image
from matplotlib import pyplot as plt
predictor = Predictor(“./code/inference_model”, use_gpu=False)
res = predictor.predict((“./code/datasets/infer/before.png”, “./code/datasets/infer/later.png”))
cm_1024x1024 = res[0][‘label_map’]
plt.imshow((cm_1024x1024*255).astype(‘uint8’)); plt.gca().set_axis_off(); plt.title(“Pred”)
plt.show()
plt.savefig(‘./code/datasets/infer/pred.png’)
print(“done”)
执行推理代码:成功执行,但出现很多警告,且预测图像无结果。
TypeError: __init__() got an unexpected keyword argument 'is_scale'
is_scale 的那行,这个在 aistudio 上不会出报错,但注释该行也不会影响正确结果,应该又是哪个版本不同引起的。检查报错并解决:
DeprecationWarning: Please use spmatrix from the scipy.sparse namespace, the scipy.sparse.base namespace is deprecated.
pip install scipy~=1.6.3 DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
检查发现, aistudio 上的 Pillow 版本为 7.1.2,而 docker 中为 9.1.1 ,尝试降级。
降级 Pillow:`pip install scipy~=7.1.2
WARNING: type object 'QuantizationTransformPass' has no attribute '_supported_quantizable_op_type'WARNING: If you want to use training-aware and post-training quantization, please use Paddle >= 1.8.4 or develop version
DeprecationWarning: np.object is a deprecated alias for the builtin object. To silence this warning, use object by itself. Doing this will not modify any behavior and is safe.
[WARNING] Cannot find raw_params. Default arguments will be used to construct the model.
清空 pip 缓存:rm -r ~/.cache/pip,容器大小从 3.83G 变为 2.49G。
推理模型基本完成,接下来修改为适用于 API 的推理方式。