基于树莓派4B与Paddle-Lite实现的智能垃圾桶项目
采用最新的图片分类模型PPLCNet,并在树莓派32位原生系统上,使用了最新的Paddle-Lite-v2.11进行本地编译,最终在Paddle-Lite-Demo-develop上部署成功
基于树莓派4B与Paddle-Lite实现的智能垃圾桶项目
项目背景
城市垃圾分类最早始于 1995 年上海市,2000 年,建设部在北京、南京、杭州、厦门等城市进行垃圾分类试点,将垃圾分类收集分为废纸、塑料、金属以及有毒有害废电池等。经过 20 多年来的发展,垃圾分类模式已经作了数次调整,把垃圾分为:有机垃圾、无机垃圾、有毒有害垃圾;干垃圾、湿垃圾、有害垃圾;废玻璃、可燃垃圾以及有害垃圾;可堆肥垃圾、有害垃圾、其他垃圾等等。
近年来,各地虽然在城市垃圾分类领域探索出了诸多的宝贵经验,但作为一项系统性工程,应从收集、运输到后期进行全过程垃圾分类处理才是严格意义上的垃圾分类。
从目前的城市垃圾分类现状来看,普遍存在重视垃圾分类,但在运输环节考虑成本等因素,又将分类收集起来的垃圾集中混合运输,导致许多可回收应用的垃圾未得到充分利用而导致巨大资源浪费。
根据测算数据,2011-2020年我国生活垃圾处理行业市场规模呈现波动上升趋势,2020年我国生活垃圾处理行业市场规模为582.78亿元,同比增长2.49%。
解决方向
本项目主要是从垃圾产生的源头来进行分类处理,也就是对生活中随处可见的普通垃圾桶进行改造升级,实现垃圾分类无人化,智能化,规模化。
核心技术
- 垃圾分类功能:基于PaddleClas中的PPLCNet模型开发
- 硬件部署:基于树莓派4B/4G,32位原生操作系统,Paddle-Lite开发
一、PaddleClas环境准备
PaddleClas是面向工业界和学术界的图像分类和图像识别工具集,可帮助用户训练更好的计算机视觉模型并将其应用于实际场景。
1.1 安装paddleclas
- 单卡,gpu环境进行模型训练
- python3.7,PaddlePaddle-2.3.0,paddleclas-2.4.2
- paddleclas环境配置有这两种方法:手动环境配置和docker容器化环境配置
下面我以手动环境配置为例,进行讲解
# 安装gpu版本的paddlepaddle
!python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
Looking in indexes: https://mirror.baidu.com/pypi/simple
Requirement already satisfied: paddlepaddle-gpu in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (2.3.0.post101)
Requirement already satisfied: numpy>=1.13 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (1.19.5)
Requirement already satisfied: requests>=2.20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (2.24.0)
Requirement already satisfied: six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (1.16.0)
Requirement already satisfied: protobuf>=3.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (3.14.0)
Requirement already satisfied: opt-einsum==3.3.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (3.3.0)
Requirement already satisfied: decorator in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (4.4.2)
Requirement already satisfied: paddle-bfloat==0.1.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (0.1.2)
Requirement already satisfied: Pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (8.2.0)
Requirement already satisfied: astor in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (0.8.1)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu) (1.25.6)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu) (2019.9.11)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu) (2.8)
Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu) (3.0.4)
# 安装paddleclas-2.4.2成功后,重启一下内核
!pip install paddleclas
# 运行结果
# Successfully installed faiss-cpu-1.7.1.post2 opencv-python-4.4.0.46 paddleclas-2.4.2
# Note: you may need to restart the kernel to use updated packages.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting paddleclas
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8a/eb/8e39b624b68fedce86b3f6f41d0c686d4ce44c91f9d19b71caefc5daafff/paddleclas-2.4.2-py3-none-any.whl (451 kB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m451.5/451.5 kB[0m [31m5.3 MB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hRequirement already satisfied: prettytable in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (3.3.0)
Requirement already satisfied: opencv-python==4.4.0.46 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (4.4.0.46)
Requirement already satisfied: pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (9.2.0)
Requirement already satisfied: easydict in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (1.9)
Requirement already satisfied: faiss-cpu==1.7.1.post2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (1.7.1.post2)
Requirement already satisfied: gast==0.3.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (0.3.3)
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (4.64.0)
Requirement already satisfied: scikit-learn>=0.21.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (1.0.2)
Requirement already satisfied: visualdl>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (2.3.0)
Requirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (1.7.3)
Requirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (6.0)
Requirement already satisfied: ujson in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (5.4.0)
Requirement already satisfied: numpy>=1.14.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from opencv-python==4.4.0.46->paddleclas) (1.19.5)
Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.0->paddleclas) (2.1.0)
Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.0->paddleclas) (0.14.1)
Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (1.1.1)
Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (1.16.0)
Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (2.24.0)
Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (2.2.3)
Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (1.0.0)
Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (3.14.0)
Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (1.1.5)
Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (0.8.53)
Requirement already satisfied: importlib-metadata in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from prettytable->paddleclas) (4.2.0)
Requirement already satisfied: wcwidth in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from prettytable->paddleclas) (0.1.7)
Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->paddleclas) (0.16.0)
Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->paddleclas) (7.0)
Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->paddleclas) (3.0.0)
Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->paddleclas) (1.1.0)
Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->paddleclas) (2.8.0)
Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->paddleclas) (2019.3)
Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->paddleclas) (0.18.0)
Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->paddleclas) (3.9.9)
Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->prettytable->paddleclas) (3.8.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->prettytable->paddleclas) (4.2.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->paddleclas) (1.1.0)
Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->paddleclas) (2.8.2)
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->paddleclas) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->paddleclas) (3.0.9)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->paddleclas) (1.25.6)
Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->paddleclas) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->paddleclas) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->paddleclas) (2019.9.11)
Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.2.0->paddleclas) (2.0.1)
Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->visualdl>=2.2.0->paddleclas) (56.2.0)
Installing collected packages: paddleclas
Successfully installed paddleclas-2.4.2
1.2 克隆 PaddleClas库
由于访问 GitHub 网速较慢,可以从 Gitee 下载,命令如下:
!git clone https://gitee.com/paddlepaddle/PaddleClas.git -b release/2.4
fatal: 目标路径 'PaddleClas' 已经存在,并且不是一个空目录。
1.3 安装 Python 依赖库
PaddleClas 的 Python 依赖库在 requirements.txt 中给出,可通过如下命令安装:
%cd PaddleClas
%pip install --upgrade -r requirements.txt -i https://mirror.baidu.com/pypi/simple
/home/aistudio/PaddleClas
Looking in indexes: https://mirror.baidu.com/pypi/simple
Requirement already satisfied: prettytable in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (0.7.2)
Collecting prettytable
Downloading https://mirror.baidu.com/pypi/packages/5f/ab/64371af206988d7b15c8112c9c277b8eb4618397c01471e52b902a17f59c/prettytable-3.3.0-py3-none-any.whl (26 kB)
Requirement already satisfied: ujson in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (5.3.0)
Collecting ujson
Downloading https://mirror.baidu.com/pypi/packages/e2/0c/e2716a22c525866c2766bfe7677b24402d2f0cdea66e2c1a3b63714ea560/ujson-5.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45 kB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m45.3/45.3 kB[0m [31m9.3 MB/s[0m eta [36m0:00:00[0m
[?25hCollecting opencv-python==4.4.0.46
Downloading https://mirror.baidu.com/pypi/packages/1b/2d/62eba161d3d713e1720504de1c25d439b02c85159804d9ecead10be5d87e/opencv_python-4.4.0.46-cp37-cp37m-manylinux2014_x86_64.whl (49.5 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m49.5/49.5 MB[0m [31m6.5 MB/s[0m eta [36m0:00:00[0m:00:01[0m00:01[0m
[?25hRequirement already satisfied: pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (8.2.0)
Collecting pillow
Downloading https://mirror.baidu.com/pypi/packages/86/d2/ca178ad71dcd1dcddbe2a3f7983639d2f8a20e723d9a978ab978ed08c874/Pillow-9.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m3.1/3.1 MB[0m [31m9.9 MB/s[0m eta [36m0:00:00[0m:00:01[0m00:01[0m
[?25hRequirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (4.27.0)
Collecting tqdm
Downloading https://mirror.baidu.com/pypi/packages/8a/c4/d15f1e627fff25443ded77ea70a7b5532d6371498f9285d44d62587e209c/tqdm-4.64.0-py2.py3-none-any.whl (78 kB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m78.4/78.4 kB[0m [31m15.2 MB/s[0m eta [36m0:00:00[0m
[?25hRequirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (5.1.2)
Collecting PyYAML
Downloading https://mirror.baidu.com/pypi/packages/eb/5f/6e6fe6904e1a9c67bc2ca5629a69e7a5a0b17f079da838bab98a1e548b25/PyYAML-6.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (596 kB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m596.3/596.3 kB[0m [31m13.9 MB/s[0m eta [36m0:00:00[0m00:01[0m
[?25hRequirement already satisfied: visualdl>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (2.2.3)
Collecting visualdl>=2.2.0
Downloading https://mirror.baidu.com/pypi/packages/b4/cd/afbc6dd8e17d538972b817b397882cbc6d818559040e939b80b74b451bf1/visualdl-2.3.0-py3-none-any.whl (2.8 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m2.8/2.8 MB[0m [31m10.7 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hRequirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (1.6.3)
Collecting scipy
Downloading https://mirror.baidu.com/pypi/packages/58/4f/11f34cfc57ead25752a7992b069c36f5d18421958ebd6466ecd849aeaf86/scipy-1.7.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (38.1 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m38.1/38.1 MB[0m [31m7.6 MB/s[0m eta [36m0:00:00[0m:00:01[0m00:01[0m
[?25hRequirement already satisfied: scikit-learn>=0.21.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (0.24.2)
Collecting scikit-learn>=0.21.0
Downloading https://mirror.baidu.com/pypi/packages/bd/05/e561bc99a615b5c099c7a9355409e5e57c525a108f1c2e156abb005b90a6/scikit_learn-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (24.8 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m24.8/24.8 MB[0m [31m8.1 MB/s[0m eta [36m0:00:00[0m:00:01[0m00:01[0m
[?25hRequirement already satisfied: gast==0.3.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 10)) (0.3.3)
Collecting faiss-cpu==1.7.1.post2
Downloading https://mirror.baidu.com/pypi/packages/4c/d6/072a9d18430b8c68c99ffb49fe14fbf89c62f71dcd4f5f692c7691447a14/faiss_cpu-1.7.1.post2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.4 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m8.4/8.4 MB[0m [31m9.6 MB/s[0m eta [36m0:00:00[0m:00:01[0m00:01[0m
[?25hRequirement already satisfied: easydict in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 12)) (1.9)
Requirement already satisfied: numpy>=1.14.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from opencv-python==4.4.0.46->-r requirements.txt (line 3)) (1.19.5)
Requirement already satisfied: wcwidth in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from prettytable->-r requirements.txt (line 1)) (0.1.7)
Requirement already satisfied: importlib-metadata in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from prettytable->-r requirements.txt (line 1)) (4.2.0)
Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (2.2.3)
Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.0.0)
Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (2.24.0)
Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.16.0)
Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (0.8.53)
Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.1)
Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.5)
Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (3.14.0)
Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.0->-r requirements.txt (line 9)) (0.14.1)
Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.0->-r requirements.txt (line 9)) (2.1.0)
Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.0.0)
Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.16.0)
Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.0)
Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (7.0)
Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.8.0)
Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->-r requirements.txt (line 7)) (2019.3)
Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.18.0)
Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.9.9)
Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->prettytable->-r requirements.txt (line 1)) (4.2.0)
Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->prettytable->-r requirements.txt (line 1)) (3.8.0)
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.1.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.0.9)
Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.8.2)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (2019.9.11)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.8)
Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 7)) (1.25.6)
Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 7)) (2.0.1)
Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->visualdl>=2.2.0->-r requirements.txt (line 7)) (56.2.0)
Installing collected packages: faiss-cpu, ujson, tqdm, scipy, PyYAML, pillow, opencv-python, scikit-learn, prettytable, visualdl
Attempting uninstall: ujson
Found existing installation: ujson 5.3.0
Uninstalling ujson-5.3.0:
Successfully uninstalled ujson-5.3.0
Attempting uninstall: tqdm
Found existing installation: tqdm 4.27.0
Uninstalling tqdm-4.27.0:
Successfully uninstalled tqdm-4.27.0
Attempting uninstall: scipy
Found existing installation: scipy 1.6.3
Uninstalling scipy-1.6.3:
Successfully uninstalled scipy-1.6.3
Attempting uninstall: PyYAML
Found existing installation: PyYAML 5.1.2
Uninstalling PyYAML-5.1.2:
Successfully uninstalled PyYAML-5.1.2
Attempting uninstall: pillow
Found existing installation: Pillow 8.2.0
Uninstalling Pillow-8.2.0:
Successfully uninstalled Pillow-8.2.0
Attempting uninstall: opencv-python
Found existing installation: opencv-python 4.1.1.26
Uninstalling opencv-python-4.1.1.26:
Successfully uninstalled opencv-python-4.1.1.26
Attempting uninstall: scikit-learn
Found existing installation: scikit-learn 0.24.2
Uninstalling scikit-learn-0.24.2:
Successfully uninstalled scikit-learn-0.24.2
Attempting uninstall: prettytable
Found existing installation: prettytable 0.7.2
Uninstalling prettytable-0.7.2:
Successfully uninstalled prettytable-0.7.2
Attempting uninstall: visualdl
Found existing installation: visualdl 2.2.3
Uninstalling visualdl-2.2.3:
Successfully uninstalled visualdl-2.2.3
[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
parl 1.4.1 requires pyzmq==18.1.1, but you have pyzmq 23.1.0 which is incompatible.
paddlefsl 1.0.0 requires pillow==8.2.0, but you have pillow 9.2.0 which is incompatible.
paddlefsl 1.0.0 requires tqdm~=4.27.0, but you have tqdm 4.64.0 which is incompatible.[0m[31m
[0mSuccessfully installed PyYAML-6.0 faiss-cpu-1.7.1.post2 opencv-python-4.4.0.46 pillow-9.2.0 prettytable-3.3.0 scikit-learn-1.0.2 scipy-1.7.3 tqdm-4.64.0 ujson-5.4.0 visualdl-2.3.0
Note: you may need to restart the kernel to use updated packages.
1.4 预测
模型预测有两种方式:命令行方式与python代码模式
1.4.1在命令行中使用 PPLCNet_x1_0 的权重快速预测
!paddleclas --model_name=PPLCNet_x1_0 --infer_imgs="docs/images/inference_deployment/whl_demo.jpg"
# 预测结果如下
# class_ids: [8, 7, 86, 81, 85],
# scores: [0.91347, 0.03779, 0.0036, 0.00117, 0.00112],
# label_names: ['hen', 'cock', 'partridge', 'ptarmigan', 'quail'],
# filename: docs/images/inference_deployment/whl_demo.jpg
# Predict complete!
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
--------------------------------------------------------------------------
Models supported by PaddleClas
+-------------------+----------------------------------------------------+
| IMN Model Series | Model Name |
+-------------------+----------------------------------------------------+
| AlexNet | AlexNet |
| DarkNet | DarkNet53 |
| DeiT | DeiT_base_distilled_patch16_224 |
| | DeiT_base_distilled_patch16_384 |
| | DeiT_base_patch16_224 DeiT_base_patch16_384 |
| | DeiT_small_distilled_patch16_224 |
| | DeiT_small_patch16_224 |
| | DeiT_tiny_distilled_patch16_224 |
| | DeiT_tiny_patch16_224 |
| DenseNet | DenseNet121 DenseNet161 DenseNet169 DenseNet201 |
| | DenseNet264 |
| DLA | DLA46_c DLA60x_c DLA34 DLA60 DLA60x DLA102 |
| | DLA102x DLA102x2 DLA169 |
| DPN | DPN68 DPN92 DPN98 DPN107 DPN131 |
| EfficientNet | EfficientNetB0 EfficientNetB0_small |
| | EfficientNetB1 EfficientNetB2 EfficientNetB3 |
| | EfficientNetB4 EfficientNetB5 EfficientNetB6 |
| | EfficientNetB7 |
| ESNet | ESNet_x0_25 ESNet_x0_5 ESNet_x0_75 ESNet_x1_0 |
| GhostNet | GhostNet_x0_5 GhostNet_x1_0 GhostNet_x1_3 |
| | GhostNet_x1_3_ssld |
| HarDNet | HarDNet39_ds HarDNet68_ds HarDNet68 HarDNet85 |
| HRNet | HRNet_W18_C HRNet_W30_C HRNet_W32_C HRNet_W40_C |
| | HRNet_W44_C HRNet_W48_C HRNet_W64_C |
| | HRNet_W18_C_ssld HRNet_W48_C_ssld |
| Inception | GoogLeNet InceptionV3 InceptionV4 |
| MixNet | MixNet_S MixNet_M MixNet_L |
| MobileNetV1 | MobileNetV1_x0_25 MobileNetV1_x0_5 |
| | MobileNetV1_x0_75 MobileNetV1 MobileNetV1_ssld |
| MobileNetV2 | MobileNetV2_x0_25 MobileNetV2_x0_5 |
| | MobileNetV2_x0_75 MobileNetV2 MobileNetV2_x1_5 |
| | MobileNetV2_x2_0 MobileNetV2_ssld |
| MobileNetV3 | MobileNetV3_small_x0_35 MobileNetV3_small_x0_5 |
| | MobileNetV3_small_x0_75 MobileNetV3_small_x1_0 |
| | MobileNetV3_small_x1_25 MobileNetV3_large_x0_35 |
| | MobileNetV3_large_x0_5 MobileNetV3_large_x0_75 |
| | MobileNetV3_large_x1_0 MobileNetV3_large_x1_25 |
| | MobileNetV3_small_x1_0_ssld |
| | MobileNetV3_large_x1_0_ssld |
| PPHGNet | PPHGNet_tiny PPHGNet_small PPHGNet_tiny_ssld |
| | PPHGNet_small_ssld |
| PPLCNet | PPLCNet_x0_25 PPLCNet_x0_35 PPLCNet_x0_5 |
| | PPLCNet_x0_75 PPLCNet_x1_0 PPLCNet_x1_5 |
| | PPLCNet_x2_0 PPLCNet_x2_5 |
| PPLCNetV2 | PPLCNetV2_base |
| RedNet | RedNet26 RedNet38 RedNet50 RedNet101 RedNet152 |
| RegNet | RegNetX_4GF |
| Res2Net | Res2Net50_14w_8s Res2Net50_26w_4s |
| | Res2Net50_vd_26w_4s Res2Net200_vd_26w_4s |
| | Res2Net101_vd_26w_4s Res2Net50_vd_26w_4s_ssld |
| | Res2Net101_vd_26w_4s_ssld |
| | Res2Net200_vd_26w_4s_ssld |
| ResNeSt | ResNeSt50 ResNeSt50_fast_1s1x64d |
| ResNet | ResNet18 ResNet18_vd ResNet34 ResNet34_vd |
| | ResNet50 ResNet50_vc ResNet50_vd ResNet50_vd_v2 |
| | ResNet101 ResNet101_vd ResNet152 ResNet152_vd |
| | ResNet200_vd ResNet34_vd_ssld ResNet50_vd_ssld |
| | ResNet50_vd_ssld_v2 ResNet101_vd_ssld |
| | Fix_ResNet50_vd_ssld_v2 ResNet50_ACNet_deploy |
| ResNeXt | ResNeXt50_32x4d ResNeXt50_vd_32x4d |
| | ResNeXt50_64x4d ResNeXt50_vd_64x4d |
| | ResNeXt101_32x4d ResNeXt101_vd_32x4d |
| | ResNeXt101_32x8d_wsl ResNeXt101_32x16d_wsl |
| | ResNeXt101_32x32d_wsl ResNeXt101_32x48d_wsl |
| | Fix_ResNeXt101_32x48d_wsl ResNeXt101_64x4d |
| | ResNeXt101_vd_64x4d ResNeXt152_32x4d |
| | ResNeXt152_vd_32x4d ResNeXt152_64x4d |
| | ResNeXt152_vd_64x4d |
| ReXNet | ReXNet_1_0 ReXNet_1_3 ReXNet_1_5 ReXNet_2_0 |
| | ReXNet_3_0 |
| SENet | SENet154_vd SE_HRNet_W64_C_ssld SE_ResNet18_vd |
| | SE_ResNet34_vd SE_ResNet50_vd SE_ResNeXt50_32x4d |
| | SE_ResNeXt50_vd_32x4d SE_ResNeXt101_32x4d |
| ShuffleNetV2 | ShuffleNetV2_swish ShuffleNetV2_x0_25 |
| | ShuffleNetV2_x0_33 ShuffleNetV2_x0_5 |
| | ShuffleNetV2_x1_0 ShuffleNetV2_x1_5 |
| | ShuffleNetV2_x2_0 |
| SqueezeNet | SqueezeNet1_0 SqueezeNet1_1 |
| SwinTransformer | SwinTransformer_large_patch4_window7_224_22kto1k |
| | SwinTransformer_large_patch4_window12_384_22kto1k |
| | SwinTransformer_base_patch4_window7_224_22kto1k |
| | SwinTransformer_base_patch4_window12_384_22kto1k |
| | SwinTransformer_base_patch4_window12_384 |
| | SwinTransformer_base_patch4_window7_224 |
| | SwinTransformer_small_patch4_window7_224 |
| | SwinTransformer_tiny_patch4_window7_224 |
| Twins | pcpvt_small pcpvt_base pcpvt_large |
| | alt_gvt_small alt_gvt_base alt_gvt_large |
| VGG | VGG11 VGG13 VGG16 VGG19 |
| VisionTransformer | ViT_base_patch16_224 ViT_base_patch16_384 |
| | ViT_base_patch32_384 ViT_large_patch16_224 |
| | ViT_large_patch16_384 ViT_large_patch32_384 |
| | ViT_small_patch16_224 |
| Xception | Xception41 Xception41_deeplab Xception65 |
| | Xception65_deeplab Xception71 |
+-------------------+----------------------------------------------------+
+---------------------------------------------------------------------------+
| PULC Models |
+---------------------------------------------------------------------------+
| car_exists language_classification person_attribute person_exists |
| safety_helmet text_image_orientation textline_orientation traffic_sign |
| vehicle_attribute |
+---------------------------------------------------------------------------+
Powered by PaddlePaddle!
--------------------------------------------------------------------------
[2022/07/19 16:58:25] ppcls INFO: download https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_5_infer.tar to /home/aistudio/.paddleclas/inference_model/IMN/PPLCNet_x1_5/PPLCNet_x1_5_infer.tar
100%|█████████████████████████████████████| 18.6M/18.6M [00:00<00:00, 19.7MiB/s]
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:65: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead.
'nearest': Image.NEAREST,
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:66: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
'bilinear': Image.BILINEAR,
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:67: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
'bicubic': Image.BICUBIC,
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:68: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead.
'box': Image.BOX,
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:69: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
'lanczos': Image.LANCZOS,
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:70: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead.
'hamming': Image.HAMMING
[2022/07/19 16:58:31] ppcls INFO: class_ids: [8, 7, 86, 80, 21], scores: [0.88553, 0.0835, 0.00191, 0.0009, 0.00069], label_names: ['hen', 'cock', 'partridge', 'black grouse', 'kite'], filename: docs/images/inference_deployment/whl_demo.jpg
[2022/07/19 16:58:31] ppcls INFO: Predict complete!
1.4.2 在 Python 代码中预测(PPLCNet_x1_0)
from paddleclas import PaddleClas
# result为可迭代对象,因此需要使用 next() 函数或 for 循环对其迭代调用。
# 每次调用将以 batch_size 为单位进行一次预测,并返回预测结果。
clas = PaddleClas(model_name='PPLCNet_x1_0')
infer_imgs='docs/images/inference_deployment/whl_demo.jpg'
result=clas.predict(infer_imgs)
print(next(result))
# 预测结果如下
# [
# { 'class_ids': [8, 7, 86, 81, 85],
# 'scores': [0.91347, 0.03779, 0.0036, 0.00117, 0.00112],
# 'label_names': ['hen', 'cock', 'partridge', 'ptarmigan', 'quail'],
# 'filename': 'docs/images/inference_deployment/whl_demo.jpg'
# }
# ]
----------------------------------------------------------------------------------------------------------------------------
Models supported by PaddleClas
+-------------------+------------------------------------------------------------------------------------------------------+
| IMN Model Series | Model Name |
+-------------------+------------------------------------------------------------------------------------------------------+
| AlexNet | AlexNet |
| DarkNet | DarkNet53 |
| DeiT | DeiT_base_distilled_patch16_224 DeiT_base_distilled_patch16_384 DeiT_base_patch16_224 |
| | DeiT_base_patch16_384 DeiT_small_distilled_patch16_224 DeiT_small_patch16_224 |
| | DeiT_tiny_distilled_patch16_224 DeiT_tiny_patch16_224 |
| DenseNet | DenseNet121 DenseNet161 DenseNet169 DenseNet201 DenseNet264 |
| DLA | DLA46_c DLA60x_c DLA34 DLA60 DLA60x DLA102 DLA102x DLA102x2 DLA169 |
| DPN | DPN68 DPN92 DPN98 DPN107 DPN131 |
| EfficientNet | EfficientNetB0 EfficientNetB0_small EfficientNetB1 EfficientNetB2 EfficientNetB3 EfficientNetB4 |
| | EfficientNetB5 EfficientNetB6 EfficientNetB7 |
| ESNet | ESNet_x0_25 ESNet_x0_5 ESNet_x0_75 ESNet_x1_0 |
| GhostNet | GhostNet_x0_5 GhostNet_x1_0 GhostNet_x1_3 GhostNet_x1_3_ssld |
| HarDNet | HarDNet39_ds HarDNet68_ds HarDNet68 HarDNet85 |
| HRNet | HRNet_W18_C HRNet_W30_C HRNet_W32_C HRNet_W40_C HRNet_W44_C HRNet_W48_C HRNet_W64_C |
| | HRNet_W18_C_ssld HRNet_W48_C_ssld |
| Inception | GoogLeNet InceptionV3 InceptionV4 |
| MixNet | MixNet_S MixNet_M MixNet_L |
| MobileNetV1 | MobileNetV1_x0_25 MobileNetV1_x0_5 MobileNetV1_x0_75 MobileNetV1 MobileNetV1_ssld |
| MobileNetV2 | MobileNetV2_x0_25 MobileNetV2_x0_5 MobileNetV2_x0_75 MobileNetV2 MobileNetV2_x1_5 |
| | MobileNetV2_x2_0 MobileNetV2_ssld |
| MobileNetV3 | MobileNetV3_small_x0_35 MobileNetV3_small_x0_5 MobileNetV3_small_x0_75 MobileNetV3_small_x1_0 |
| | MobileNetV3_small_x1_25 MobileNetV3_large_x0_35 MobileNetV3_large_x0_5 MobileNetV3_large_x0_75 |
| | MobileNetV3_large_x1_0 MobileNetV3_large_x1_25 MobileNetV3_small_x1_0_ssld |
| | MobileNetV3_large_x1_0_ssld |
| PPHGNet | PPHGNet_tiny PPHGNet_small PPHGNet_tiny_ssld PPHGNet_small_ssld |
| PPLCNet | PPLCNet_x0_25 PPLCNet_x0_35 PPLCNet_x0_5 PPLCNet_x0_75 PPLCNet_x1_0 PPLCNet_x1_5 PPLCNet_x2_0 |
| | PPLCNet_x2_5 |
| PPLCNetV2 | PPLCNetV2_base |
| RedNet | RedNet26 RedNet38 RedNet50 RedNet101 RedNet152 |
| RegNet | RegNetX_4GF |
| Res2Net | Res2Net50_14w_8s Res2Net50_26w_4s Res2Net50_vd_26w_4s Res2Net200_vd_26w_4s Res2Net101_vd_26w_4s |
| | Res2Net50_vd_26w_4s_ssld Res2Net101_vd_26w_4s_ssld Res2Net200_vd_26w_4s_ssld |
| ResNeSt | ResNeSt50 ResNeSt50_fast_1s1x64d |
| ResNet | ResNet18 ResNet18_vd ResNet34 ResNet34_vd ResNet50 ResNet50_vc ResNet50_vd ResNet50_vd_v2 |
| | ResNet101 ResNet101_vd ResNet152 ResNet152_vd ResNet200_vd ResNet34_vd_ssld ResNet50_vd_ssld |
| | ResNet50_vd_ssld_v2 ResNet101_vd_ssld Fix_ResNet50_vd_ssld_v2 ResNet50_ACNet_deploy |
| ResNeXt | ResNeXt50_32x4d ResNeXt50_vd_32x4d ResNeXt50_64x4d ResNeXt50_vd_64x4d ResNeXt101_32x4d |
| | ResNeXt101_vd_32x4d ResNeXt101_32x8d_wsl ResNeXt101_32x16d_wsl ResNeXt101_32x32d_wsl |
| | ResNeXt101_32x48d_wsl Fix_ResNeXt101_32x48d_wsl ResNeXt101_64x4d ResNeXt101_vd_64x4d |
| | ResNeXt152_32x4d ResNeXt152_vd_32x4d ResNeXt152_64x4d ResNeXt152_vd_64x4d |
| ReXNet | ReXNet_1_0 ReXNet_1_3 ReXNet_1_5 ReXNet_2_0 ReXNet_3_0 |
| SENet | SENet154_vd SE_HRNet_W64_C_ssld SE_ResNet18_vd SE_ResNet34_vd SE_ResNet50_vd SE_ResNeXt50_32x4d |
| | SE_ResNeXt50_vd_32x4d SE_ResNeXt101_32x4d |
| ShuffleNetV2 | ShuffleNetV2_swish ShuffleNetV2_x0_25 ShuffleNetV2_x0_33 ShuffleNetV2_x0_5 ShuffleNetV2_x1_0 |
| | ShuffleNetV2_x1_5 ShuffleNetV2_x2_0 |
| SqueezeNet | SqueezeNet1_0 SqueezeNet1_1 |
| SwinTransformer | SwinTransformer_large_patch4_window7_224_22kto1k SwinTransformer_large_patch4_window12_384_22kto1k |
| | SwinTransformer_base_patch4_window7_224_22kto1k SwinTransformer_base_patch4_window12_384_22kto1k |
| | SwinTransformer_base_patch4_window12_384 SwinTransformer_base_patch4_window7_224 |
| | SwinTransformer_small_patch4_window7_224 SwinTransformer_tiny_patch4_window7_224 |
| Twins | pcpvt_small pcpvt_base pcpvt_large alt_gvt_small alt_gvt_base alt_gvt_large |
| VGG | VGG11 VGG13 VGG16 VGG19 |
| VisionTransformer | ViT_base_patch16_224 ViT_base_patch16_384 ViT_base_patch32_384 ViT_large_patch16_224 |
| | ViT_large_patch16_384 ViT_large_patch32_384 ViT_small_patch16_224 |
| Xception | Xception41 Xception41_deeplab Xception65 Xception65_deeplab Xception71 |
+-------------------+------------------------------------------------------------------------------------------------------+
+-------------------------------------------------------------------------------------+
| PULC Models |
+-------------------------------------------------------------------------------------+
| car_exists language_classification person_attribute person_exists safety_helmet |
| text_image_orientation textline_orientation traffic_sign vehicle_attribute |
+-------------------------------------------------------------------------------------+
Powered by PaddlePaddle!
----------------------------------------------------------------------------------------------------------------------------
[2022/07/19 13:40:47] ppcls WARNING: The current running environment does not support the use of GPU. CPU has been used instead.
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
[37m--- fused 0 elementwise_add with relu activation[0m
[37m--- fused 0 elementwise_add with tanh activation[0m
[37m--- fused 0 elementwise_add with leaky_relu activation[0m
[37m--- fused 0 elementwise_add with swish activation[0m
[37m--- fused 0 elementwise_add with hardswish activation[0m
[37m--- fused 0 elementwise_add with sqrt activation[0m
[37m--- fused 0 elementwise_add with abs activation[0m
[37m--- fused 0 elementwise_add with clip activation[0m
[37m--- fused 0 elementwise_add with gelu activation[0m
[37m--- fused 0 elementwise_add with relu6 activation[0m
[37m--- fused 0 elementwise_add with sigmoid activation[0m
[37m--- fused 0 elementwise_sub with relu activation[0m
[37m--- fused 0 elementwise_sub with tanh activation[0m
[37m--- fused 0 elementwise_sub with leaky_relu activation[0m
[37m--- fused 0 elementwise_sub with swish activation[0m
[37m--- fused 0 elementwise_sub with hardswish activation[0m
[37m--- fused 0 elementwise_sub with sqrt activation[0m
[37m--- fused 0 elementwise_sub with abs activation[0m
[37m--- fused 0 elementwise_sub with clip activation[0m
[37m--- fused 0 elementwise_sub with gelu activation[0m
[37m--- fused 0 elementwise_sub with relu6 activation[0m
[37m--- fused 0 elementwise_sub with sigmoid activation[0m
[37m--- fused 0 elementwise_mul with relu activation[0m
[37m--- fused 0 elementwise_mul with tanh activation[0m
[37m--- fused 0 elementwise_mul with leaky_relu activation[0m
[37m--- fused 0 elementwise_mul with swish activation[0m
[37m--- fused 0 elementwise_mul with hardswish activation[0m
[37m--- fused 0 elementwise_mul with sqrt activation[0m
[37m--- fused 0 elementwise_mul with abs activation[0m
[37m--- fused 0 elementwise_mul with clip activation[0m
[37m--- fused 0 elementwise_mul with gelu activation[0m
[37m--- fused 0 elementwise_mul with relu6 activation[0m
[37m--- fused 0 elementwise_mul with sigmoid activation[0m
/home/aistudio/PaddleClas/deploy/python/preprocess.py:65: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead.
'nearest': Image.NEAREST,
/home/aistudio/PaddleClas/deploy/python/preprocess.py:66: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
'bilinear': Image.BILINEAR,
/home/aistudio/PaddleClas/deploy/python/preprocess.py:67: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
'bicubic': Image.BICUBIC,
/home/aistudio/PaddleClas/deploy/python/preprocess.py:68: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead.
'box': Image.BOX,
/home/aistudio/PaddleClas/deploy/python/preprocess.py:69: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
'lanczos': Image.LANCZOS,
/home/aistudio/PaddleClas/deploy/python/preprocess.py:70: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead.
'hamming': Image.HAMMING
[{'class_ids': [8, 7, 86, 81, 85], 'scores': [0.91347, 0.03779, 0.0036, 0.00117, 0.00112], 'label_names': ['hen', 'cock', 'partridge', 'ptarmigan', 'quail'], 'filename': 'docs/images/inference_deployment/whl_demo.jpg'}]
二、模型训练、评估和预测
2.1 数据准备
PaddleClas 使用 txt 格式文件指定训练集和测试集,train_list.txt 和 val_list.txt 分别为训练集和验证集的标签文件,其格式说明可以参考PaddleClas分类数据集格式说明
其中 train_list.txt 和 val_list.txt 的格式形如:
# 每一行采用"空格"分隔图像路径与标注
# 下面是 train_list.txt 中的格式样例:
taoci/IMG_8886.JPG 4
tudou/IMG_8936.JPG 5
yinliaoping/IMG_9065.JPG 9
yilaguan/IMG_7987.JPG 8
pingguo/IMG_8726.JPG 2
# 下面是 val_list.txt 中的格式样例:
pingguo/IMG_8754.JPG 2
pingguo/IMG_8795.JPG 2
tudou/IMG_8377.JPG 5
xiangjiao/IMG_8998.JPG 6
pingguo/IMG_7814.JPG 2
# 将数据集解压至PaddleClas/dataset/目录下
!unzip ../data/data155466/垃圾检测.zip -d dataset/
Archive: data/data155466/垃圾检测.zip
replace PaddleClas/dataset/dianchi/IMG_8384.JPG? [y]es, [n]o, [A]ll, [N]one, [r]ename: ^C
2.2 模型训练
在 ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml 中提供了 PPLCNet_x1_0 训练配置,可以通过如下脚本启动训练。
但在启动训练之前需要对PPLCNet_x1_0.yaml的参数进行修改
Global:
pretrained_model: https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_pretrained.pdparams
save_interval: 1 # 模型保存间隔
eval_during_train: True # 启动验证集
eval_interval: 1 # 每训练完一轮就进行验证
epochs: 10 # 总训练轮数
print_batch_step: 10 # 每迭代10个iters打印一次训练信息
class_num: 10 # 类别数
learning_rate: 0.00625000 # 学习率
batch_size: 16 # 训练批次
Train:
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/train_list.txt
Eval:
dataset:
name: ImageNetDataset
image_root: ./dataset/
cls_label_path: ./dataset/val_list.txt
Infer:
infer_imgs: ./dataset/taoci/IMG_7923.JPG
...
PostProcess:
class_id_map_file: ./dataset/labels.txt
# 将CUDA设置为单卡
!export CUDA_VISIBLE_DEVICES=0
!python3 -m paddle.distributed.launch \
--gpus="0" \
tools/train.py \
-c ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml
# 训练结果非常nice,在epoch=2时,验证集上的top1和top5的准确率就已经达到了1
# [2022/07/19 18:57:40] [Eval][Epoch 2][Iter: 0/13] CELoss: 0.09414, loss: 0.09414, top1: 1.00000, top5: 1.00000, batch_cost: 9.11237s, reader_cost: 9.08816, ips: 1.75586 images/sec
# [2022/07/19 18:57:56] [Eval][Epoch 2][Iter: 10/13]CELoss: 0.06553, loss: 0.06553, top1: 1.00000, top5: 1.00000, batch_cost: 1.35222s, reader_cost: 1.31854, ips: 11.83241 images/sec
# [2022/07/19 18:57:58] [Eval][Epoch 2] [Avg]CELoss: 0.05911, loss: 0.05911, top1: 1.00000, top5: 1.00000
LAUNCH INFO 2022-07-19 18:54:26,890 ----------- Configuration ----------------------
LAUNCH INFO 2022-07-19 18:54:26,890 devices: None
LAUNCH INFO 2022-07-19 18:54:26,890 elastic_level: -1
LAUNCH INFO 2022-07-19 18:54:26,890 elastic_timeout: 30
LAUNCH INFO 2022-07-19 18:54:26,890 gloo_port: 6767
LAUNCH INFO 2022-07-19 18:54:26,890 host: None
LAUNCH INFO 2022-07-19 18:54:26,890 job_id: default
LAUNCH INFO 2022-07-19 18:54:26,890 legacy: False
LAUNCH INFO 2022-07-19 18:54:26,890 log_dir: log
LAUNCH INFO 2022-07-19 18:54:26,890 log_level: INFO
LAUNCH INFO 2022-07-19 18:54:26,890 master: None
LAUNCH INFO 2022-07-19 18:54:26,890 max_restart: 3
LAUNCH INFO 2022-07-19 18:54:26,890 nnodes: 1
LAUNCH INFO 2022-07-19 18:54:26,890 nproc_per_node: None
LAUNCH INFO 2022-07-19 18:54:26,890 rank: -1
LAUNCH INFO 2022-07-19 18:54:26,890 run_mode: collective
LAUNCH INFO 2022-07-19 18:54:26,890 server_num: None
LAUNCH INFO 2022-07-19 18:54:26,890 servers:
LAUNCH INFO 2022-07-19 18:54:26,890 trainer_num: None
LAUNCH INFO 2022-07-19 18:54:26,890 trainers:
LAUNCH INFO 2022-07-19 18:54:26,890 training_script: tools/train.py
LAUNCH INFO 2022-07-19 18:54:26,890 training_script_args: ['-c', 'ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml']
LAUNCH INFO 2022-07-19 18:54:26,890 with_gloo: 0
LAUNCH INFO 2022-07-19 18:54:26,891 --------------------------------------------------
LAUNCH WARNING 2022-07-19 18:54:26,891 Compatible mode enable with args ['--gpus=0']
----------- Configuration Arguments -----------
backend: auto
cluster_topo_path: None
elastic_pre_hook: None
elastic_server: None
enable_auto_mapping: False
force: False
gpus: 0
heter_devices:
heter_worker_num: None
heter_workers:
host: None
http_port: None
ips: 127.0.0.1
job_id: None
log_dir: log
np: None
nproc_per_node: None
rank_mapping_path: None
run_mode: None
scale: 0
server_num: None
servers:
training_script: tools/train.py
training_script_args: ['-c', 'ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml']
worker_num: None
workers:
------------------------------------------------
WARNING 2022-07-19 18:54:26,892 launch.py:519] Not found distinct arguments and compiled with cuda or xpu or npu or mlu. Default use collective mode
WARNING 2022-07-19 18:54:26,892 launch.py:519] Not found distinct arguments and compiled with cuda or xpu or npu or mlu. Default use collective mode
launch train in GPU mode!
INFO 2022-07-19 18:54:26,894 launch_utils.py:561] Local start 1 processes. First process distributed environment info (Only For Debug):
+=======================================================================================+
| Distributed Envs Value |
+---------------------------------------------------------------------------------------+
| PADDLE_TRAINER_ID 0 |
| PADDLE_CURRENT_ENDPOINT 127.0.0.1:58011 |
| PADDLE_TRAINERS_NUM 1 |
| PADDLE_TRAINER_ENDPOINTS 127.0.0.1:58011 |
| PADDLE_RANK_IN_NODE 0 |
| PADDLE_LOCAL_DEVICE_IDS 0 |
| PADDLE_WORLD_DEVICE_IDS 0 |
| FLAGS_selected_gpus 0 |
| FLAGS_selected_accelerators 0 |
+=======================================================================================+
INFO 2022-07-19 18:54:26,894 launch_utils.py:561] Local start 1 processes. First process distributed environment info (Only For Debug):
+=======================================================================================+
| Distributed Envs Value |
+---------------------------------------------------------------------------------------+
| PADDLE_TRAINER_ID 0 |
| PADDLE_CURRENT_ENDPOINT 127.0.0.1:58011 |
| PADDLE_TRAINERS_NUM 1 |
| PADDLE_TRAINER_ENDPOINTS 127.0.0.1:58011 |
| PADDLE_RANK_IN_NODE 0 |
| PADDLE_LOCAL_DEVICE_IDS 0 |
| PADDLE_WORLD_DEVICE_IDS 0 |
| FLAGS_selected_gpus 0 |
| FLAGS_selected_accelerators 0 |
+=======================================================================================+
INFO 2022-07-19 18:54:26,894 launch_utils.py:566] details about PADDLE_TRAINER_ENDPOINTS can be found in log/endpoints.log, and detail running logs maybe found in log/workerlog.0
INFO 2022-07-19 18:54:26,894 launch_utils.py:566] details about PADDLE_TRAINER_ENDPOINTS can be found in log/endpoints.log, and detail running logs maybe found in log/workerlog.0
launch proc_id:19563 idx:0
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sized
[2022/07/19 18:54:29] ppcls INFO:
===========================================================
== PaddleClas is powered by PaddlePaddle ! ==
===========================================================
== ==
== For more info please go to the following website. ==
== ==
== https://github.com/PaddlePaddle/PaddleClas ==
===========================================================
[2022/07/19 18:54:29] ppcls INFO: Arch :
[2022/07/19 18:54:29] ppcls INFO: class_num : 10
[2022/07/19 18:54:29] ppcls INFO: name : PPLCNet_x1_0
[2022/07/19 18:54:29] ppcls INFO: DataLoader :
[2022/07/19 18:54:29] ppcls INFO: Eval :
[2022/07/19 18:54:29] ppcls INFO: dataset :
[2022/07/19 18:54:29] ppcls INFO: cls_label_path : ./dataset/val_list.txt
[2022/07/19 18:54:29] ppcls INFO: image_root : ./dataset/
[2022/07/19 18:54:29] ppcls INFO: name : ImageNetDataset
[2022/07/19 18:54:29] ppcls INFO: transform_ops :
[2022/07/19 18:54:29] ppcls INFO: DecodeImage :
[2022/07/19 18:54:29] ppcls INFO: channel_first : False
[2022/07/19 18:54:29] ppcls INFO: to_rgb : True
[2022/07/19 18:54:29] ppcls INFO: ResizeImage :
[2022/07/19 18:54:29] ppcls INFO: resize_short : 256
[2022/07/19 18:54:29] ppcls INFO: CropImage :
[2022/07/19 18:54:29] ppcls INFO: size : 224
[2022/07/19 18:54:29] ppcls INFO: NormalizeImage :
[2022/07/19 18:54:29] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 18:54:29] ppcls INFO: order :
[2022/07/19 18:54:29] ppcls INFO: scale : 1.0/255.0
[2022/07/19 18:54:29] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 18:54:29] ppcls INFO: loader :
[2022/07/19 18:54:29] ppcls INFO: num_workers : 4
[2022/07/19 18:54:29] ppcls INFO: use_shared_memory : True
[2022/07/19 18:54:29] ppcls INFO: sampler :
[2022/07/19 18:54:29] ppcls INFO: batch_size : 16
[2022/07/19 18:54:29] ppcls INFO: drop_last : False
[2022/07/19 18:54:29] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 18:54:29] ppcls INFO: shuffle : False
[2022/07/19 18:54:29] ppcls INFO: Train :
[2022/07/19 18:54:29] ppcls INFO: dataset :
[2022/07/19 18:54:29] ppcls INFO: cls_label_path : ./dataset/train_list.txt
[2022/07/19 18:54:29] ppcls INFO: image_root : ./dataset/
[2022/07/19 18:54:29] ppcls INFO: name : ImageNetDataset
[2022/07/19 18:54:29] ppcls INFO: transform_ops :
[2022/07/19 18:54:29] ppcls INFO: DecodeImage :
[2022/07/19 18:54:29] ppcls INFO: channel_first : False
[2022/07/19 18:54:29] ppcls INFO: to_rgb : True
[2022/07/19 18:54:29] ppcls INFO: RandCropImage :
[2022/07/19 18:54:29] ppcls INFO: size : 224
[2022/07/19 18:54:29] ppcls INFO: RandFlipImage :
[2022/07/19 18:54:29] ppcls INFO: flip_code : 1
[2022/07/19 18:54:29] ppcls INFO: NormalizeImage :
[2022/07/19 18:54:29] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 18:54:29] ppcls INFO: order :
[2022/07/19 18:54:29] ppcls INFO: scale : 1.0/255.0
[2022/07/19 18:54:29] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 18:54:29] ppcls INFO: loader :
[2022/07/19 18:54:29] ppcls INFO: num_workers : 4
[2022/07/19 18:54:29] ppcls INFO: use_shared_memory : True
[2022/07/19 18:54:29] ppcls INFO: sampler :
[2022/07/19 18:54:29] ppcls INFO: batch_size : 16
[2022/07/19 18:54:29] ppcls INFO: drop_last : False
[2022/07/19 18:54:29] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 18:54:29] ppcls INFO: shuffle : True
[2022/07/19 18:54:29] ppcls INFO: Global :
[2022/07/19 18:54:29] ppcls INFO: checkpoints : None
[2022/07/19 18:54:29] ppcls INFO: device : gpu
[2022/07/19 18:54:29] ppcls INFO: epochs : 10
[2022/07/19 18:54:29] ppcls INFO: eval_during_train : True
[2022/07/19 18:54:29] ppcls INFO: eval_interval : 1
[2022/07/19 18:54:29] ppcls INFO: image_shape : [3, 224, 224]
[2022/07/19 18:54:29] ppcls INFO: output_dir : ./output/
[2022/07/19 18:54:29] ppcls INFO: pretrained_model : https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_pretrained.pdparams
[2022/07/19 18:54:29] ppcls INFO: print_batch_step : 10
[2022/07/19 18:54:29] ppcls INFO: save_inference_dir : ./inference
[2022/07/19 18:54:29] ppcls INFO: save_interval : 1
[2022/07/19 18:54:29] ppcls INFO: use_visualdl : False
[2022/07/19 18:54:29] ppcls INFO: Infer :
[2022/07/19 18:54:29] ppcls INFO: PostProcess :
[2022/07/19 18:54:29] ppcls INFO: class_id_map_file : ./dataset/labels.txt
[2022/07/19 18:54:29] ppcls INFO: name : Topk
[2022/07/19 18:54:29] ppcls INFO: topk : 5
[2022/07/19 18:54:29] ppcls INFO: batch_size : 2.5
[2022/07/19 18:54:29] ppcls INFO: infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/07/19 18:54:29] ppcls INFO: transforms :
[2022/07/19 18:54:29] ppcls INFO: DecodeImage :
[2022/07/19 18:54:29] ppcls INFO: channel_first : False
[2022/07/19 18:54:29] ppcls INFO: to_rgb : True
[2022/07/19 18:54:29] ppcls INFO: ResizeImage :
[2022/07/19 18:54:29] ppcls INFO: resize_short : 256
[2022/07/19 18:54:29] ppcls INFO: CropImage :
[2022/07/19 18:54:29] ppcls INFO: size : 224
[2022/07/19 18:54:29] ppcls INFO: NormalizeImage :
[2022/07/19 18:54:29] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 18:54:29] ppcls INFO: order :
[2022/07/19 18:54:29] ppcls INFO: scale : 1.0/255.0
[2022/07/19 18:54:29] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 18:54:29] ppcls INFO: ToCHWImage : None
[2022/07/19 18:54:29] ppcls INFO: Loss :
[2022/07/19 18:54:29] ppcls INFO: Eval :
[2022/07/19 18:54:29] ppcls INFO: CELoss :
[2022/07/19 18:54:29] ppcls INFO: weight : 1.0
[2022/07/19 18:54:29] ppcls INFO: Train :
[2022/07/19 18:54:29] ppcls INFO: CELoss :
[2022/07/19 18:54:29] ppcls INFO: epsilon : 0.1
[2022/07/19 18:54:29] ppcls INFO: weight : 1.0
[2022/07/19 18:54:29] ppcls INFO: Metric :
[2022/07/19 18:54:29] ppcls INFO: Eval :
[2022/07/19 18:54:29] ppcls INFO: TopkAcc :
[2022/07/19 18:54:29] ppcls INFO: topk : [1, 5]
[2022/07/19 18:54:29] ppcls INFO: Train :
[2022/07/19 18:54:29] ppcls INFO: TopkAcc :
[2022/07/19 18:54:29] ppcls INFO: topk : [1, 5]
[2022/07/19 18:54:29] ppcls INFO: Optimizer :
[2022/07/19 18:54:29] ppcls INFO: lr :
[2022/07/19 18:54:29] ppcls INFO: learning_rate : 0.00625
[2022/07/19 18:54:29] ppcls INFO: name : Cosine
[2022/07/19 18:54:29] ppcls INFO: warmup_epoch : 5
[2022/07/19 18:54:29] ppcls INFO: momentum : 0.9
[2022/07/19 18:54:29] ppcls INFO: name : Momentum
[2022/07/19 18:54:29] ppcls INFO: regularizer :
[2022/07/19 18:54:29] ppcls INFO: coeff : 3e-05
[2022/07/19 18:54:29] ppcls INFO: name : L2
[2022/07/19 18:54:29] ppcls INFO: profiler_options : None
[2022/07/19 18:54:29] ppcls INFO: train with paddle 2.3.0 and device Place(gpu:0)
W0719 18:54:29.291875 19563 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0719 18:54:29.296648 19563 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
[2022/07/19 18:54:33] ppcls INFO: unique_endpoints {'127.0.0.1:58011'}
[2022/07/19 18:54:33] ppcls INFO: Found /home/aistudio/.paddleclas/weights/PPLCNet_x1_0_pretrained.pdparams
[2022/07/19 18:54:33] ppcls WARNING: The training strategy provided by PaddleClas is based on 4 gpus. But the number of gpu is 1 in current training. Please modify the stategy (learning rate, batch size and so on) if use this config to train.
[2022/07/19 18:54:40] ppcls INFO: [Train][Epoch 1/10][Iter: 0/44]lr(LinearWarmup): 0.00002841, top1: 0.06250, top5: 0.37500, CELoss: 2.49782, loss: 2.49782, batch_cost: 7.21715s, reader_cost: 7.02618, ips: 2.21694 samples/s, eta: 0:52:55
[2022/07/19 18:54:54] ppcls INFO: [Train][Epoch 1/10][Iter: 10/44]lr(LinearWarmup): 0.00031250, top1: 0.10227, top5: 0.50568, CELoss: 2.41375, loss: 2.41375, batch_cost: 1.26793s, reader_cost: 1.19930, ips: 12.61900 samples/s, eta: 0:09:05
[2022/07/19 18:55:13] ppcls INFO: [Train][Epoch 1/10][Iter: 20/44]lr(LinearWarmup): 0.00059659, top1: 0.14881, top5: 0.61607, CELoss: 2.31057, loss: 2.31057, batch_cost: 1.71211s, reader_cost: 1.63361, ips: 9.34522 samples/s, eta: 0:11:59
[2022/07/19 18:55:28] ppcls INFO: [Train][Epoch 1/10][Iter: 30/44]lr(LinearWarmup): 0.00088068, top1: 0.22782, top5: 0.67742, CELoss: 2.20175, loss: 2.20175, batch_cost: 1.61461s, reader_cost: 1.53020, ips: 9.90949 samples/s, eta: 0:11:01
[2022/07/19 18:55:46] ppcls INFO: [Train][Epoch 1/10][Iter: 40/44]lr(LinearWarmup): 0.00116477, top1: 0.32927, top5: 0.74695, CELoss: 2.04212, loss: 2.04212, batch_cost: 1.67579s, reader_cost: 1.59619, ips: 9.54771 samples/s, eta: 0:11:10
[2022/07/19 18:55:47] ppcls INFO: [Train][Epoch 1/10][Avg]top1: 0.35429, top5: 0.75429, CELoss: 2.00069, loss: 2.00069
[2022/07/19 18:55:56] ppcls INFO: [Eval][Epoch 1][Iter: 0/13]CELoss: 0.92097, loss: 0.92097, top1: 0.87500, top5: 1.00000, batch_cost: 9.28455s, reader_cost: 9.19475, ips: 1.72329 images/sec
[2022/07/19 18:56:13] ppcls INFO: [Eval][Epoch 1][Iter: 10/13]CELoss: 0.77980, loss: 0.77980, top1: 0.97727, top5: 1.00000, batch_cost: 1.43464s, reader_cost: 1.41019, ips: 11.15263 images/sec
[2022/07/19 18:56:15] ppcls INFO: [Eval][Epoch 1][Avg]CELoss: 0.66045, loss: 0.66045, top1: 0.98000, top5: 1.00000
[2022/07/19 18:56:15] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/best_model
[2022/07/19 18:56:15] ppcls INFO: [Eval][Epoch 1][best metric: 0.9799999594688416]
[2022/07/19 18:56:15] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_1
[2022/07/19 18:56:15] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 18:56:22] ppcls INFO: [Train][Epoch 2/10][Iter: 0/44]lr(LinearWarmup): 0.00127841, top1: 0.81250, top5: 1.00000, CELoss: 1.27425, loss: 1.27425, batch_cost: 1.69805s, reader_cost: 1.61973, ips: 9.42257 samples/s, eta: 0:11:12
[2022/07/19 18:56:37] ppcls INFO: [Train][Epoch 2/10][Iter: 10/44]lr(LinearWarmup): 0.00156250, top1: 0.84659, top5: 0.98295, CELoss: 1.04811, loss: 1.04811, batch_cost: 1.13406s, reader_cost: 1.07299, ips: 14.10854 samples/s, eta: 0:07:17
[2022/07/19 18:56:56] ppcls INFO: [Train][Epoch 2/10][Iter: 20/44]lr(LinearWarmup): 0.00184659, top1: 0.87202, top5: 0.97619, CELoss: 0.97516, loss: 0.97516, batch_cost: 1.58010s, reader_cost: 1.50765, ips: 10.12593 samples/s, eta: 0:09:54
[2022/07/19 18:57:10] ppcls INFO: [Train][Epoch 2/10][Iter: 30/44]lr(LinearWarmup): 0.00213068, top1: 0.88306, top5: 0.98185, CELoss: 0.91531, loss: 0.91531, batch_cost: 1.53841s, reader_cost: 1.46148, ips: 10.40035 samples/s, eta: 0:09:23
[2022/07/19 18:57:29] ppcls INFO: [Train][Epoch 2/10][Iter: 40/44]lr(LinearWarmup): 0.00241477, top1: 0.89939, top5: 0.98476, CELoss: 0.86870, loss: 0.86870, batch_cost: 1.63912s, reader_cost: 1.55939, ips: 9.76135 samples/s, eta: 0:09:43
[2022/07/19 18:57:31] ppcls INFO: [Train][Epoch 2/10][Avg]top1: 0.90143, top5: 0.98571, CELoss: 0.85959, loss: 0.85959
[2022/07/19 18:57:40] ppcls INFO: [Eval][Epoch 2][Iter: 0/13]CELoss: 0.09414, loss: 0.09414, top1: 1.00000, top5: 1.00000, batch_cost: 9.11237s, reader_cost: 9.08816, ips: 1.75586 images/sec
[2022/07/19 18:57:56] ppcls INFO: [Eval][Epoch 2][Iter: 10/13]CELoss: 0.06553, loss: 0.06553, top1: 1.00000, top5: 1.00000, batch_cost: 1.35222s, reader_cost: 1.31854, ips: 11.83241 images/sec
[2022/07/19 18:57:58] ppcls INFO: [Eval][Epoch 2][Avg]CELoss: 0.05911, loss: 0.05911, top1: 1.00000, top5: 1.00000
[2022/07/19 18:57:58] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/best_model
[2022/07/19 18:57:58] ppcls INFO: [Eval][Epoch 2][best metric: 1.0]
[2022/07/19 18:57:58] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_2
[2022/07/19 18:57:58] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 18:58:05] ppcls INFO: [Train][Epoch 3/10][Iter: 0/44]lr(LinearWarmup): 0.00252841, top1: 1.00000, top5: 1.00000, CELoss: 0.77644, loss: 0.77644, batch_cost: 1.68143s, reader_cost: 1.60299, ips: 9.51569 samples/s, eta: 0:09:51
[2022/07/19 18:58:19] ppcls INFO: [Train][Epoch 3/10][Iter: 10/44]lr(LinearWarmup): 0.00281250, top1: 0.93750, top5: 0.98864, CELoss: 0.73684, loss: 0.73684, batch_cost: 1.19664s, reader_cost: 1.10043, ips: 13.37076 samples/s, eta: 0:06:49
[2022/07/19 18:58:39] ppcls INFO: [Train][Epoch 3/10][Iter: 20/44]lr(LinearWarmup): 0.00309659, top1: 0.93452, top5: 0.99107, CELoss: 0.74565, loss: 0.74565, batch_cost: 1.70498s, reader_cost: 1.61474, ips: 9.38429 samples/s, eta: 0:09:26
[2022/07/19 18:58:54] ppcls INFO: [Train][Epoch 3/10][Iter: 30/44]lr(LinearWarmup): 0.00338068, top1: 0.92339, top5: 0.98589, CELoss: 0.75553, loss: 0.75553, batch_cost: 1.61963s, reader_cost: 1.53439, ips: 9.87880 samples/s, eta: 0:08:41
[2022/07/19 18:59:12] ppcls INFO: [Train][Epoch 3/10][Iter: 40/44]lr(LinearWarmup): 0.00366477, top1: 0.92835, top5: 0.98780, CELoss: 0.74052, loss: 0.74052, batch_cost: 1.65231s, reader_cost: 1.56699, ips: 9.68340 samples/s, eta: 0:08:35
[2022/07/19 18:59:13] ppcls INFO: [Train][Epoch 3/10][Avg]top1: 0.93143, top5: 0.98714, CELoss: 0.73704, loss: 0.73704
[2022/07/19 18:59:22] ppcls INFO: [Eval][Epoch 3][Iter: 0/13]CELoss: 0.07857, loss: 0.07857, top1: 1.00000, top5: 1.00000, batch_cost: 8.96303s, reader_cost: 8.87793, ips: 1.78511 images/sec
[2022/07/19 18:59:40] ppcls INFO: [Eval][Epoch 3][Iter: 10/13]CELoss: 0.08117, loss: 0.08117, top1: 1.00000, top5: 1.00000, batch_cost: 1.45158s, reader_cost: 1.41663, ips: 11.02251 images/sec
[2022/07/19 18:59:42] ppcls INFO: [Eval][Epoch 3][Avg]CELoss: 0.06262, loss: 0.06262, top1: 1.00000, top5: 1.00000
[2022/07/19 18:59:42] ppcls INFO: [Eval][Epoch 3][best metric: 1.0]
[2022/07/19 18:59:42] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_3
[2022/07/19 18:59:42] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 18:59:50] ppcls INFO: [Train][Epoch 4/10][Iter: 0/44]lr(LinearWarmup): 0.00377841, top1: 0.93750, top5: 1.00000, CELoss: 0.66027, loss: 0.66027, batch_cost: 1.70246s, reader_cost: 1.61926, ips: 9.39816 samples/s, eta: 0:08:44
[2022/07/19 19:00:03] ppcls INFO: [Train][Epoch 4/10][Iter: 10/44]lr(LinearWarmup): 0.00406250, top1: 0.97159, top5: 0.99432, CELoss: 0.66069, loss: 0.66069, batch_cost: 1.08780s, reader_cost: 1.01769, ips: 14.70861 samples/s, eta: 0:05:24
[2022/07/19 19:00:23] ppcls INFO: [Train][Epoch 4/10][Iter: 20/44]lr(LinearWarmup): 0.00434659, top1: 0.96726, top5: 0.99702, CELoss: 0.65925, loss: 0.65925, batch_cost: 1.65806s, reader_cost: 1.58666, ips: 9.64986 samples/s, eta: 0:07:57
[2022/07/19 19:00:37] ppcls INFO: [Train][Epoch 4/10][Iter: 30/44]lr(LinearWarmup): 0.00463068, top1: 0.96573, top5: 0.99395, CELoss: 0.66205, loss: 0.66205, batch_cost: 1.58151s, reader_cost: 1.50100, ips: 10.11689 samples/s, eta: 0:07:19
[2022/07/19 19:00:56] ppcls INFO: [Train][Epoch 4/10][Iter: 40/44]lr(LinearWarmup): 0.00491477, top1: 0.96494, top5: 0.99390, CELoss: 0.65981, loss: 0.65981, batch_cost: 1.66432s, reader_cost: 1.58027, ips: 9.61354 samples/s, eta: 0:07:26
[2022/07/19 19:00:57] ppcls INFO: [Train][Epoch 4/10][Avg]top1: 0.96429, top5: 0.99429, CELoss: 0.65890, loss: 0.65890
[2022/07/19 19:01:06] ppcls INFO: [Eval][Epoch 4][Iter: 0/13]CELoss: 0.14100, loss: 0.14100, top1: 1.00000, top5: 1.00000, batch_cost: 8.79275s, reader_cost: 8.69995, ips: 1.81968 images/sec
[2022/07/19 19:01:23] ppcls INFO: [Eval][Epoch 4][Iter: 10/13]CELoss: 0.07985, loss: 0.07985, top1: 1.00000, top5: 1.00000, batch_cost: 1.43992s, reader_cost: 1.41531, ips: 11.11174 images/sec
[2022/07/19 19:01:24] ppcls INFO: [Eval][Epoch 4][Avg]CELoss: 0.09826, loss: 0.09826, top1: 1.00000, top5: 1.00000
[2022/07/19 19:01:24] ppcls INFO: [Eval][Epoch 4][best metric: 1.0]
[2022/07/19 19:01:25] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_4
[2022/07/19 19:01:25] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 19:01:32] ppcls INFO: [Train][Epoch 5/10][Iter: 0/44]lr(LinearWarmup): 0.00502841, top1: 1.00000, top5: 1.00000, CELoss: 0.65752, loss: 0.65752, batch_cost: 1.69117s, reader_cost: 1.61090, ips: 9.46088 samples/s, eta: 0:07:26
[2022/07/19 19:01:46] ppcls INFO: [Train][Epoch 5/10][Iter: 10/44]lr(LinearWarmup): 0.00531250, top1: 0.97159, top5: 0.99432, CELoss: 0.66519, loss: 0.66519, batch_cost: 1.21865s, reader_cost: 1.12642, ips: 13.12930 samples/s, eta: 0:05:09
[2022/07/19 19:02:06] ppcls INFO: [Train][Epoch 5/10][Iter: 20/44]lr(LinearWarmup): 0.00559659, top1: 0.97024, top5: 0.99702, CELoss: 0.66501, loss: 0.66501, batch_cost: 1.68107s, reader_cost: 1.59422, ips: 9.51775 samples/s, eta: 0:06:50
[2022/07/19 19:02:21] ppcls INFO: [Train][Epoch 5/10][Iter: 30/44]lr(LinearWarmup): 0.00588068, top1: 0.96774, top5: 0.99597, CELoss: 0.66524, loss: 0.66524, batch_cost: 1.61575s, reader_cost: 1.53074, ips: 9.90252 samples/s, eta: 0:06:18
[2022/07/19 19:02:38] ppcls INFO: [Train][Epoch 5/10][Iter: 40/44]lr(LinearWarmup): 0.00616477, top1: 0.96799, top5: 0.99543, CELoss: 0.66001, loss: 0.66001, batch_cost: 1.65601s, reader_cost: 1.57411, ips: 9.66177 samples/s, eta: 0:06:10
[2022/07/19 19:02:39] ppcls INFO: [Train][Epoch 5/10][Avg]top1: 0.96857, top5: 0.99429, CELoss: 0.65961, loss: 0.65961
[2022/07/19 19:02:49] ppcls INFO: [Eval][Epoch 5][Iter: 0/13]CELoss: 0.10051, loss: 0.10051, top1: 1.00000, top5: 1.00000, batch_cost: 9.40426s, reader_cost: 9.37807, ips: 1.70136 images/sec
[2022/07/19 19:03:06] ppcls INFO: [Eval][Epoch 5][Iter: 10/13]CELoss: 0.07818, loss: 0.07818, top1: 1.00000, top5: 1.00000, batch_cost: 1.39798s, reader_cost: 1.36674, ips: 11.44509 images/sec
[2022/07/19 19:03:08] ppcls INFO: [Eval][Epoch 5][Avg]CELoss: 0.09212, loss: 0.09212, top1: 1.00000, top5: 1.00000
[2022/07/19 19:03:08] ppcls INFO: [Eval][Epoch 5][best metric: 1.0]
[2022/07/19 19:03:08] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_5
[2022/07/19 19:03:08] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 19:03:15] ppcls INFO: [Train][Epoch 6/10][Iter: 0/44]lr(LinearWarmup): 0.00624968, top1: 0.93750, top5: 1.00000, CELoss: 0.66260, loss: 0.66260, batch_cost: 1.68322s, reader_cost: 1.60517, ips: 9.50556 samples/s, eta: 0:06:10
[2022/07/19 19:03:29] ppcls INFO: [Train][Epoch 6/10][Iter: 10/44]lr(LinearWarmup): 0.00621153, top1: 0.93182, top5: 0.99432, CELoss: 0.70450, loss: 0.70450, batch_cost: 1.13245s, reader_cost: 1.04904, ips: 14.12864 samples/s, eta: 0:03:57
[2022/07/19 19:03:50] ppcls INFO: [Train][Epoch 6/10][Iter: 20/44]lr(LinearWarmup): 0.00611054, top1: 0.94940, top5: 0.99405, CELoss: 0.69122, loss: 0.69122, batch_cost: 1.74957s, reader_cost: 1.66941, ips: 9.14513 samples/s, eta: 0:05:49
[2022/07/19 19:04:05] ppcls INFO: [Train][Epoch 6/10][Iter: 30/44]lr(LinearWarmup): 0.00594877, top1: 0.95161, top5: 0.99597, CELoss: 0.68098, loss: 0.68098, batch_cost: 1.64175s, reader_cost: 1.55872, ips: 9.74569 samples/s, eta: 0:05:11
[2022/07/19 19:04:23] ppcls INFO: [Train][Epoch 6/10][Iter: 40/44]lr(LinearWarmup): 0.00572952, top1: 0.95884, top5: 0.99695, CELoss: 0.66194, loss: 0.66194, batch_cost: 1.69871s, reader_cost: 1.61421, ips: 9.41889 samples/s, eta: 0:05:05
[2022/07/19 19:04:24] ppcls INFO: [Train][Epoch 6/10][Avg]top1: 0.96143, top5: 0.99714, CELoss: 0.65650, loss: 0.65650
[2022/07/19 19:04:32] ppcls INFO: [Eval][Epoch 6][Iter: 0/13]CELoss: 0.17069, loss: 0.17069, top1: 1.00000, top5: 1.00000, batch_cost: 8.59946s, reader_cost: 8.51504, ips: 1.86058 images/sec
[2022/07/19 19:04:49] ppcls INFO: [Eval][Epoch 6][Iter: 10/13]CELoss: 0.09064, loss: 0.09064, top1: 1.00000, top5: 1.00000, batch_cost: 1.43126s, reader_cost: 1.39280, ips: 11.17894 images/sec
[2022/07/19 19:04:51] ppcls INFO: [Eval][Epoch 6][Avg]CELoss: 0.12623, loss: 0.12623, top1: 1.00000, top5: 1.00000
[2022/07/19 19:04:51] ppcls INFO: [Eval][Epoch 6][best metric: 1.0]
[2022/07/19 19:04:51] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_6
[2022/07/19 19:04:51] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 19:04:58] ppcls INFO: [Train][Epoch 7/10][Iter: 0/44]lr(LinearWarmup): 0.00562669, top1: 0.81250, top5: 0.93750, CELoss: 0.88575, loss: 0.88575, batch_cost: 1.70448s, reader_cost: 1.62408, ips: 9.38704 samples/s, eta: 0:04:59
[2022/07/19 19:05:13] ppcls INFO: [Train][Epoch 7/10][Iter: 10/44]lr(LinearWarmup): 0.00533471, top1: 0.93750, top5: 0.98295, CELoss: 0.68466, loss: 0.68466, batch_cost: 1.21328s, reader_cost: 1.10683, ips: 13.18735 samples/s, eta: 0:03:21
[2022/07/19 19:05:33] ppcls INFO: [Train][Epoch 7/10][Iter: 20/44]lr(LinearWarmup): 0.00499774, top1: 0.95238, top5: 0.99107, CELoss: 0.66636, loss: 0.66636, batch_cost: 1.66867s, reader_cost: 1.58468, ips: 9.58848 samples/s, eta: 0:04:20
[2022/07/19 19:05:46] ppcls INFO: [Train][Epoch 7/10][Iter: 30/44]lr(LinearWarmup): 0.00462265, top1: 0.95565, top5: 0.99395, CELoss: 0.66310, loss: 0.66310, batch_cost: 1.54590s, reader_cost: 1.46111, ips: 10.34996 samples/s, eta: 0:03:45
[2022/07/19 19:06:06] ppcls INFO: [Train][Epoch 7/10][Iter: 40/44]lr(LinearWarmup): 0.00421708, top1: 0.96037, top5: 0.99543, CELoss: 0.65215, loss: 0.65215, batch_cost: 1.66280s, reader_cost: 1.58095, ips: 9.62231 samples/s, eta: 0:03:46
[2022/07/19 19:06:06] ppcls INFO: [Train][Epoch 7/10][Avg]top1: 0.96000, top5: 0.99429, CELoss: 0.65397, loss: 0.65397
[2022/07/19 19:06:16] ppcls INFO: [Eval][Epoch 7][Iter: 0/13]CELoss: 0.07389, loss: 0.07389, top1: 1.00000, top5: 1.00000, batch_cost: 10.20977s, reader_cost: 10.12908, ips: 1.56713 images/sec
[2022/07/19 19:06:32] ppcls INFO: [Eval][Epoch 7][Iter: 10/13]CELoss: 0.09863, loss: 0.09863, top1: 1.00000, top5: 1.00000, batch_cost: 1.32267s, reader_cost: 1.29861, ips: 12.09677 images/sec
[2022/07/19 19:06:34] ppcls INFO: [Eval][Epoch 7][Avg]CELoss: 0.09440, loss: 0.09440, top1: 1.00000, top5: 1.00000
[2022/07/19 19:06:34] ppcls INFO: [Eval][Epoch 7][best metric: 1.0]
[2022/07/19 19:06:35] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_7
[2022/07/19 19:06:35] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 19:06:41] ppcls INFO: [Train][Epoch 8/10][Iter: 0/44]lr(LinearWarmup): 0.00404814, top1: 1.00000, top5: 1.00000, CELoss: 0.56616, loss: 0.56616, batch_cost: 1.67110s, reader_cost: 1.59135, ips: 9.57451 samples/s, eta: 0:03:40
[2022/07/19 19:06:56] ppcls INFO: [Train][Epoch 8/10][Iter: 10/44]lr(LinearWarmup): 0.00361386, top1: 0.95455, top5: 1.00000, CELoss: 0.63547, loss: 0.63547, batch_cost: 1.18147s, reader_cost: 1.08819, ips: 13.54244 samples/s, eta: 0:02:24
[2022/07/19 19:07:16] ppcls INFO: [Train][Epoch 8/10][Iter: 20/44]lr(LinearWarmup): 0.00316962, top1: 0.95238, top5: 1.00000, CELoss: 0.64941, loss: 0.64941, batch_cost: 1.72283s, reader_cost: 1.63022, ips: 9.28705 samples/s, eta: 0:03:12
[2022/07/19 19:07:30] ppcls INFO: [Train][Epoch 8/10][Iter: 30/44]lr(LinearWarmup): 0.00272448, top1: 0.95766, top5: 1.00000, CELoss: 0.63539, loss: 0.63539, batch_cost: 1.59495s, reader_cost: 1.50022, ips: 10.03168 samples/s, eta: 0:02:42
[2022/07/19 19:07:48] ppcls INFO: [Train][Epoch 8/10][Iter: 40/44]lr(LinearWarmup): 0.00228749, top1: 0.96037, top5: 0.99848, CELoss: 0.63345, loss: 0.63345, batch_cost: 1.65191s, reader_cost: 1.56454, ips: 9.68573 samples/s, eta: 0:02:31
[2022/07/19 19:07:49] ppcls INFO: [Train][Epoch 8/10][Avg]top1: 0.96286, top5: 0.99857, CELoss: 0.63022, loss: 0.63022
[2022/07/19 19:07:58] ppcls INFO: [Eval][Epoch 8][Iter: 0/13]CELoss: 0.09073, loss: 0.09073, top1: 1.00000, top5: 1.00000, batch_cost: 9.18364s, reader_cost: 9.09703, ips: 1.74223 images/sec
[2022/07/19 19:08:15] ppcls INFO: [Eval][Epoch 8][Iter: 10/13]CELoss: 0.07859, loss: 0.07859, top1: 1.00000, top5: 1.00000, batch_cost: 1.33330s, reader_cost: 1.30494, ips: 12.00031 images/sec
[2022/07/19 19:08:17] ppcls INFO: [Eval][Epoch 8][Avg]CELoss: 0.08259, loss: 0.08259, top1: 1.00000, top5: 1.00000
[2022/07/19 19:08:17] ppcls INFO: [Eval][Epoch 8][best metric: 1.0]
[2022/07/19 19:08:17] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_8
[2022/07/19 19:08:18] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 19:08:26] ppcls INFO: [Train][Epoch 9/10][Iter: 0/44]lr(LinearWarmup): 0.00211698, top1: 1.00000, top5: 1.00000, CELoss: 0.55877, loss: 0.55877, batch_cost: 1.71710s, reader_cost: 1.63244, ips: 9.31806 samples/s, eta: 0:02:31
[2022/07/19 19:08:40] ppcls INFO: [Train][Epoch 9/10][Iter: 10/44]lr(LinearWarmup): 0.00170628, top1: 0.96591, top5: 1.00000, CELoss: 0.60734, loss: 0.60734, batch_cost: 1.11971s, reader_cost: 1.05329, ips: 14.28938 samples/s, eta: 0:01:27
[2022/07/19 19:08:59] ppcls INFO: [Train][Epoch 9/10][Iter: 20/44]lr(LinearWarmup): 0.00132446, top1: 0.96131, top5: 1.00000, CELoss: 0.63093, loss: 0.63093, batch_cost: 1.63194s, reader_cost: 1.55801, ips: 9.80426 samples/s, eta: 0:01:50
[2022/07/19 19:09:14] ppcls INFO: [Train][Epoch 9/10][Iter: 30/44]lr(LinearWarmup): 0.00097929, top1: 0.97177, top5: 1.00000, CELoss: 0.61646, loss: 0.61646, batch_cost: 1.57376s, reader_cost: 1.49802, ips: 10.16676 samples/s, eta: 0:01:31
[2022/07/19 19:09:31] ppcls INFO: [Train][Epoch 9/10][Iter: 40/44]lr(LinearWarmup): 0.00067781, top1: 0.97409, top5: 1.00000, CELoss: 0.61567, loss: 0.61567, batch_cost: 1.62338s, reader_cost: 1.54411, ips: 9.85597 samples/s, eta: 0:01:17
[2022/07/19 19:09:33] ppcls INFO: [Train][Epoch 9/10][Avg]top1: 0.97429, top5: 1.00000, CELoss: 0.61527, loss: 0.61527
[2022/07/19 19:09:42] ppcls INFO: [Eval][Epoch 9][Iter: 0/13]CELoss: 0.09019, loss: 0.09019, top1: 1.00000, top5: 1.00000, batch_cost: 8.49554s, reader_cost: 8.41041, ips: 1.88334 images/sec
[2022/07/19 19:09:59] ppcls INFO: [Eval][Epoch 9][Iter: 10/13]CELoss: 0.07029, loss: 0.07029, top1: 1.00000, top5: 1.00000, batch_cost: 1.43166s, reader_cost: 1.40579, ips: 11.17581 images/sec
[2022/07/19 19:10:01] ppcls INFO: [Eval][Epoch 9][Avg]CELoss: 0.08078, loss: 0.08078, top1: 1.00000, top5: 1.00000
[2022/07/19 19:10:01] ppcls INFO: [Eval][Epoch 9][best metric: 1.0]
[2022/07/19 19:10:01] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_9
[2022/07/19 19:10:01] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/07/19 19:10:08] ppcls INFO: [Train][Epoch 10/10][Iter: 0/44]lr(LinearWarmup): 0.00057085, top1: 1.00000, top5: 1.00000, CELoss: 0.56639, loss: 0.56639, batch_cost: 1.68346s, reader_cost: 1.60572, ips: 9.50421 samples/s, eta: 0:01:14
[2022/07/19 19:10:22] ppcls INFO: [Train][Epoch 10/10][Iter: 10/44]lr(LinearWarmup): 0.00034060, top1: 0.98864, top5: 1.00000, CELoss: 0.59657, loss: 0.59657, batch_cost: 1.21732s, reader_cost: 1.12300, ips: 13.14364 samples/s, eta: 0:00:41
[2022/07/19 19:10:42] ppcls INFO: [Train][Epoch 10/10][Iter: 20/44]lr(LinearWarmup): 0.00016704, top1: 0.98214, top5: 0.99702, CELoss: 0.60033, loss: 0.60033, batch_cost: 1.69470s, reader_cost: 1.61170, ips: 9.44120 samples/s, eta: 0:00:40
[2022/07/19 19:10:55] ppcls INFO: [Train][Epoch 10/10][Iter: 30/44]lr(LinearWarmup): 0.00005369, top1: 0.98185, top5: 0.99597, CELoss: 0.60543, loss: 0.60543, batch_cost: 1.55448s, reader_cost: 1.47117, ips: 10.29285 samples/s, eta: 0:00:21
[2022/07/19 19:11:14] ppcls INFO: [Train][Epoch 10/10][Iter: 40/44]lr(LinearWarmup): 0.00000287, top1: 0.97866, top5: 0.99695, CELoss: 0.60596, loss: 0.60596, batch_cost: 1.64540s, reader_cost: 1.56367, ips: 9.72407 samples/s, eta: 0:00:06
[2022/07/19 19:11:15] ppcls INFO: [Train][Epoch 10/10][Avg]top1: 0.97857, top5: 0.99714, CELoss: 0.60629, loss: 0.60629
[2022/07/19 19:11:24] ppcls INFO: [Eval][Epoch 10][Iter: 0/13]CELoss: 0.08059, loss: 0.08059, top1: 1.00000, top5: 1.00000, batch_cost: 9.31524s, reader_cost: 9.29288, ips: 1.71762 images/sec
[2022/07/19 19:11:42] ppcls INFO: [Eval][Epoch 10][Iter: 10/13]CELoss: 0.06708, loss: 0.06708, top1: 1.00000, top5: 1.00000, batch_cost: 1.69138s, reader_cost: 1.65910, ips: 9.45974 images/sec
[2022/07/19 19:11:44] ppcls INFO: [Eval][Epoch 10][Avg]CELoss: 0.07274, loss: 0.07274, top1: 1.00000, top5: 1.00000
[2022/07/19 19:11:44] ppcls INFO: [Eval][Epoch 10][best metric: 1.0]
[2022/07/19 19:11:44] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_10
[2022/07/19 19:11:44] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
INFO 2022-07-19 19:11:46,515 launch.py:402] Local processes completed.
INFO 2022-07-19 19:11:46,515 launch.py:402] Local processes completed.
2.3 模型评估
训练好模型之后,可以通过以下命令实现对模型指标的评估。
!python3 tools/eval.py \
-c ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml \
-o Global.pretrained_model=output/PPLCNet_x1_0/best_model
# 验证结果
# [2022/07/19 19:44:10] [Eval][Epoch 0][Iter: 0/13] CELoss: 0.09414, loss: 0.09414, top1: 1.00000, top5: 1.00000, batch_cost: 9.49708s, reader_cost: 9.39857, ips: 1.68473 images/sec
# [2022/07/19 19:44:27] [Eval][Epoch 0][Iter: 10/13]CELoss: 0.06553, loss: 0.06553, top1: 1.00000, top5: 1.00000, batch_cost: 1.36988s, reader_cost: 1.34440, ips: 11.67983 images/sec
# [2022/07/19 19:44:29] [Eval][Epoch 0] [Avg]CELoss: 0.05911, loss: 0.05911, top1: 1.00000, top5: 1.00000
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sized
[2022/07/19 19:43:57] ppcls INFO:
===========================================================
== PaddleClas is powered by PaddlePaddle ! ==
===========================================================
== ==
== For more info please go to the following website. ==
== ==
== https://github.com/PaddlePaddle/PaddleClas ==
===========================================================
[2022/07/19 19:43:57] ppcls INFO: Arch :
[2022/07/19 19:43:57] ppcls INFO: class_num : 10
[2022/07/19 19:43:57] ppcls INFO: name : PPLCNet_x1_0
[2022/07/19 19:43:57] ppcls INFO: DataLoader :
[2022/07/19 19:43:57] ppcls INFO: Eval :
[2022/07/19 19:43:57] ppcls INFO: dataset :
[2022/07/19 19:43:57] ppcls INFO: cls_label_path : ./dataset/val_list.txt
[2022/07/19 19:43:57] ppcls INFO: image_root : ./dataset/
[2022/07/19 19:43:57] ppcls INFO: name : ImageNetDataset
[2022/07/19 19:43:57] ppcls INFO: transform_ops :
[2022/07/19 19:43:57] ppcls INFO: DecodeImage :
[2022/07/19 19:43:57] ppcls INFO: channel_first : False
[2022/07/19 19:43:57] ppcls INFO: to_rgb : True
[2022/07/19 19:43:57] ppcls INFO: ResizeImage :
[2022/07/19 19:43:57] ppcls INFO: resize_short : 256
[2022/07/19 19:43:57] ppcls INFO: CropImage :
[2022/07/19 19:43:57] ppcls INFO: size : 224
[2022/07/19 19:43:57] ppcls INFO: NormalizeImage :
[2022/07/19 19:43:57] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:43:57] ppcls INFO: order :
[2022/07/19 19:43:57] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:43:57] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:43:57] ppcls INFO: loader :
[2022/07/19 19:43:57] ppcls INFO: num_workers : 4
[2022/07/19 19:43:57] ppcls INFO: use_shared_memory : True
[2022/07/19 19:43:57] ppcls INFO: sampler :
[2022/07/19 19:43:57] ppcls INFO: batch_size : 16
[2022/07/19 19:43:57] ppcls INFO: drop_last : False
[2022/07/19 19:43:57] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 19:43:57] ppcls INFO: shuffle : False
[2022/07/19 19:43:57] ppcls INFO: Train :
[2022/07/19 19:43:57] ppcls INFO: dataset :
[2022/07/19 19:43:57] ppcls INFO: cls_label_path : ./dataset/train_list.txt
[2022/07/19 19:43:57] ppcls INFO: image_root : ./dataset/
[2022/07/19 19:43:57] ppcls INFO: name : ImageNetDataset
[2022/07/19 19:43:57] ppcls INFO: transform_ops :
[2022/07/19 19:43:57] ppcls INFO: DecodeImage :
[2022/07/19 19:43:57] ppcls INFO: channel_first : False
[2022/07/19 19:43:57] ppcls INFO: to_rgb : True
[2022/07/19 19:43:57] ppcls INFO: RandCropImage :
[2022/07/19 19:43:57] ppcls INFO: size : 224
[2022/07/19 19:43:57] ppcls INFO: RandFlipImage :
[2022/07/19 19:43:57] ppcls INFO: flip_code : 1
[2022/07/19 19:43:57] ppcls INFO: NormalizeImage :
[2022/07/19 19:43:57] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:43:57] ppcls INFO: order :
[2022/07/19 19:43:57] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:43:57] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:43:57] ppcls INFO: loader :
[2022/07/19 19:43:57] ppcls INFO: num_workers : 4
[2022/07/19 19:43:57] ppcls INFO: use_shared_memory : True
[2022/07/19 19:43:57] ppcls INFO: sampler :
[2022/07/19 19:43:57] ppcls INFO: batch_size : 16
[2022/07/19 19:43:57] ppcls INFO: drop_last : False
[2022/07/19 19:43:57] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 19:43:57] ppcls INFO: shuffle : True
[2022/07/19 19:43:57] ppcls INFO: Global :
[2022/07/19 19:43:57] ppcls INFO: checkpoints : None
[2022/07/19 19:43:57] ppcls INFO: device : gpu
[2022/07/19 19:43:57] ppcls INFO: epochs : 10
[2022/07/19 19:43:57] ppcls INFO: eval_during_train : True
[2022/07/19 19:43:57] ppcls INFO: eval_interval : 1
[2022/07/19 19:43:57] ppcls INFO: image_shape : [3, 224, 224]
[2022/07/19 19:43:57] ppcls INFO: output_dir : ./output/
[2022/07/19 19:43:57] ppcls INFO: pretrained_model : output/PPLCNet_x1_0/best_model
[2022/07/19 19:43:57] ppcls INFO: print_batch_step : 10
[2022/07/19 19:43:57] ppcls INFO: save_inference_dir : ./inference
[2022/07/19 19:43:57] ppcls INFO: save_interval : 1
[2022/07/19 19:43:57] ppcls INFO: use_visualdl : False
[2022/07/19 19:43:57] ppcls INFO: Infer :
[2022/07/19 19:43:57] ppcls INFO: PostProcess :
[2022/07/19 19:43:57] ppcls INFO: class_id_map_file : ./dataset/labels.txt
[2022/07/19 19:43:57] ppcls INFO: name : Topk
[2022/07/19 19:43:57] ppcls INFO: topk : 5
[2022/07/19 19:43:57] ppcls INFO: batch_size : 1
[2022/07/19 19:43:57] ppcls INFO: infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/07/19 19:43:57] ppcls INFO: transforms :
[2022/07/19 19:43:57] ppcls INFO: DecodeImage :
[2022/07/19 19:43:57] ppcls INFO: channel_first : False
[2022/07/19 19:43:57] ppcls INFO: to_rgb : True
[2022/07/19 19:43:57] ppcls INFO: ResizeImage :
[2022/07/19 19:43:57] ppcls INFO: resize_short : 256
[2022/07/19 19:43:57] ppcls INFO: CropImage :
[2022/07/19 19:43:57] ppcls INFO: size : 224
[2022/07/19 19:43:57] ppcls INFO: NormalizeImage :
[2022/07/19 19:43:57] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:43:57] ppcls INFO: order :
[2022/07/19 19:43:57] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:43:57] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:43:57] ppcls INFO: ToCHWImage : None
[2022/07/19 19:43:57] ppcls INFO: Loss :
[2022/07/19 19:43:57] ppcls INFO: Eval :
[2022/07/19 19:43:57] ppcls INFO: CELoss :
[2022/07/19 19:43:57] ppcls INFO: weight : 1.0
[2022/07/19 19:43:57] ppcls INFO: Train :
[2022/07/19 19:43:57] ppcls INFO: CELoss :
[2022/07/19 19:43:57] ppcls INFO: epsilon : 0.1
[2022/07/19 19:43:57] ppcls INFO: weight : 1.0
[2022/07/19 19:43:57] ppcls INFO: Metric :
[2022/07/19 19:43:57] ppcls INFO: Eval :
[2022/07/19 19:43:57] ppcls INFO: TopkAcc :
[2022/07/19 19:43:57] ppcls INFO: topk : [1, 5]
[2022/07/19 19:43:57] ppcls INFO: Train :
[2022/07/19 19:43:57] ppcls INFO: TopkAcc :
[2022/07/19 19:43:57] ppcls INFO: topk : [1, 5]
[2022/07/19 19:43:57] ppcls INFO: Optimizer :
[2022/07/19 19:43:57] ppcls INFO: lr :
[2022/07/19 19:43:57] ppcls INFO: learning_rate : 0.00625
[2022/07/19 19:43:57] ppcls INFO: name : Cosine
[2022/07/19 19:43:57] ppcls INFO: warmup_epoch : 5
[2022/07/19 19:43:57] ppcls INFO: momentum : 0.9
[2022/07/19 19:43:57] ppcls INFO: name : Momentum
[2022/07/19 19:43:57] ppcls INFO: regularizer :
[2022/07/19 19:43:57] ppcls INFO: coeff : 3e-05
[2022/07/19 19:43:57] ppcls INFO: name : L2
[2022/07/19 19:43:57] ppcls INFO: train with paddle 2.3.0 and device Place(gpu:0)
W0719 19:43:57.461098 26725 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0719 19:43:57.465955 26725 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
[2022/07/19 19:44:10] ppcls INFO: [Eval][Epoch 0][Iter: 0/13]CELoss: 0.09414, loss: 0.09414, top1: 1.00000, top5: 1.00000, batch_cost: 9.49708s, reader_cost: 9.39857, ips: 1.68473 images/sec
[2022/07/19 19:44:27] ppcls INFO: [Eval][Epoch 0][Iter: 10/13]CELoss: 0.06553, loss: 0.06553, top1: 1.00000, top5: 1.00000, batch_cost: 1.36988s, reader_cost: 1.34440, ips: 11.67983 images/sec
[2022/07/19 19:44:29] ppcls INFO: [Eval][Epoch 0][Avg]CELoss: 0.05911, loss: 0.05911, top1: 1.00000, top5: 1.00000
2.4 模型预测
模型训练完成之后,可以加载训练得到的预训练模型,进行模型预测。在模型库的 tools/infer.py 中提供了完整的示例,只需执行下述命令即可完成模型预测:
!python3 tools/infer.py \
-c ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml \
-o Global.pretrained_model=output/PPLCNet_x1_0/best_model
# 预测结果评分高达0.95
# [
# {
# 'class_ids': [4, 9, 6, 7, 5],
# 'scores': [0.95325, 0.01007, 0.00961, 0.00652, 0.00556],
# 'file_name': './dataset/taoci/IMG_7923.JPG',
# 'label_names': []
# }
# ]
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sized
[2022/07/19 19:46:28] ppcls INFO:
===========================================================
== PaddleClas is powered by PaddlePaddle ! ==
===========================================================
== ==
== For more info please go to the following website. ==
== ==
== https://github.com/PaddlePaddle/PaddleClas ==
===========================================================
[2022/07/19 19:46:28] ppcls INFO: Arch :
[2022/07/19 19:46:28] ppcls INFO: class_num : 10
[2022/07/19 19:46:28] ppcls INFO: name : PPLCNet_x1_0
[2022/07/19 19:46:28] ppcls INFO: DataLoader :
[2022/07/19 19:46:28] ppcls INFO: Eval :
[2022/07/19 19:46:28] ppcls INFO: dataset :
[2022/07/19 19:46:28] ppcls INFO: cls_label_path : ./dataset/val_list.txt
[2022/07/19 19:46:28] ppcls INFO: image_root : ./dataset/
[2022/07/19 19:46:28] ppcls INFO: name : ImageNetDataset
[2022/07/19 19:46:28] ppcls INFO: transform_ops :
[2022/07/19 19:46:28] ppcls INFO: DecodeImage :
[2022/07/19 19:46:28] ppcls INFO: channel_first : False
[2022/07/19 19:46:28] ppcls INFO: to_rgb : True
[2022/07/19 19:46:28] ppcls INFO: ResizeImage :
[2022/07/19 19:46:28] ppcls INFO: resize_short : 256
[2022/07/19 19:46:28] ppcls INFO: CropImage :
[2022/07/19 19:46:28] ppcls INFO: size : 224
[2022/07/19 19:46:28] ppcls INFO: NormalizeImage :
[2022/07/19 19:46:28] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:46:28] ppcls INFO: order :
[2022/07/19 19:46:28] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:46:28] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:46:28] ppcls INFO: loader :
[2022/07/19 19:46:28] ppcls INFO: num_workers : 4
[2022/07/19 19:46:28] ppcls INFO: use_shared_memory : True
[2022/07/19 19:46:28] ppcls INFO: sampler :
[2022/07/19 19:46:28] ppcls INFO: batch_size : 16
[2022/07/19 19:46:28] ppcls INFO: drop_last : False
[2022/07/19 19:46:28] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 19:46:28] ppcls INFO: shuffle : False
[2022/07/19 19:46:28] ppcls INFO: Train :
[2022/07/19 19:46:28] ppcls INFO: dataset :
[2022/07/19 19:46:28] ppcls INFO: cls_label_path : ./dataset/train_list.txt
[2022/07/19 19:46:28] ppcls INFO: image_root : ./dataset/
[2022/07/19 19:46:28] ppcls INFO: name : ImageNetDataset
[2022/07/19 19:46:28] ppcls INFO: transform_ops :
[2022/07/19 19:46:28] ppcls INFO: DecodeImage :
[2022/07/19 19:46:28] ppcls INFO: channel_first : False
[2022/07/19 19:46:28] ppcls INFO: to_rgb : True
[2022/07/19 19:46:28] ppcls INFO: RandCropImage :
[2022/07/19 19:46:28] ppcls INFO: size : 224
[2022/07/19 19:46:28] ppcls INFO: RandFlipImage :
[2022/07/19 19:46:28] ppcls INFO: flip_code : 1
[2022/07/19 19:46:28] ppcls INFO: NormalizeImage :
[2022/07/19 19:46:28] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:46:28] ppcls INFO: order :
[2022/07/19 19:46:28] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:46:28] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:46:28] ppcls INFO: loader :
[2022/07/19 19:46:28] ppcls INFO: num_workers : 4
[2022/07/19 19:46:28] ppcls INFO: use_shared_memory : True
[2022/07/19 19:46:28] ppcls INFO: sampler :
[2022/07/19 19:46:28] ppcls INFO: batch_size : 16
[2022/07/19 19:46:28] ppcls INFO: drop_last : False
[2022/07/19 19:46:28] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 19:46:28] ppcls INFO: shuffle : True
[2022/07/19 19:46:28] ppcls INFO: Global :
[2022/07/19 19:46:28] ppcls INFO: checkpoints : None
[2022/07/19 19:46:28] ppcls INFO: device : gpu
[2022/07/19 19:46:28] ppcls INFO: epochs : 10
[2022/07/19 19:46:28] ppcls INFO: eval_during_train : True
[2022/07/19 19:46:28] ppcls INFO: eval_interval : 1
[2022/07/19 19:46:28] ppcls INFO: image_shape : [3, 224, 224]
[2022/07/19 19:46:28] ppcls INFO: output_dir : ./output/
[2022/07/19 19:46:28] ppcls INFO: pretrained_model : output/PPLCNet_x1_0/best_model
[2022/07/19 19:46:28] ppcls INFO: print_batch_step : 10
[2022/07/19 19:46:28] ppcls INFO: save_inference_dir : ./inference
[2022/07/19 19:46:28] ppcls INFO: save_interval : 1
[2022/07/19 19:46:28] ppcls INFO: use_visualdl : False
[2022/07/19 19:46:28] ppcls INFO: Infer :
[2022/07/19 19:46:28] ppcls INFO: PostProcess :
[2022/07/19 19:46:28] ppcls INFO: class_id_map_file : ./dataset/labels.txt
[2022/07/19 19:46:28] ppcls INFO: name : Topk
[2022/07/19 19:46:28] ppcls INFO: topk : 5
[2022/07/19 19:46:28] ppcls INFO: batch_size : 1
[2022/07/19 19:46:28] ppcls INFO: infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/07/19 19:46:28] ppcls INFO: transforms :
[2022/07/19 19:46:28] ppcls INFO: DecodeImage :
[2022/07/19 19:46:28] ppcls INFO: channel_first : False
[2022/07/19 19:46:28] ppcls INFO: to_rgb : True
[2022/07/19 19:46:28] ppcls INFO: ResizeImage :
[2022/07/19 19:46:28] ppcls INFO: resize_short : 256
[2022/07/19 19:46:28] ppcls INFO: CropImage :
[2022/07/19 19:46:28] ppcls INFO: size : 224
[2022/07/19 19:46:28] ppcls INFO: NormalizeImage :
[2022/07/19 19:46:28] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:46:28] ppcls INFO: order :
[2022/07/19 19:46:28] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:46:28] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:46:28] ppcls INFO: ToCHWImage : None
[2022/07/19 19:46:28] ppcls INFO: Loss :
[2022/07/19 19:46:28] ppcls INFO: Eval :
[2022/07/19 19:46:28] ppcls INFO: CELoss :
[2022/07/19 19:46:28] ppcls INFO: weight : 1.0
[2022/07/19 19:46:28] ppcls INFO: Train :
[2022/07/19 19:46:28] ppcls INFO: CELoss :
[2022/07/19 19:46:28] ppcls INFO: epsilon : 0.1
[2022/07/19 19:46:28] ppcls INFO: weight : 1.0
[2022/07/19 19:46:28] ppcls INFO: Metric :
[2022/07/19 19:46:28] ppcls INFO: Eval :
[2022/07/19 19:46:28] ppcls INFO: TopkAcc :
[2022/07/19 19:46:28] ppcls INFO: topk : [1, 5]
[2022/07/19 19:46:28] ppcls INFO: Train :
[2022/07/19 19:46:28] ppcls INFO: TopkAcc :
[2022/07/19 19:46:28] ppcls INFO: topk : [1, 5]
[2022/07/19 19:46:28] ppcls INFO: Optimizer :
[2022/07/19 19:46:28] ppcls INFO: lr :
[2022/07/19 19:46:28] ppcls INFO: learning_rate : 0.00625
[2022/07/19 19:46:28] ppcls INFO: name : Cosine
[2022/07/19 19:46:28] ppcls INFO: warmup_epoch : 5
[2022/07/19 19:46:28] ppcls INFO: momentum : 0.9
[2022/07/19 19:46:28] ppcls INFO: name : Momentum
[2022/07/19 19:46:28] ppcls INFO: regularizer :
[2022/07/19 19:46:28] ppcls INFO: coeff : 3e-05
[2022/07/19 19:46:28] ppcls INFO: name : L2
[2022/07/19 19:46:28] ppcls INFO: train with paddle 2.3.0 and device Place(gpu:0)
W0719 19:46:28.515225 27092 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0719 19:46:28.519981 27092 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
invalid literal for int() with base 10: 'dianchi'
[{'class_ids': [4, 9, 6, 7, 5], 'scores': [0.95325, 0.01007, 0.00961, 0.00652, 0.00556], 'file_name': './dataset/taoci/IMG_7923.JPG', 'label_names': []}]
三、树莓派部署
3.1 基于训练得到的权重导出 inference 模型
以下是将权重和模型转换的脚本,执行该脚本可以得到对应的 inference 模型:
!python3 tools/export_model.py \
-c ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml \
-o Global.pretrained_model=output/PPLCNet_x1_0/best_model \
-o Global.save_inference_dir=deploy/models/PPLCNet_x1_0_infer
# 出现以下结果即为导出成功
# Export succeeded! The inference model exported has been saved in "deploy/models/PPLCNet_x1_0_infer".
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/home/aistudio/PaddleClas/ppcls/data/preprocess/ops/timm_autoaugment.py:39: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
_RANDOM_INTERPOLATION = (Image.BILINEAR, Image.BICUBIC)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Sized
[2022/07/19 19:59:23] ppcls INFO:
===========================================================
== PaddleClas is powered by PaddlePaddle ! ==
===========================================================
== ==
== For more info please go to the following website. ==
== ==
== https://github.com/PaddlePaddle/PaddleClas ==
===========================================================
[2022/07/19 19:59:23] ppcls INFO: Arch :
[2022/07/19 19:59:23] ppcls INFO: class_num : 10
[2022/07/19 19:59:23] ppcls INFO: name : PPLCNet_x1_0
[2022/07/19 19:59:23] ppcls INFO: DataLoader :
[2022/07/19 19:59:23] ppcls INFO: Eval :
[2022/07/19 19:59:23] ppcls INFO: dataset :
[2022/07/19 19:59:23] ppcls INFO: cls_label_path : ./dataset/val_list.txt
[2022/07/19 19:59:23] ppcls INFO: image_root : ./dataset/
[2022/07/19 19:59:23] ppcls INFO: name : ImageNetDataset
[2022/07/19 19:59:23] ppcls INFO: transform_ops :
[2022/07/19 19:59:23] ppcls INFO: DecodeImage :
[2022/07/19 19:59:23] ppcls INFO: channel_first : False
[2022/07/19 19:59:23] ppcls INFO: to_rgb : True
[2022/07/19 19:59:23] ppcls INFO: ResizeImage :
[2022/07/19 19:59:23] ppcls INFO: resize_short : 256
[2022/07/19 19:59:23] ppcls INFO: CropImage :
[2022/07/19 19:59:23] ppcls INFO: size : 224
[2022/07/19 19:59:23] ppcls INFO: NormalizeImage :
[2022/07/19 19:59:23] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:59:23] ppcls INFO: order :
[2022/07/19 19:59:23] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:59:23] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:59:23] ppcls INFO: loader :
[2022/07/19 19:59:23] ppcls INFO: num_workers : 4
[2022/07/19 19:59:23] ppcls INFO: use_shared_memory : True
[2022/07/19 19:59:23] ppcls INFO: sampler :
[2022/07/19 19:59:23] ppcls INFO: batch_size : 16
[2022/07/19 19:59:23] ppcls INFO: drop_last : False
[2022/07/19 19:59:23] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 19:59:23] ppcls INFO: shuffle : False
[2022/07/19 19:59:23] ppcls INFO: Train :
[2022/07/19 19:59:23] ppcls INFO: dataset :
[2022/07/19 19:59:23] ppcls INFO: cls_label_path : ./dataset/train_list.txt
[2022/07/19 19:59:23] ppcls INFO: image_root : ./dataset/
[2022/07/19 19:59:23] ppcls INFO: name : ImageNetDataset
[2022/07/19 19:59:23] ppcls INFO: transform_ops :
[2022/07/19 19:59:23] ppcls INFO: DecodeImage :
[2022/07/19 19:59:23] ppcls INFO: channel_first : False
[2022/07/19 19:59:23] ppcls INFO: to_rgb : True
[2022/07/19 19:59:23] ppcls INFO: RandCropImage :
[2022/07/19 19:59:23] ppcls INFO: size : 224
[2022/07/19 19:59:23] ppcls INFO: RandFlipImage :
[2022/07/19 19:59:23] ppcls INFO: flip_code : 1
[2022/07/19 19:59:23] ppcls INFO: NormalizeImage :
[2022/07/19 19:59:23] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:59:23] ppcls INFO: order :
[2022/07/19 19:59:23] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:59:23] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:59:23] ppcls INFO: loader :
[2022/07/19 19:59:23] ppcls INFO: num_workers : 4
[2022/07/19 19:59:23] ppcls INFO: use_shared_memory : True
[2022/07/19 19:59:23] ppcls INFO: sampler :
[2022/07/19 19:59:23] ppcls INFO: batch_size : 16
[2022/07/19 19:59:23] ppcls INFO: drop_last : False
[2022/07/19 19:59:23] ppcls INFO: name : DistributedBatchSampler
[2022/07/19 19:59:23] ppcls INFO: shuffle : True
[2022/07/19 19:59:23] ppcls INFO: Global :
[2022/07/19 19:59:23] ppcls INFO: checkpoints : None
[2022/07/19 19:59:23] ppcls INFO: device : gpu
[2022/07/19 19:59:23] ppcls INFO: epochs : 10
[2022/07/19 19:59:23] ppcls INFO: eval_during_train : True
[2022/07/19 19:59:23] ppcls INFO: eval_interval : 1
[2022/07/19 19:59:23] ppcls INFO: image_shape : [3, 224, 224]
[2022/07/19 19:59:23] ppcls INFO: output_dir : ./output/
[2022/07/19 19:59:23] ppcls INFO: pretrained_model : output/PPLCNet_x1_0/best_model
[2022/07/19 19:59:23] ppcls INFO: print_batch_step : 10
[2022/07/19 19:59:23] ppcls INFO: save_inference_dir : deploy/models/PPLCNet_x1_0_infer
[2022/07/19 19:59:23] ppcls INFO: save_interval : 1
[2022/07/19 19:59:23] ppcls INFO: use_visualdl : False
[2022/07/19 19:59:23] ppcls INFO: Infer :
[2022/07/19 19:59:23] ppcls INFO: PostProcess :
[2022/07/19 19:59:23] ppcls INFO: class_id_map_file : ./dataset/labels.txt
[2022/07/19 19:59:23] ppcls INFO: name : Topk
[2022/07/19 19:59:23] ppcls INFO: topk : 5
[2022/07/19 19:59:23] ppcls INFO: batch_size : 1
[2022/07/19 19:59:23] ppcls INFO: infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/07/19 19:59:23] ppcls INFO: transforms :
[2022/07/19 19:59:23] ppcls INFO: DecodeImage :
[2022/07/19 19:59:23] ppcls INFO: channel_first : False
[2022/07/19 19:59:23] ppcls INFO: to_rgb : True
[2022/07/19 19:59:23] ppcls INFO: ResizeImage :
[2022/07/19 19:59:23] ppcls INFO: resize_short : 256
[2022/07/19 19:59:23] ppcls INFO: CropImage :
[2022/07/19 19:59:23] ppcls INFO: size : 224
[2022/07/19 19:59:23] ppcls INFO: NormalizeImage :
[2022/07/19 19:59:23] ppcls INFO: mean : [0.485, 0.456, 0.406]
[2022/07/19 19:59:23] ppcls INFO: order :
[2022/07/19 19:59:23] ppcls INFO: scale : 1.0/255.0
[2022/07/19 19:59:23] ppcls INFO: std : [0.229, 0.224, 0.225]
[2022/07/19 19:59:23] ppcls INFO: ToCHWImage : None
[2022/07/19 19:59:23] ppcls INFO: Loss :
[2022/07/19 19:59:23] ppcls INFO: Eval :
[2022/07/19 19:59:23] ppcls INFO: CELoss :
[2022/07/19 19:59:23] ppcls INFO: weight : 1.0
[2022/07/19 19:59:23] ppcls INFO: Train :
[2022/07/19 19:59:23] ppcls INFO: CELoss :
[2022/07/19 19:59:23] ppcls INFO: epsilon : 0.1
[2022/07/19 19:59:23] ppcls INFO: weight : 1.0
[2022/07/19 19:59:23] ppcls INFO: Metric :
[2022/07/19 19:59:23] ppcls INFO: Eval :
[2022/07/19 19:59:23] ppcls INFO: TopkAcc :
[2022/07/19 19:59:23] ppcls INFO: topk : [1, 5]
[2022/07/19 19:59:23] ppcls INFO: Train :
[2022/07/19 19:59:23] ppcls INFO: TopkAcc :
[2022/07/19 19:59:23] ppcls INFO: topk : [1, 5]
[2022/07/19 19:59:23] ppcls INFO: Optimizer :
[2022/07/19 19:59:23] ppcls INFO: lr :
[2022/07/19 19:59:23] ppcls INFO: learning_rate : 0.00625
[2022/07/19 19:59:23] ppcls INFO: name : Cosine
[2022/07/19 19:59:23] ppcls INFO: warmup_epoch : 5
[2022/07/19 19:59:23] ppcls INFO: momentum : 0.9
[2022/07/19 19:59:23] ppcls INFO: name : Momentum
[2022/07/19 19:59:23] ppcls INFO: regularizer :
[2022/07/19 19:59:23] ppcls INFO: coeff : 3e-05
[2022/07/19 19:59:23] ppcls INFO: name : L2
[2022/07/19 19:59:23] ppcls INFO: train with paddle 2.3.0 and device Place(gpu:0)
W0719 19:59:23.641359 28934 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0719 19:59:23.646458 28934 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
[2022/07/19 19:59:28] ppcls INFO: Export succeeded! The inference model exported has been saved in "deploy/models/PPLCNet_x1_0_infer".
执行完该脚本后会在 PaddleClas/deploy/models/ 下生成 PPLCNet_x1_0_infer 文件夹,models 文件夹下应有如下文件结构:
├── PPLCNet_x1_0_infer
│ ├── inference.pdiparams
│ ├── inference.pdiparams.info
│ └── inference.pdmodel
# 将PPLCNet_x1_0_infer文件夹压缩并上传至树莓派
%cd deploy/models
!zip -r PPLCNet_x1_0_infer.zip PPLCNet_x1_0_infer/
# 将 data/data155466/垃圾检测.zip 上传至树莓派
adding: PPLCNet_x1_0_infer/ (stored 0%)
adding: PPLCNet_x1_0_infer/inference.pdmodel (deflated 97%)
adding: PPLCNet_x1_0_infer/inference.pdiparams.info (deflated 82%)
adding: PPLCNet_x1_0_infer/inference.pdiparams (deflated 7%)
3.2 本地编译Paddle-Lite
Paddle Lite 是一个高性能、轻量级、灵活性强且易于扩展的深度学习推理框架,定位于支持包括移动端、嵌入式以及服务器端在内的多硬件平台。
当前 Paddle Lite 不仅在百度内部业务中得到全面应用,也成功支持了众多外部用户和企业的生产任务。
由于PaddlePaddle是不支持ARM架构CPU的,所以我们在树莓派上只可以使用本地源码编译的方式
3.2.1 准备编译环境
- 最新的树莓派32位或者64位操作系统,python>=3.7
- gcc、g++、git、make、wget、unzip、patchelf、libssl-dev、libopencv-dev、pkg-config
- cmake>=3.1
- 下面以最新的树莓派32位操作系统进行演示
# 创建root用户,linux环境下输入密码时看不到已经输入好的密码,因此放心输入即可
sudo passwd root
# 输入密码:xxxx
# 确认密码:xxxx
# 登录到root账户
su
# 输入密码:xxxx
# apt换国内清华源
nano /etc/apt/sources.list
# 注释原文件所有内容,用以下内容取代
deb [arch=armhf] http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ bullseye main non-free contrib rpi
# ctrl+o保存,ctrl+x退出,到这里,Debian的清华源已经更换好了
# Raspi镜像修改
nano /etc/apt/sources.list.d/raspi.list
# 注释源文件内容,用以下内容替代,ctrl+o保存,ctrl+x退出
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bullseye main
# 系统源更新
# 1.更新软件索引清单
apt-get update
# 2.比较索引清单更新依赖关系
apt-get upgrade
# 安装pip,并换国内清华源
apt-get install python3-pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 安装基础软件
apt-get install -y gcc g++ git make wget unzip patchelf libssl-dev libopencv-dev pkg-config
# 本地编译cmake,如果不会科学上网,大概率你会wget不下来。
# 所以建议先在PC机上打开浏览器输入网址https://cmake.org/files/v3.20/cmake-3.20.0-rc4.tar.gz进行下载
# 下载完成后再通过远程连接软件:如finalshell上传至树莓派来进行解压,编译
wget https://cmake.org/files/v3.20/cmake-3.20.0-rc4.tar.gz
tar -zxvf cmake-3.20.0-rc4.tar.gz
cd cmake-3.20.0-rc4
./configure
make
# make编译将会持续大概1小时左右,这期间可以去刷会视频或者打打游戏
make install
# 查看cmake版本以验证安装成功
cmake --version
3.2.2 本地编译
通过修改build_linux.sh脚本文件中的参数,可满足不同场景编译包的构建需求,常用的基础编译参数如下表所示:
参数 | 说明 | 可选范围 | 默认值 |
---|---|---|---|
arch | 目标硬件的架构版本 | armv8 / armv7hf / armv7 | armv8 |
toolchain | C++ 语言的编译器工具链 | gcc | gcc |
with_python | 是否包含 python 编译包,目标应用程序是 python 语言时需配置为 ON | OFF / ON | OFF |
with_cv | 是否将 cv 函数加入编译包中 | OFF / ON | OFF |
with_log | 是否在执行过程打印日志 | OFF / ON | ON |
with_exception | 是否开启 C++ 异常 | OFF / ON | OFF |
with_extra | 是否编译完整算子(见支持算子一节) | OFF / ON | OFF |
with_profile | 是否打开执行耗时分析 | OFF / ON | OFF |
with_precision_profile | 是否打开逐层精度结果分析 | OFF / ON | OFF |
with_opencl | 是否编译支持 OpenCL 的预测库 | OFF / ON | OFF |
# 从Gitee上面下载 paddle-lite 源码
git clone https://gitee.com/paddlepaddle/paddle-lite.git
cd paddle-lite
# 删除 third-party 目录,编译脚本会自动从国内 CDN 下载第三方库文件
rm -rf third-party
# 查看当前操作系统是armv8|armv7|armv7hf中的哪一个
uname -a
# 如果是32位操作系统(armv7/armv7hf),则执行编译脚本:
./lite/tools/build_linux.sh --arch=armv7hf --with_python=ON --with_extra=ON --with_cv=ON
# 如果是64位操作系统(默认为armv8),则执行编译脚本:
./lite/tools/build_linux.sh --with_python=ON --with_extra=ON --with_cv=ON
# 等待编译3小时,这期间可以去刷会视频或者打打游戏
成功后会在 paddle-lite/build.lite.linux.armv7hf.gcc/inference_lite_lib.armlinux.armv7hf/ 生成 Paddle Lite 编译包,文件目录如下:
inference_lite_lib.armlinux.armv7hf
├── cxx C++ 预测库和头文件
│ ├── include C++ 头文件
│ │ ├── paddle_api.h
│ │ ├── paddle_image_preprocess.h
│ │ ├── paddle_lite_factory_helper.h
│ │ ├── paddle_place.h
│ │ ├── paddle_use_kernels.h
│ │ ├── paddle_use_ops.h
│ │ └── paddle_use_passes.h
│ └── lib C++ 预测库
│ ├── libpaddle_api_light_bundled.a C++ 静态库
│ └── libpaddle_light_api_shared.so C++ 动态库
├── demo
│ └── python Python 预测库demo
│
└── python Python 预测库(需要打开with_python选项)
├── install
│ └── dist
│ └── paddlelite-*.whl Python whl包
└── lib
└── lite.so Python 预测库
# 我们的目标文件是paddlelite-*.whl,对其进行安装:
pip install pip install paddlelite-2.11-cp39-cp39m-linux_armv7l.whl
# 最后验证一下paddlelite 是否可以import,没有报错即安装成功
python
import paddlelite
3.3 安装 Paddle-Lite-Demo
paddlelite预测支持c++和python两种方式,下面以python接口预测为例进行讲解
# 安装 Opencv 包
python -m pip install opencv-python
# 不会科学上网的,建议直接在PC机上下载好了,再传到树莓派上解压
git clone https://github.com/PaddlePaddle/Paddle-Lite-Demo
tar -zxvf Paddle-Lite-Demo.tar.gz
# 下载预测库
cd Paddle-Lite-Demo/libs
./download.sh
# 下载OPT 优化后的模型、测试图片、标签文件
cd ../image_classification/assets
./download.sh
# 预测官方demo
cd ../armlinux/shell/python
sh run.sh
# 运行结果如下:
# ================== Speed Report ===================
# model: ./mv1.nb, run avg_time: 1.7610676288604733e-05 ms, min_time: 1.4084100723266602e-05 ms
# ================== Precision Report ===================
# i: 0, index: 285, name: n02124075 Egyptian cat
# , score: 0.4729956388473511
# i: 1, index: 281, name: n02123045 tabby, tabby cat
# , score: 0.43637195229530334
# i: 2, index: 282, name: n02123159 tiger cat
# , score: 0.07664451748132706
# ================== Report End ===================
四、本地推理部署
4.1 opt模型优化
# 将之前上传到树莓派上的inference模型压缩包:PPLCNet_x1_0_infer.zip,在树莓派上解压
cd ../../../../
unzip PPLCNet_x1_0_infer.zip
# 编写opt模型优化脚本
nano opt.py
# 将以下代码copy到opt.py中,ctrl+o保存,ctrl+x退出
paddle_lite_opt --model_dir=./PPLCNet_x1_0_infer \
--valid_targets=arm \
--optimize_out=model
# 在当前目录下会生成一个优化后的model.nb模型,将其copy至Paddle-Lite-Demo/image_classification/assets/models下
cp -i model.nb Paddle-Lite-Demo/image_classification/assets/models/
4.2 更换数据集
# 将之前上传到树莓派上的数据集:垃圾检测.zip,移动到Paddle-Lite-Demo/image_classification/assets/images/并解压
mv 垃圾检测.zip Paddle-Lite-Demo/image_classification/assets/images/
unzip 垃圾检测.zip
# 将标签集labels.txt移动到assets/labels/下
mv labels.txt ../labels/
# 在assets/下创建images_classification.py
cd ..
nano images_classification.py
将以下预测代码copy至images_classification.py中,ctrl+o保存,ctrl+x退出
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
from numpy.lib.shape_base import column_stack
from paddlelite.lite import *
import numpy as np
import cv2
import time
# image_path是图片的路径,单张图片路径为xxx.png/jpg,多张图片路径为xxx.txt
model_dir = "models/model.nb"
image_path = 'images/test_list.txt'
labels_path = 'labels/labels.txt'
input_shape = [1, 3, 224, 224]
thread_num = 4
warmup_num = 10
repeat_num = 100
topk = 3
# 加载标签集labels
def load_labels():
labels = []
fp_r = open(labels_path, 'r')
data = fp_r.readline()[:-1]
while data:
labels.append(data)
data = fp_r.readline()[:-1]
# print(labels)
fp_r.close()
return labels
# (1) 设置配置信息并创建预测器
config = MobileConfig()
config.set_model_from_file(model_dir)
predictor = create_paddle_predictor(config)
labels = load_labels()
# (2) 从图片读入数据 image_data
def RunModel():
# 将任意分辨率的图像数据缩放为224*224
resize_img = cv2.resize(
img, [input_shape[2], input_shape[3]], interpolation=cv2.INTER_AREA)
# 将RGB图像数据转换为HSV
arr = np.array(resize_img)
rows = resize_img.shape[0]
cols = resize_img.shape[1]
means = [0.485, 0.456, 0.406]
scales = [0.229, 0.224, 0.225]
dst_data = []
for i in range(rows):
for j in range(cols):
val = arr[i][j][0] / 255.0
val = (val - means[0]) / scales[0]
dst_data.append(val)
for i in range(rows):
for j in range(cols):
val = arr[i][j][1] / 255.0
val = (val - means[1]) / scales[1]
dst_data.append(val)
for i in range(rows):
for j in range(cols):
val = arr[i][j][2] / 255.0
val = (val - means[2]) / scales[2]
dst_data.append(val)
# print(dst_data)
image_data = np.array(dst_data).reshape(input_shape).astype(np.float32)
# (3) 设置输入数据 input_tensor
input_tensor = predictor.get_input(0)
input_tensor.from_numpy(image_data)
# (4) 执行预测
predictor.run()
# (5) 得到输出数据 output_data
output_tensor = predictor.get_output(0)
output_data = output_tensor.numpy()
# (6) 将评分数组output_data[0]转换为排序后的评分字典res_val,并显示图片分类结果result和评分score
# size为labels中的类别数
size = len(output_data[0])
scores_dict = {}
for i in range(size):
scores_dict[i] = float(output_data[0][i])
res_val = sorted(
scores_dict.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
# print(res_val)
return res_val
# 单张图片分类
if image_path[-3:] != 'txt':
img = cv2.imread(image_path, cv2.COLOR_BGR2RGB)
res_val = RunModel()
# 模型预热,warmup_num = 10
for i in range(0, warmup_num):
predictor.run()
# 输出前三名的预测结果,topk = 3
print("================== 预测报告 ===================")
for i in range(topk):
result = labels[res_val[i][0]]
score = res_val[i][1]
print('类别:' + result + ", 评估分数: " + str(score))
# 评估单张图片的实际预测速度,repeat_num = 100
time_val = []
sum = 0
for i in range(0, repeat_num):
start_time = time.time()
predictor.run()
end_time = time.time()
elapse = (end_time - start_time) / 1000.0
time_val.append(elapse)
sum = sum + elapse
print("================== 速度报告 ===================")
print("模型: " + model_dir + ", 平均运行时长: ", sum / repeat_num, "ms, 最短时长: ",
min(time_val), "ms")
# 多张图片分类,数组img_list用于存放批量图片路径
else:
img_list = []
f = open(image_path)
img = f.readline()[:-3]
while img:
img_list.append(img)
img = f.readline()[:-3]
f.close()
print("================== 预测报告 ===================")
for img_path in img_list:
img = cv2.imread('images/' + img_path,
cv2.COLOR_BGR2RGB)
res_val = RunModel()
result = labels[res_val[0][0]]
score = res_val[0][1]
# 多张图片的分类结果
print('类别:' + result + ", 评估分数: " + str(score))
# 运行预测脚本,对批量图片进行预测
python images_classification.py
运行结果如下:在树莓派4B/4G上CPU的占用率始终稳定在30%左右。
相比demo示例中的mobilenet_v1模型,在树莓派4B/4G上的实际预测速度提高了整整64.7%
# 播放软硬一体的实物视频
import IPython
IPython.display.Video('demo_video.mp4',width=400, height=200)
Your browser does not support the
video
element.
五、项目总结
回顾整个项目,从最开始的数据采集,模型选择,再到模型训练,最终部署成功这一个多月的开发历程。虽然每天都忙到1,2点,累得不行,但这段时间确实过得极其充实。项目的难点主要集中在硬件部署这一环节上,前期在AI Studio上进行模型训练,并导出推理模型只花了3~5天,本以为最多一个星期就能完成硬件部署,谁知道这一卡就是半个多月。
由于是第一次部署,流程不太清楚,所以就跟着官方文档一步一步走,也许是自己太菜,文档没看太懂,然后就遇到了各种各样,花里胡哨的报错信息,更可怕的是网上的解决方案试了个遍,不仅没有把当前的问题解决,反而还衍生出了更多其他的问题,鬼知道我当时的心理阴影面积有多大。
由于本人始终秉持着这样一种信念:只要人还没挂,就能死磕到底!就这样操作系统率先投降撑不住了,崩了10余次,然后我又不厌其烦的给它装了上去,像raspi OS 32位/64位,ubantu OS 64位都已经被装了n次。我可以这样自豪地说:树莓派上部署的坑几乎都被我踩了个遍。总算在经历了这九九八十一难之后,终于杀出了一条成功部署的血路。
以上就是我部署路上的辛酸历程,同时也是驱动着我写下这篇看起来很啰嗦,却又实用无比的树莓派部署文档的源动力。如果这篇文档切切实实地帮助到了你,希望你能将它转发给你正在从事深度学习应用落地的同学或朋友,帮助他们少走弯路。
最后最后,希望大家都能在百度飞桨的带领下,在深度学习应用落地这条路上越走越远,为国产开源事业添砖加瓦,为实现中华民族伟大复兴贡献自己的光和热!
个人介绍
姓名:肖雄
学校:长江大学
学历:大三在读
爱好:喜欢专研技术,对深度学习产业落地的前景十分看好,同时也在学习Spring全家桶,提高自己的软件设计能力。
主要方向:CV,软件开发
个人博客:https://blog.csdn.net/weixin_46227276
此文章为搬运
原项目链接
更多推荐
所有评论(0)