项目背景

城市垃圾分类最早始于 1995 年上海市,2000 年,建设部在北京、南京、杭州、厦门等城市进行垃圾分类试点,将垃圾分类收集分为废纸、塑料、金属以及有毒有害废电池等。经过 20 多年来的发展,垃圾分类模式已经作了数次调整,把垃圾分为:有机垃圾、无机垃圾、有毒有害垃圾;干垃圾、湿垃圾、有害垃圾;废玻璃、可燃垃圾以及有害垃圾;可堆肥垃圾、有害垃圾、其他垃圾等等。

2020年11月,住建部等12部门联合印发了《关于进一步推进生活垃圾分类工作的若干意见》,明确了到2025年,46个重点城市要基本建立配套完善的生活垃圾分类法律法规制度体系,地级以上城市因地制宜基本建立生活垃圾分类投放、收集、运输、处理系统,居民普遍形成生活垃圾分类习惯。足以体现国家对生活垃圾分类工作的高度重视。

“十三五”期间,国家在无害化处理城镇生活垃圾的设施建设期间,投资总额累计达到了2518.4亿元。其中,投资建设无害化处理设施的资金累计达到了1699.3亿元。国家投资金额巨大,市场潜力巨大。

解决方向

本项目主要是从垃圾产生的源头来进行分类处理,也就是对生活中随处可见的普通垃圾桶进行智能化改造升级,从根本上解决人工垃圾分类在人力,物力,财力上的巨大投入,以及对环境造成的巨大污染问题。

核心技术


  • 垃圾分类功能:基于PaddleClas中的PPLCNet预训练模型的二次开发
  • 硬件部署:基于jetson nano在Paddle Inference上进行推理部署

一、PaddleClas环境准备


飞桨图像识别套件PaddleClas是飞桨为工业界和学术界所准备的一个图像识别和图像分类任务的工具集,助力使用者训练出更好的视觉模型和应用落地。

1.1 安装paddleclas

下面我以手动环境配置为例,进行讲解

# 安装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.2.post112)
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: six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (1.16.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: astor in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (0.8.1)
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: paddle-bfloat==0.1.7 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (0.1.7)
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: numpy>=1.13 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (1.19.5)
Requirement already satisfied: protobuf<=3.20.0,>=3.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu) (3.20.0)
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)
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)

[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m A new release of pip available: [0m[31;49m22.1.2[0m[39;49m -> [0m[32;49m22.2.2[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m To update, run: [0m[32;49mpip install --upgrade pip[0m
# 安装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/e0/f2/1d4fd838b82ee314847093e35c6b4addba8713c14280313094e0be233ca3/paddleclas-2.4.3-py3-none-any.whl (326 kB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m326.7/326.7 kB[0m [31m667.6 kB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hRequirement already satisfied: ujson in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (1.35)
Requirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (4.1.1.26)
Requirement already satisfied: scipy>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (1.6.3)
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: pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (8.2.0)
Requirement already satisfied: scikit-learn>=0.21.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (0.24.2)
Collecting faiss-cpu==1.7.1.post2
  Downloading https://pypi.tuna.tsinghua.edu.cn/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 [31m5.5 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hRequirement already satisfied: visualdl>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (2.4.0)
Requirement already satisfied: PyYAML>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (5.1.2)
Requirement already satisfied: easydict in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (1.9)
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (4.27.0)
Requirement already satisfied: prettytable in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddleclas) (0.7.2)
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: numpy>=1.13.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.0->paddleclas) (1.19.5)
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: 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: 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: 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: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->paddleclas) (3.20.0)
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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: faiss-cpu, paddleclas
Successfully installed faiss-cpu-1.7.1.post2 paddleclas-2.4.3

[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m A new release of pip available: [0m[31;49m22.1.2[0m[39;49m -> [0m[32;49m22.2.2[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m To update, run: [0m[32;49mpip install --upgrade pip[0m

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/5b/c9/4e7dbae5054c5bbaed9e7aa7a78e1ceff003d0b0699318e5d6993a0a10c9/prettytable-3.4.1-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)) (1.35)
Collecting ujson
  Downloading https://mirror.baidu.com/pypi/packages/64/f6/d5a0b4fba60451649abac5347945d7b8f7cc6eb2c0dc3e89f83764256513/ujson-5.5.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45 kB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m45.9/45.9 kB[0m [31m88.1 kB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hRequirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (4.1.1.26)
Collecting opencv-python
  Downloading https://mirror.baidu.com/pypi/packages/af/bf/8d189a5c43460f6b5c8eb81ead8732e94b9f73ef8d9abba9e8f5a61a6531/opencv_python-4.6.0.66-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.9 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m60.9/60.9 MB[0m [31m6.4 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 [31m10.2 MB/s[0m eta [36m0:00:00[0m00: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/47/bb/849011636c4da2e44f1253cd927cfb20ada4374d8b3a4e425416e84900cc/tqdm-4.64.1-py2.py3-none-any.whl (78 kB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m78.5/78.5 kB[0m [31m10.4 MB/s[0m eta [36m0:00:00[0m
[?25hRequirement already satisfied: PyYAML>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (5.1.2)
Collecting PyYAML>=5.1
  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 [31m14.6 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.4.0)
Collecting visualdl>=2.2.0
  Downloading https://mirror.baidu.com/pypi/packages/8a/e5/940426714a10c916466764eaea51ab7e10bd03896c625fcc4524a0855175/visualdl-2.4.1-py3-none-any.whl (4.9 MB)
[2K     [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m4.9/4.9 MB[0m [31m10.2 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hRequirement already satisfied: scipy>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (1.6.3)
Collecting scipy>=1.0.0
  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 [31m8.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.5 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)
Requirement already satisfied: faiss-cpu==1.7.1.post2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 11)) (1.7.1.post2)
Requirement already satisfied: easydict in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 12)) (1.9)
Collecting easydict
  Downloading https://mirror.baidu.com/pypi/packages/55/83/0d1ee7962f3ba3fbe9eebe67eb484f6745995c9af045c0ebe5f33564cba0/easydict-1.10.tar.gz (6.4 kB)
  Preparing metadata (setup.py) ... [?25ldone
[?25hRequirement 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: numpy>=1.14.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from opencv-python->-r requirements.txt (line 3)) (1.19.5)
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: 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: 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: multiprocess in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (0.70.11.1)
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.20.0)
Requirement already satisfied: packaging in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 7)) (21.3)
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: 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: 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: 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: 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: 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: 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.3.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.1)
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: 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: 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: 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: dill>=0.3.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from multiprocess->visualdl>=2.2.0->-r requirements.txt (line 7)) (0.3.3)
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: 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: 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)
Building wheels for collected packages: easydict
  Building wheel for easydict (setup.py) ... [?25ldone
[?25h  Created wheel for easydict: filename=easydict-1.10-py3-none-any.whl size=6497 sha256=168b85064fe4c0153afd6f8a6314fe873510c8ad05d0eb49b4deea4f7c6edb23
  Stored in directory: /home/aistudio/.cache/pip/wheels/56/0e/cb/b005b8b1ceaf9d4b024f17e233fa29025c6cf96b5e4411b0c5
Successfully built easydict
Installing collected packages: easydict, ujson, tqdm, scipy, PyYAML, pillow, opencv-python, scikit-learn, prettytable, visualdl
  Attempting uninstall: easydict
    Found existing installation: easydict 1.9
    Uninstalling easydict-1.9:
      Successfully uninstalled easydict-1.9
  Attempting uninstall: ujson
    Found existing installation: ujson 1.35
    Uninstalling ujson-1.35:
      Successfully uninstalled ujson-1.35
  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.4.0
    Uninstalling visualdl-2.4.0:
      Successfully uninstalled visualdl-2.4.0
[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.
python-language-server 0.33.0 requires ujson<=1.35; platform_system != "Windows", but you have ujson 5.5.0 which is incompatible.
python-jsonrpc-server 0.3.4 requires ujson<=1.35; platform_system != "Windows", but you have ujson 5.5.0 which is incompatible.
parl 1.4.1 requires pyzmq==18.1.1, but you have pyzmq 23.2.1 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.1 which is incompatible.[0m[31m
[0mSuccessfully installed PyYAML-6.0 easydict-1.10 opencv-python-4.6.0.66 pillow-9.2.0 prettytable-3.4.1 scikit-learn-1.0.2 scipy-1.7.3 tqdm-4.64.1 ujson-5.5.0 visualdl-2.4.1

[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m A new release of pip available: [0m[31;49m22.1.2[0m[39;49m -> [0m[32;49m22.2.2[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m To update, run: [0m[32;49mpip install --upgrade pip[0m
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!
--------------------------------------------------------------------------
                      Models supported by PaddleClas                      
+-------------------+----------------------------------------------------+
|  IMN Model Series |                     Model Name                     |
+-------------------+----------------------------------------------------+
|      AlexNet      |                      AlexNet                       |
|  CSWinTransformer |             CSWinTransformer_tiny_224              |
|                   |             CSWinTransformer_small_224             |
|                   |             CSWinTransformer_base_224              |
|                   |             CSWinTransformer_base_384              |
|                   |             CSWinTransformer_large_224             |
|                   |             CSWinTransformer_large_384             |
|      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         |
|       LeViT       |    LeViT_128S  LeViT_128  LeViT_192  LeViT_256     |
|                   |                     LeViT_384                      |
|       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             |
|     MobileViT     |      MobileViT_XXS  MobileViT_XS  MobileViT_S      |
|      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                   |
|       PVTV2       | PVT_V2_B0  PVT_V2_B1  PVT_V2_B2  PVT_V2_B2_Linear  |
|                   |          PVT_V2_B3  PVT_V2_B4  PVT_V2_B5           |
|       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     |
|        TNT        |                     TNT_small                      |
|        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/10/01 21:43:23] ppcls INFO: download https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x1_0_infer.tar to /home/aistudio/.paddleclas/inference_model/IMN/PPLCNet_x1_0/PPLCNet_x1_0_infer.tar
100%|█████████████████████████████████████| 12.4M/12.4M [00:00<00:00, 19.9MiB/s]
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:67: 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:68: 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:69: 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:70: 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:71: 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:72: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead.
  'hamming': Image.HAMMING,
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:73: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead.
  'random': (Image.BILINEAR, Image.BICUBIC)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleclas/deploy/python/preprocess.py:73: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead.
  'random': (Image.BILINEAR, Image.BICUBIC)
[2022/10/01 21:43:27] ppcls INFO: 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
[2022/10/01 21:43:27] 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/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'
#     }
# ]
---------------------------------------------------------------------------

ImportError                               Traceback (most recent call last)

/tmp/ipykernel_163/2879969815.py in <module>
----> 1 from paddleclas import PaddleClas
      2 
      3 # result为可迭代对象,因此需要使用 next() 函数或 for 循环对其迭代调用。
      4 # 每次调用将以 batch_size 为单位进行一次预测,并返回预测结果。
      5 clas = PaddleClas(model_name='PPLCNet_x1_0')


~/PaddleClas/paddleclas.py in <module>
     29 import paddle
     30 
---> 31 from .ppcls.arch import backbone
     32 from .ppcls.utils import logger
     33 


ImportError: attempted relative import with no known parent package

二、模型训练、评估和预测

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/ 
cd ../../
/home/aistudio/PaddleClas

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-10-01 22:01:51,311 -----------  Configuration  ----------------------
LAUNCH INFO 2022-10-01 22:01:51,311 devices: None
LAUNCH INFO 2022-10-01 22:01:51,311 elastic_level: -1
LAUNCH INFO 2022-10-01 22:01:51,311 elastic_timeout: 30
LAUNCH INFO 2022-10-01 22:01:51,311 gloo_port: 6767
LAUNCH INFO 2022-10-01 22:01:51,311 host: None
LAUNCH INFO 2022-10-01 22:01:51,311 job_id: default
LAUNCH INFO 2022-10-01 22:01:51,311 legacy: False
LAUNCH INFO 2022-10-01 22:01:51,311 log_dir: log
LAUNCH INFO 2022-10-01 22:01:51,312 log_level: INFO
LAUNCH INFO 2022-10-01 22:01:51,312 master: None
LAUNCH INFO 2022-10-01 22:01:51,312 max_restart: 3
LAUNCH INFO 2022-10-01 22:01:51,312 nnodes: 1
LAUNCH INFO 2022-10-01 22:01:51,312 nproc_per_node: None
LAUNCH INFO 2022-10-01 22:01:51,312 rank: -1
LAUNCH INFO 2022-10-01 22:01:51,312 run_mode: collective
LAUNCH INFO 2022-10-01 22:01:51,312 server_num: None
LAUNCH INFO 2022-10-01 22:01:51,312 servers: 
LAUNCH INFO 2022-10-01 22:01:51,312 trainer_num: None
LAUNCH INFO 2022-10-01 22:01:51,312 trainers: 
LAUNCH INFO 2022-10-01 22:01:51,312 training_script: tools/train.py
LAUNCH INFO 2022-10-01 22:01:51,312 training_script_args: ['-c', 'ppcls/configs/ImageNet/PPLCNet/PPLCNet_x1_0.yaml']
LAUNCH INFO 2022-10-01 22:01:51,312 with_gloo: 0
LAUNCH INFO 2022-10-01 22:01:51,312 --------------------------------------------------
LAUNCH WARNING 2022-10-01 22:01:51,312 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-10-01 22:01:51,313 launch.py:519] Not found distinct arguments and compiled with cuda or xpu or npu or mlu. Default use collective mode
WARNING 2022-10-01 22:01:51,313 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-10-01 22:01:51,315 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:40367               |
    |                     PADDLE_TRAINERS_NUM                        1                      |
    |                PADDLE_TRAINER_ENDPOINTS                 127.0.0.1:40367               |
    |                     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-10-01 22:01:51,315 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:40367               |
    |                     PADDLE_TRAINERS_NUM                        1                      |
    |                PADDLE_TRAINER_ENDPOINTS                 127.0.0.1:40367               |
    |                     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-10-01 22:01:51,315 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-10-01 22:01:51,315 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:3253 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/10/01 22:01:53] ppcls INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2022/10/01 22:01:53] ppcls INFO: Arch : 
[2022/10/01 22:01:53] ppcls INFO:     class_num : 10
[2022/10/01 22:01:53] ppcls INFO:     name : PPLCNet_x1_0
[2022/10/01 22:01:53] ppcls INFO: DataLoader : 
[2022/10/01 22:01:53] ppcls INFO:     Eval : 
[2022/10/01 22:01:53] ppcls INFO:         dataset : 
[2022/10/01 22:01:53] ppcls INFO:             cls_label_path : ./dataset/val_list.txt
[2022/10/01 22:01:53] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:01:53] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:01:53] ppcls INFO:             transform_ops : 
[2022/10/01 22:01:53] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:01:53] ppcls INFO:                     channel_first : False
[2022/10/01 22:01:53] ppcls INFO:                     to_rgb : True
[2022/10/01 22:01:53] ppcls INFO:                 ResizeImage : 
[2022/10/01 22:01:53] ppcls INFO:                     resize_short : 256
[2022/10/01 22:01:53] ppcls INFO:                 CropImage : 
[2022/10/01 22:01:53] ppcls INFO:                     size : 224
[2022/10/01 22:01:53] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:01:53] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:01:53] ppcls INFO:                     order : 
[2022/10/01 22:01:53] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:01:53] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:01:53] ppcls INFO:         loader : 
[2022/10/01 22:01:53] ppcls INFO:             num_workers : 4
[2022/10/01 22:01:53] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:01:53] ppcls INFO:         sampler : 
[2022/10/01 22:01:53] ppcls INFO:             batch_size : 16
[2022/10/01 22:01:53] ppcls INFO:             drop_last : False
[2022/10/01 22:01:53] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:01:53] ppcls INFO:             shuffle : False
[2022/10/01 22:01:53] ppcls INFO:     Train : 
[2022/10/01 22:01:53] ppcls INFO:         dataset : 
[2022/10/01 22:01:53] ppcls INFO:             cls_label_path : ./dataset/train_list.txt
[2022/10/01 22:01:53] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:01:53] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:01:53] ppcls INFO:             transform_ops : 
[2022/10/01 22:01:53] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:01:53] ppcls INFO:                     channel_first : False
[2022/10/01 22:01:53] ppcls INFO:                     to_rgb : True
[2022/10/01 22:01:53] ppcls INFO:                 RandCropImage : 
[2022/10/01 22:01:53] ppcls INFO:                     size : 224
[2022/10/01 22:01:53] ppcls INFO:                 RandFlipImage : 
[2022/10/01 22:01:53] ppcls INFO:                     flip_code : 1
[2022/10/01 22:01:53] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:01:53] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:01:53] ppcls INFO:                     order : 
[2022/10/01 22:01:53] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:01:53] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:01:53] ppcls INFO:         loader : 
[2022/10/01 22:01:53] ppcls INFO:             num_workers : 4
[2022/10/01 22:01:53] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:01:53] ppcls INFO:         sampler : 
[2022/10/01 22:01:53] ppcls INFO:             batch_size : 16
[2022/10/01 22:01:53] ppcls INFO:             drop_last : False
[2022/10/01 22:01:53] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:01:53] ppcls INFO:             shuffle : True
[2022/10/01 22:01:53] ppcls INFO: Global : 
[2022/10/01 22:01:53] ppcls INFO:     checkpoints : None
[2022/10/01 22:01:53] ppcls INFO:     device : gpu
[2022/10/01 22:01:53] ppcls INFO:     epochs : 10
[2022/10/01 22:01:53] ppcls INFO:     eval_during_train : True
[2022/10/01 22:01:53] ppcls INFO:     eval_interval : 1
[2022/10/01 22:01:53] ppcls INFO:     image_shape : [3, 224, 224]
[2022/10/01 22:01:53] ppcls INFO:     output_dir : ./output/
[2022/10/01 22:01:53] ppcls INFO:     pretrained_model : https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_pretrained.pdparams
[2022/10/01 22:01:53] ppcls INFO:     print_batch_step : 10
[2022/10/01 22:01:53] ppcls INFO:     save_inference_dir : ./inference
[2022/10/01 22:01:53] ppcls INFO:     save_interval : 1
[2022/10/01 22:01:53] ppcls INFO:     use_visualdl : False
[2022/10/01 22:01:53] ppcls INFO: Infer : 
[2022/10/01 22:01:53] ppcls INFO:     PostProcess : 
[2022/10/01 22:01:53] ppcls INFO:         class_id_map_file : ./dataset/labels.txt
[2022/10/01 22:01:53] ppcls INFO:         name : Topk
[2022/10/01 22:01:53] ppcls INFO:         topk : 5
[2022/10/01 22:01:53] ppcls INFO:     batch_size : 1
[2022/10/01 22:01:53] ppcls INFO:     infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/10/01 22:01:53] ppcls INFO:     transforms : 
[2022/10/01 22:01:53] ppcls INFO:         DecodeImage : 
[2022/10/01 22:01:53] ppcls INFO:             channel_first : False
[2022/10/01 22:01:53] ppcls INFO:             to_rgb : True
[2022/10/01 22:01:53] ppcls INFO:         ResizeImage : 
[2022/10/01 22:01:53] ppcls INFO:             resize_short : 256
[2022/10/01 22:01:53] ppcls INFO:         CropImage : 
[2022/10/01 22:01:53] ppcls INFO:             size : 224
[2022/10/01 22:01:53] ppcls INFO:         NormalizeImage : 
[2022/10/01 22:01:53] ppcls INFO:             mean : [0.485, 0.456, 0.406]
[2022/10/01 22:01:53] ppcls INFO:             order : 
[2022/10/01 22:01:53] ppcls INFO:             scale : 1.0/255.0
[2022/10/01 22:01:53] ppcls INFO:             std : [0.229, 0.224, 0.225]
[2022/10/01 22:01:53] ppcls INFO:         ToCHWImage : None
[2022/10/01 22:01:53] ppcls INFO: Loss : 
[2022/10/01 22:01:53] ppcls INFO:     Eval : 
[2022/10/01 22:01:53] ppcls INFO:         CELoss : 
[2022/10/01 22:01:53] ppcls INFO:             weight : 1.0
[2022/10/01 22:01:53] ppcls INFO:     Train : 
[2022/10/01 22:01:53] ppcls INFO:         CELoss : 
[2022/10/01 22:01:53] ppcls INFO:             epsilon : 0.1
[2022/10/01 22:01:53] ppcls INFO:             weight : 1.0
[2022/10/01 22:01:53] ppcls INFO: Metric : 
[2022/10/01 22:01:53] ppcls INFO:     Eval : 
[2022/10/01 22:01:53] ppcls INFO:         TopkAcc : 
[2022/10/01 22:01:53] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:01:53] ppcls INFO:     Train : 
[2022/10/01 22:01:53] ppcls INFO:         TopkAcc : 
[2022/10/01 22:01:53] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:01:53] ppcls INFO: Optimizer : 
[2022/10/01 22:01:53] ppcls INFO:     lr : 
[2022/10/01 22:01:53] ppcls INFO:         learning_rate : 0.00625
[2022/10/01 22:01:53] ppcls INFO:         name : Cosine
[2022/10/01 22:01:53] ppcls INFO:         warmup_epoch : 5
[2022/10/01 22:01:53] ppcls INFO:     momentum : 0.9
[2022/10/01 22:01:53] ppcls INFO:     name : Momentum
[2022/10/01 22:01:53] ppcls INFO:     regularizer : 
[2022/10/01 22:01:53] ppcls INFO:         coeff : 3e-05
[2022/10/01 22:01:53] ppcls INFO:         name : L2
[2022/10/01 22:01:53] ppcls INFO: profiler_options : None
[2022/10/01 22:01:53] ppcls INFO: train with paddle 2.3.2 and device Place(gpu:0)
W1001 22:01:53.640229  3253 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2
W1001 22:01:53.644788  3253 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.
[2022/10/01 22:01:54] ppcls INFO: unique_endpoints {'127.0.0.1:40367'}
[2022/10/01 22:01:54] ppcls INFO: Downloading PPLCNet_x1_0_pretrained.pdparams from https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x1_0_pretrained.pdparams

  0%|          | 0/11590 [00:00<?, ?it/s]
  6%|▋         | 741/11590 [00:00<00:01, 7407.06it/s]
 20%|██        | 2371/11590 [00:00<00:00, 12636.15it/s]
 41%|████      | 4707/11590 [00:00<00:00, 17365.63it/s]
 60%|██████    | 7001/11590 [00:00<00:00, 19553.18it/s]
 81%|████████  | 9363/11590 [00:00<00:00, 21014.18it/s]
100%|██████████| 11590/11590 [00:00<00:00, 19935.15it/s]
[2022/10/01 22:01:55] 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/10/01 22:02:01] ppcls INFO: [Train][Epoch 1/10][Iter: 0/44]lr(LinearWarmup): 0.00002841, top1: 0.25000, top5: 0.68750, CELoss: 2.34709, loss: 2.34709, batch_cost: 5.95726s, reader_cost: 3.56910, ips: 2.68580 samples/s, eta: 0:43:41
[2022/10/01 22:02:06] ppcls INFO: [Train][Epoch 1/10][Iter: 10/44]lr(LinearWarmup): 0.00031250, top1: 0.07955, top5: 0.56818, CELoss: 2.40199, loss: 2.40199, batch_cost: 0.55488s, reader_cost: 0.50854, ips: 28.83528 samples/s, eta: 0:03:58
[2022/10/01 22:02:16] ppcls INFO: [Train][Epoch 1/10][Iter: 20/44]lr(LinearWarmup): 0.00059659, top1: 0.14583, top5: 0.61607, CELoss: 2.32137, loss: 2.32137, batch_cost: 0.82079s, reader_cost: 0.77629, ips: 19.49334 samples/s, eta: 0:05:44
[2022/10/01 22:02:22] ppcls INFO: [Train][Epoch 1/10][Iter: 30/44]lr(LinearWarmup): 0.00088068, top1: 0.21371, top5: 0.67742, CELoss: 2.21557, loss: 2.21557, batch_cost: 0.75172s, reader_cost: 0.70701, ips: 21.28448 samples/s, eta: 0:05:08
[2022/10/01 22:02:31] ppcls INFO: [Train][Epoch 1/10][Iter: 40/44]lr(LinearWarmup): 0.00116477, top1: 0.32317, top5: 0.73018, CELoss: 2.05487, loss: 2.05487, batch_cost: 0.79190s, reader_cost: 0.74833, ips: 20.20445 samples/s, eta: 0:05:16
[2022/10/01 22:02:31] ppcls INFO: [Train][Epoch 1/10][Avg]top1: 0.35000, top5: 0.74571, CELoss: 2.00860, loss: 2.00860
[2022/10/01 22:02:35] ppcls INFO: [Eval][Epoch 1][Iter: 0/13]CELoss: 0.83211, loss: 0.83211, top1: 1.00000, top5: 1.00000, batch_cost: 4.30568s, reader_cost: 4.24805, ips: 3.71602 images/sec
[2022/10/01 22:02:44] ppcls INFO: [Eval][Epoch 1][Iter: 10/13]CELoss: 0.65044, loss: 0.65044, top1: 0.97159, top5: 1.00000, batch_cost: 0.68250s, reader_cost: 0.66400, ips: 23.44331 images/sec
[2022/10/01 22:02:46] ppcls INFO: [Eval][Epoch 1][Avg]CELoss: 0.64428, loss: 0.64428, top1: 0.97000, top5: 1.00000
[2022/10/01 22:02:46] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/best_model
[2022/10/01 22:02:46] ppcls INFO: [Eval][Epoch 1][best metric: 0.9699999690055847]
[2022/10/01 22:02:46] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_1
[2022/10/01 22:02:46] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:02:49] ppcls INFO: [Train][Epoch 2/10][Iter: 0/44]lr(LinearWarmup): 0.00127841, top1: 0.75000, top5: 1.00000, CELoss: 1.41169, loss: 1.41169, batch_cost: 0.80519s, reader_cost: 0.76208, ips: 19.87120 samples/s, eta: 0:05:18
[2022/10/01 22:02:56] ppcls INFO: [Train][Epoch 2/10][Iter: 10/44]lr(LinearWarmup): 0.00156250, top1: 0.89205, top5: 0.98864, CELoss: 1.05984, loss: 1.05984, batch_cost: 0.56854s, reader_cost: 0.51898, ips: 28.14242 samples/s, eta: 0:03:39
[2022/10/01 22:03:05] ppcls INFO: [Train][Epoch 2/10][Iter: 20/44]lr(LinearWarmup): 0.00184659, top1: 0.89583, top5: 0.98214, CELoss: 0.96530, loss: 0.96530, batch_cost: 0.77672s, reader_cost: 0.73305, ips: 20.59951 samples/s, eta: 0:04:52
[2022/10/01 22:03:12] ppcls INFO: [Train][Epoch 2/10][Iter: 30/44]lr(LinearWarmup): 0.00213068, top1: 0.89516, top5: 0.98387, CELoss: 0.91499, loss: 0.91499, batch_cost: 0.74415s, reader_cost: 0.70249, ips: 21.50095 samples/s, eta: 0:04:32
[2022/10/01 22:03:21] ppcls INFO: [Train][Epoch 2/10][Iter: 40/44]lr(LinearWarmup): 0.00241477, top1: 0.90701, top5: 0.98780, CELoss: 0.87282, loss: 0.87282, batch_cost: 0.78614s, reader_cost: 0.74299, ips: 20.35264 samples/s, eta: 0:04:39
[2022/10/01 22:03:22] ppcls INFO: [Train][Epoch 2/10][Avg]top1: 0.90571, top5: 0.98857, CELoss: 0.86454, loss: 0.86454
[2022/10/01 22:03:27] ppcls INFO: [Eval][Epoch 2][Iter: 0/13]CELoss: 0.09245, loss: 0.09245, top1: 1.00000, top5: 1.00000, batch_cost: 4.74504s, reader_cost: 4.71346, ips: 3.37194 images/sec
[2022/10/01 22:03:35] ppcls INFO: [Eval][Epoch 2][Iter: 10/13]CELoss: 0.05753, loss: 0.05753, top1: 0.99432, top5: 1.00000, batch_cost: 0.67321s, reader_cost: 0.65198, ips: 23.76690 images/sec
[2022/10/01 22:03:37] ppcls INFO: [Eval][Epoch 2][Avg]CELoss: 0.06366, loss: 0.06366, top1: 0.99500, top5: 1.00000
[2022/10/01 22:03:37] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/best_model
[2022/10/01 22:03:37] ppcls INFO: [Eval][Epoch 2][best metric: 0.9950000047683716]
[2022/10/01 22:03:37] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_2
[2022/10/01 22:03:37] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:03:41] ppcls INFO: [Train][Epoch 3/10][Iter: 0/44]lr(LinearWarmup): 0.00252841, top1: 1.00000, top5: 1.00000, CELoss: 0.73471, loss: 0.73471, batch_cost: 0.83339s, reader_cost: 0.79037, ips: 19.19877 samples/s, eta: 0:04:53
[2022/10/01 22:03:48] ppcls INFO: [Train][Epoch 3/10][Iter: 10/44]lr(LinearWarmup): 0.00281250, top1: 0.93182, top5: 1.00000, CELoss: 0.73933, loss: 0.73933, batch_cost: 0.58292s, reader_cost: 0.54250, ips: 27.44790 samples/s, eta: 0:03:19
[2022/10/01 22:03:57] ppcls INFO: [Train][Epoch 3/10][Iter: 20/44]lr(LinearWarmup): 0.00309659, top1: 0.93750, top5: 1.00000, CELoss: 0.72359, loss: 0.72359, batch_cost: 0.79006s, reader_cost: 0.74480, ips: 20.25152 samples/s, eta: 0:04:22
[2022/10/01 22:04:04] ppcls INFO: [Train][Epoch 3/10][Iter: 30/44]lr(LinearWarmup): 0.00338068, top1: 0.93347, top5: 0.99798, CELoss: 0.73336, loss: 0.73336, batch_cost: 0.74440s, reader_cost: 0.69925, ips: 21.49390 samples/s, eta: 0:03:59
[2022/10/01 22:04:13] ppcls INFO: [Train][Epoch 3/10][Iter: 40/44]lr(LinearWarmup): 0.00366477, top1: 0.94055, top5: 0.99848, CELoss: 0.72531, loss: 0.72531, batch_cost: 0.78380s, reader_cost: 0.73980, ips: 20.41336 samples/s, eta: 0:04:04
[2022/10/01 22:04:13] ppcls INFO: [Train][Epoch 3/10][Avg]top1: 0.94286, top5: 0.99857, CELoss: 0.71965, loss: 0.71965
[2022/10/01 22:04:18] ppcls INFO: [Eval][Epoch 3][Iter: 0/13]CELoss: 0.16722, loss: 0.16722, top1: 1.00000, top5: 1.00000, batch_cost: 4.75166s, reader_cost: 4.71514, ips: 3.36725 images/sec
[2022/10/01 22:04:26] ppcls INFO: [Eval][Epoch 3][Iter: 10/13]CELoss: 0.08227, loss: 0.08227, top1: 0.99432, top5: 1.00000, batch_cost: 0.66559s, reader_cost: 0.64234, ips: 24.03882 images/sec
[2022/10/01 22:04:28] ppcls INFO: [Eval][Epoch 3][Avg]CELoss: 0.09223, loss: 0.09223, top1: 0.99500, top5: 1.00000
[2022/10/01 22:04:28] ppcls INFO: [Eval][Epoch 3][best metric: 0.9950000047683716]
[2022/10/01 22:04:28] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_3
[2022/10/01 22:04:28] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:04:32] ppcls INFO: [Train][Epoch 4/10][Iter: 0/44]lr(LinearWarmup): 0.00377841, top1: 1.00000, top5: 1.00000, CELoss: 0.58134, loss: 0.58134, batch_cost: 0.80190s, reader_cost: 0.75820, ips: 19.95249 samples/s, eta: 0:04:06
[2022/10/01 22:04:38] ppcls INFO: [Train][Epoch 4/10][Iter: 10/44]lr(LinearWarmup): 0.00406250, top1: 0.93182, top5: 0.98864, CELoss: 0.72225, loss: 0.72225, batch_cost: 0.57385s, reader_cost: 0.52944, ips: 27.88174 samples/s, eta: 0:02:51
[2022/10/01 22:04:48] ppcls INFO: [Train][Epoch 4/10][Iter: 20/44]lr(LinearWarmup): 0.00434659, top1: 0.93155, top5: 0.99107, CELoss: 0.72102, loss: 0.72102, batch_cost: 0.79135s, reader_cost: 0.74740, ips: 20.21858 samples/s, eta: 0:03:47
[2022/10/01 22:04:55] ppcls INFO: [Train][Epoch 4/10][Iter: 30/44]lr(LinearWarmup): 0.00463068, top1: 0.94556, top5: 0.99194, CELoss: 0.69756, loss: 0.69756, batch_cost: 0.75619s, reader_cost: 0.71288, ips: 21.15868 samples/s, eta: 0:03:30
[2022/10/01 22:05:03] ppcls INFO: [Train][Epoch 4/10][Iter: 40/44]lr(LinearWarmup): 0.00491477, top1: 0.94817, top5: 0.99390, CELoss: 0.69424, loss: 0.69424, batch_cost: 0.79428s, reader_cost: 0.75113, ips: 20.14399 samples/s, eta: 0:03:32
[2022/10/01 22:05:04] ppcls INFO: [Train][Epoch 4/10][Avg]top1: 0.95143, top5: 0.99429, CELoss: 0.68949, loss: 0.68949
[2022/10/01 22:05:09] ppcls INFO: [Eval][Epoch 4][Iter: 0/13]CELoss: 0.19519, loss: 0.19519, top1: 1.00000, top5: 1.00000, batch_cost: 4.37575s, reader_cost: 4.34352, ips: 3.65651 images/sec
[2022/10/01 22:05:17] ppcls INFO: [Eval][Epoch 4][Iter: 10/13]CELoss: 0.14239, loss: 0.14239, top1: 1.00000, top5: 1.00000, batch_cost: 0.67236s, reader_cost: 0.65052, ips: 23.79692 images/sec
[2022/10/01 22:05:19] ppcls INFO: [Eval][Epoch 4][Avg]CELoss: 0.11543, loss: 0.11543, top1: 1.00000, top5: 1.00000
[2022/10/01 22:05:19] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/best_model
[2022/10/01 22:05:19] ppcls INFO: [Eval][Epoch 4][best metric: 1.0]
[2022/10/01 22:05:19] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_4
[2022/10/01 22:05:19] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:05:23] ppcls INFO: [Train][Epoch 5/10][Iter: 0/44]lr(LinearWarmup): 0.00502841, top1: 0.93750, top5: 1.00000, CELoss: 0.66409, loss: 0.66409, batch_cost: 0.82402s, reader_cost: 0.78032, ips: 19.41695 samples/s, eta: 0:03:37
[2022/10/01 22:05:29] ppcls INFO: [Train][Epoch 5/10][Iter: 10/44]lr(LinearWarmup): 0.00531250, top1: 0.97159, top5: 0.99432, CELoss: 0.66016, loss: 0.66016, batch_cost: 0.57426s, reader_cost: 0.53361, ips: 27.86187 samples/s, eta: 0:02:25
[2022/10/01 22:05:39] ppcls INFO: [Train][Epoch 5/10][Iter: 20/44]lr(LinearWarmup): 0.00559659, top1: 0.97917, top5: 0.99702, CELoss: 0.64180, loss: 0.64180, batch_cost: 0.82789s, reader_cost: 0.78265, ips: 19.32624 samples/s, eta: 0:03:22
[2022/10/01 22:05:46] ppcls INFO: [Train][Epoch 5/10][Iter: 30/44]lr(LinearWarmup): 0.00588068, top1: 0.97581, top5: 0.99597, CELoss: 0.64692, loss: 0.64692, batch_cost: 0.76480s, reader_cost: 0.72069, ips: 20.92061 samples/s, eta: 0:02:58
[2022/10/01 22:05:54] ppcls INFO: [Train][Epoch 5/10][Iter: 40/44]lr(LinearWarmup): 0.00616477, top1: 0.96799, top5: 0.99390, CELoss: 0.66034, loss: 0.66034, batch_cost: 0.79323s, reader_cost: 0.74822, ips: 20.17076 samples/s, eta: 0:02:57
[2022/10/01 22:05:55] ppcls INFO: [Train][Epoch 5/10][Avg]top1: 0.96714, top5: 0.99429, CELoss: 0.66031, loss: 0.66031
[2022/10/01 22:05:59] ppcls INFO: [Eval][Epoch 5][Iter: 0/13]CELoss: 0.22768, loss: 0.22768, top1: 1.00000, top5: 1.00000, batch_cost: 4.34034s, reader_cost: 4.30585, ips: 3.68634 images/sec
[2022/10/01 22:06:07] ppcls INFO: [Eval][Epoch 5][Iter: 10/13]CELoss: 0.12387, loss: 0.12387, top1: 1.00000, top5: 1.00000, batch_cost: 0.71629s, reader_cost: 0.69061, ips: 22.33729 images/sec
[2022/10/01 22:06:09] ppcls INFO: [Eval][Epoch 5][Avg]CELoss: 0.10660, loss: 0.10660, top1: 1.00000, top5: 1.00000
[2022/10/01 22:06:09] ppcls INFO: [Eval][Epoch 5][best metric: 1.0]
[2022/10/01 22:06:09] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_5
[2022/10/01 22:06:09] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:06:13] ppcls INFO: [Train][Epoch 6/10][Iter: 0/44]lr(LinearWarmup): 0.00624968, top1: 1.00000, top5: 1.00000, CELoss: 0.58649, loss: 0.58649, batch_cost: 0.81164s, reader_cost: 0.76715, ips: 19.71316 samples/s, eta: 0:02:58
[2022/10/01 22:06:20] ppcls INFO: [Train][Epoch 6/10][Iter: 10/44]lr(LinearWarmup): 0.00621153, top1: 0.94886, top5: 0.98864, CELoss: 0.68963, loss: 0.68963, batch_cost: 0.55702s, reader_cost: 0.51285, ips: 28.72404 samples/s, eta: 0:01:56
[2022/10/01 22:06:29] ppcls INFO: [Train][Epoch 6/10][Iter: 20/44]lr(LinearWarmup): 0.00611054, top1: 0.95833, top5: 0.99107, CELoss: 0.66731, loss: 0.66731, batch_cost: 0.80279s, reader_cost: 0.76030, ips: 19.93041 samples/s, eta: 0:02:40
[2022/10/01 22:06:36] ppcls INFO: [Train][Epoch 6/10][Iter: 30/44]lr(LinearWarmup): 0.00594877, top1: 0.96371, top5: 0.99194, CELoss: 0.65782, loss: 0.65782, batch_cost: 0.74204s, reader_cost: 0.69794, ips: 21.56216 samples/s, eta: 0:02:20
[2022/10/01 22:06:45] ppcls INFO: [Train][Epoch 6/10][Iter: 40/44]lr(LinearWarmup): 0.00572952, top1: 0.97104, top5: 0.99390, CELoss: 0.64281, loss: 0.64281, batch_cost: 0.80138s, reader_cost: 0.75834, ips: 19.96558 samples/s, eta: 0:02:24
[2022/10/01 22:06:46] ppcls INFO: [Train][Epoch 6/10][Avg]top1: 0.97286, top5: 0.99429, CELoss: 0.63840, loss: 0.63840
[2022/10/01 22:06:50] ppcls INFO: [Eval][Epoch 6][Iter: 0/13]CELoss: 0.12986, loss: 0.12986, top1: 1.00000, top5: 1.00000, batch_cost: 4.70918s, reader_cost: 4.67550, ips: 3.39762 images/sec
[2022/10/01 22:06:58] ppcls INFO: [Eval][Epoch 6][Iter: 10/13]CELoss: 0.09480, loss: 0.09480, top1: 1.00000, top5: 1.00000, batch_cost: 0.70019s, reader_cost: 0.67744, ips: 22.85107 images/sec
[2022/10/01 22:07:00] ppcls INFO: [Eval][Epoch 6][Avg]CELoss: 0.09140, loss: 0.09140, top1: 1.00000, top5: 1.00000
[2022/10/01 22:07:00] ppcls INFO: [Eval][Epoch 6][best metric: 1.0]
[2022/10/01 22:07:00] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_6
[2022/10/01 22:07:00] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:07:04] ppcls INFO: [Train][Epoch 7/10][Iter: 0/44]lr(LinearWarmup): 0.00562669, top1: 1.00000, top5: 1.00000, CELoss: 0.58749, loss: 0.58749, batch_cost: 0.81567s, reader_cost: 0.77303, ips: 19.61581 samples/s, eta: 0:02:23
[2022/10/01 22:07:12] ppcls INFO: [Train][Epoch 7/10][Iter: 10/44]lr(LinearWarmup): 0.00533471, top1: 0.97727, top5: 1.00000, CELoss: 0.62289, loss: 0.62289, batch_cost: 0.65222s, reader_cost: 0.59129, ips: 24.53159 samples/s, eta: 0:01:48
[2022/10/01 22:07:22] ppcls INFO: [Train][Epoch 7/10][Iter: 20/44]lr(LinearWarmup): 0.00499774, top1: 0.97917, top5: 1.00000, CELoss: 0.63008, loss: 0.63008, batch_cost: 0.87056s, reader_cost: 0.81645, ips: 18.37904 samples/s, eta: 0:02:15
[2022/10/01 22:07:29] ppcls INFO: [Train][Epoch 7/10][Iter: 30/44]lr(LinearWarmup): 0.00462265, top1: 0.98387, top5: 1.00000, CELoss: 0.61835, loss: 0.61835, batch_cost: 0.80793s, reader_cost: 0.75414, ips: 19.80375 samples/s, eta: 0:01:57
[2022/10/01 22:07:38] ppcls INFO: [Train][Epoch 7/10][Iter: 40/44]lr(LinearWarmup): 0.00421708, top1: 0.98171, top5: 1.00000, CELoss: 0.61945, loss: 0.61945, batch_cost: 0.84141s, reader_cost: 0.79168, ips: 19.01579 samples/s, eta: 0:01:54
[2022/10/01 22:07:38] ppcls INFO: [Train][Epoch 7/10][Avg]top1: 0.98143, top5: 1.00000, CELoss: 0.62678, loss: 0.62678
[2022/10/01 22:07:43] ppcls INFO: [Eval][Epoch 7][Iter: 0/13]CELoss: 0.11798, loss: 0.11798, top1: 1.00000, top5: 1.00000, batch_cost: 4.78805s, reader_cost: 4.75264, ips: 3.34166 images/sec
[2022/10/01 22:07:52] ppcls INFO: [Eval][Epoch 7][Iter: 10/13]CELoss: 0.08314, loss: 0.08314, top1: 1.00000, top5: 1.00000, batch_cost: 0.74363s, reader_cost: 0.71971, ips: 21.51594 images/sec
[2022/10/01 22:07:54] ppcls INFO: [Eval][Epoch 7][Avg]CELoss: 0.08739, loss: 0.08739, top1: 1.00000, top5: 1.00000
[2022/10/01 22:07:54] ppcls INFO: [Eval][Epoch 7][best metric: 1.0]
[2022/10/01 22:07:54] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_7
[2022/10/01 22:07:54] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:07:57] ppcls INFO: [Train][Epoch 8/10][Iter: 0/44]lr(LinearWarmup): 0.00404814, top1: 1.00000, top5: 1.00000, CELoss: 0.55295, loss: 0.55295, batch_cost: 0.85385s, reader_cost: 0.80496, ips: 18.73870 samples/s, eta: 0:01:52
[2022/10/01 22:08:04] ppcls INFO: [Train][Epoch 8/10][Iter: 10/44]lr(LinearWarmup): 0.00361386, top1: 0.99432, top5: 1.00000, CELoss: 0.58948, loss: 0.58948, batch_cost: 0.57030s, reader_cost: 0.52810, ips: 28.05548 samples/s, eta: 0:01:09
[2022/10/01 22:08:14] ppcls INFO: [Train][Epoch 8/10][Iter: 20/44]lr(LinearWarmup): 0.00316962, top1: 0.98512, top5: 1.00000, CELoss: 0.61181, loss: 0.61181, batch_cost: 0.85235s, reader_cost: 0.80137, ips: 18.77160 samples/s, eta: 0:01:35
[2022/10/01 22:08:20] ppcls INFO: [Train][Epoch 8/10][Iter: 30/44]lr(LinearWarmup): 0.00272448, top1: 0.98185, top5: 1.00000, CELoss: 0.61127, loss: 0.61127, batch_cost: 0.75266s, reader_cost: 0.70443, ips: 21.25786 samples/s, eta: 0:01:16
[2022/10/01 22:08:30] ppcls INFO: [Train][Epoch 8/10][Iter: 40/44]lr(LinearWarmup): 0.00228749, top1: 0.98171, top5: 1.00000, CELoss: 0.61105, loss: 0.61105, batch_cost: 0.80893s, reader_cost: 0.76032, ips: 19.77910 samples/s, eta: 0:01:14
[2022/10/01 22:08:30] ppcls INFO: [Train][Epoch 8/10][Avg]top1: 0.98286, top5: 1.00000, CELoss: 0.60748, loss: 0.60748
[2022/10/01 22:08:34] ppcls INFO: [Eval][Epoch 8][Iter: 0/13]CELoss: 0.12163, loss: 0.12163, top1: 1.00000, top5: 1.00000, batch_cost: 4.45723s, reader_cost: 4.40558, ips: 3.58968 images/sec
[2022/10/01 22:08:42] ppcls INFO: [Eval][Epoch 8][Iter: 10/13]CELoss: 0.08177, loss: 0.08177, top1: 1.00000, top5: 1.00000, batch_cost: 0.65953s, reader_cost: 0.63533, ips: 24.25960 images/sec
[2022/10/01 22:08:44] ppcls INFO: [Eval][Epoch 8][Avg]CELoss: 0.09293, loss: 0.09293, top1: 1.00000, top5: 1.00000
[2022/10/01 22:08:44] ppcls INFO: [Eval][Epoch 8][best metric: 1.0]
[2022/10/01 22:08:44] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_8
[2022/10/01 22:08:45] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:08:48] ppcls INFO: [Train][Epoch 9/10][Iter: 0/44]lr(LinearWarmup): 0.00211698, top1: 1.00000, top5: 1.00000, CELoss: 0.59934, loss: 0.59934, batch_cost: 0.82000s, reader_cost: 0.77237, ips: 19.51230 samples/s, eta: 0:01:12
[2022/10/01 22:08:55] ppcls INFO: [Train][Epoch 9/10][Iter: 10/44]lr(LinearWarmup): 0.00170628, top1: 0.98295, top5: 1.00000, CELoss: 0.60856, loss: 0.60856, batch_cost: 0.62814s, reader_cost: 0.58438, ips: 25.47211 samples/s, eta: 0:00:48
[2022/10/01 22:09:04] ppcls INFO: [Train][Epoch 9/10][Iter: 20/44]lr(LinearWarmup): 0.00132446, top1: 0.97321, top5: 0.99702, CELoss: 0.63255, loss: 0.63255, batch_cost: 0.77690s, reader_cost: 0.73320, ips: 20.59468 samples/s, eta: 0:00:52
[2022/10/01 22:09:11] ppcls INFO: [Train][Epoch 9/10][Iter: 30/44]lr(LinearWarmup): 0.00097929, top1: 0.97782, top5: 0.99798, CELoss: 0.61867, loss: 0.61867, batch_cost: 0.75388s, reader_cost: 0.71014, ips: 21.22344 samples/s, eta: 0:00:43
[2022/10/01 22:09:19] ppcls INFO: [Train][Epoch 9/10][Iter: 40/44]lr(LinearWarmup): 0.00067781, top1: 0.98018, top5: 0.99695, CELoss: 0.61452, loss: 0.61452, batch_cost: 0.76773s, reader_cost: 0.72313, ips: 20.84056 samples/s, eta: 0:00:36
[2022/10/01 22:09:21] ppcls INFO: [Train][Epoch 9/10][Avg]top1: 0.98000, top5: 0.99714, CELoss: 0.61585, loss: 0.61585
[2022/10/01 22:09:25] ppcls INFO: [Eval][Epoch 9][Iter: 0/13]CELoss: 0.11098, loss: 0.11098, top1: 1.00000, top5: 1.00000, batch_cost: 4.35904s, reader_cost: 4.32332, ips: 3.67054 images/sec
[2022/10/01 22:09:33] ppcls INFO: [Eval][Epoch 9][Iter: 10/13]CELoss: 0.07526, loss: 0.07526, top1: 1.00000, top5: 1.00000, batch_cost: 0.70196s, reader_cost: 0.68046, ips: 22.79330 images/sec
[2022/10/01 22:09:35] ppcls INFO: [Eval][Epoch 9][Avg]CELoss: 0.08644, loss: 0.08644, top1: 1.00000, top5: 1.00000
[2022/10/01 22:09:35] ppcls INFO: [Eval][Epoch 9][best metric: 1.0]
[2022/10/01 22:09:36] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_9
[2022/10/01 22:09:36] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
[2022/10/01 22:09:39] ppcls INFO: [Train][Epoch 10/10][Iter: 0/44]lr(LinearWarmup): 0.00057085, top1: 1.00000, top5: 1.00000, CELoss: 0.54177, loss: 0.54177, batch_cost: 0.81887s, reader_cost: 0.77467, ips: 19.53923 samples/s, eta: 0:00:36
[2022/10/01 22:09:46] ppcls INFO: [Train][Epoch 10/10][Iter: 10/44]lr(LinearWarmup): 0.00034060, top1: 0.98295, top5: 1.00000, CELoss: 0.59843, loss: 0.59843, batch_cost: 0.57836s, reader_cost: 0.52802, ips: 27.66430 samples/s, eta: 0:00:19
[2022/10/01 22:09:56] ppcls INFO: [Train][Epoch 10/10][Iter: 20/44]lr(LinearWarmup): 0.00016704, top1: 0.97321, top5: 1.00000, CELoss: 0.61922, loss: 0.61922, batch_cost: 0.84776s, reader_cost: 0.80208, ips: 18.87329 samples/s, eta: 0:00:20
[2022/10/01 22:10:02] ppcls INFO: [Train][Epoch 10/10][Iter: 30/44]lr(LinearWarmup): 0.00005369, top1: 0.97379, top5: 1.00000, CELoss: 0.61167, loss: 0.61167, batch_cost: 0.76437s, reader_cost: 0.71805, ips: 20.93220 samples/s, eta: 0:00:10
[2022/10/01 22:10:11] ppcls INFO: [Train][Epoch 10/10][Iter: 40/44]lr(LinearWarmup): 0.00000287, top1: 0.96799, top5: 1.00000, CELoss: 0.61944, loss: 0.61944, batch_cost: 0.80014s, reader_cost: 0.75597, ips: 19.99648 samples/s, eta: 0:00:03
[2022/10/01 22:10:12] ppcls INFO: [Train][Epoch 10/10][Avg]top1: 0.96714, top5: 1.00000, CELoss: 0.62067, loss: 0.62067
[2022/10/01 22:10:16] ppcls INFO: [Eval][Epoch 10][Iter: 0/13]CELoss: 0.09542, loss: 0.09542, top1: 1.00000, top5: 1.00000, batch_cost: 4.35401s, reader_cost: 4.31903, ips: 3.67477 images/sec
[2022/10/01 22:10:25] ppcls INFO: [Eval][Epoch 10][Iter: 10/13]CELoss: 0.06318, loss: 0.06318, top1: 1.00000, top5: 1.00000, batch_cost: 0.66734s, reader_cost: 0.64518, ips: 23.97569 images/sec
[2022/10/01 22:10:27] ppcls INFO: [Eval][Epoch 10][Avg]CELoss: 0.07378, loss: 0.07378, top1: 1.00000, top5: 1.00000
[2022/10/01 22:10:27] ppcls INFO: [Eval][Epoch 10][best metric: 1.0]
[2022/10/01 22:10:27] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/epoch_10
[2022/10/01 22:10:27] ppcls INFO: Already save model in ./output/PPLCNet_x1_0/latest
INFO 2022-10-01 22:10:30,839 launch.py:402] Local processes completed.
INFO 2022-10-01 22:10:30,839 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/10/01 22:10:33] ppcls INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2022/10/01 22:10:33] ppcls INFO: Arch : 
[2022/10/01 22:10:33] ppcls INFO:     class_num : 10
[2022/10/01 22:10:33] ppcls INFO:     name : PPLCNet_x1_0
[2022/10/01 22:10:33] ppcls INFO: DataLoader : 
[2022/10/01 22:10:33] ppcls INFO:     Eval : 
[2022/10/01 22:10:33] ppcls INFO:         dataset : 
[2022/10/01 22:10:33] ppcls INFO:             cls_label_path : ./dataset/val_list.txt
[2022/10/01 22:10:33] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:10:33] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:10:33] ppcls INFO:             transform_ops : 
[2022/10/01 22:10:33] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:10:33] ppcls INFO:                     channel_first : False
[2022/10/01 22:10:33] ppcls INFO:                     to_rgb : True
[2022/10/01 22:10:33] ppcls INFO:                 ResizeImage : 
[2022/10/01 22:10:33] ppcls INFO:                     resize_short : 256
[2022/10/01 22:10:33] ppcls INFO:                 CropImage : 
[2022/10/01 22:10:33] ppcls INFO:                     size : 224
[2022/10/01 22:10:33] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:10:33] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:33] ppcls INFO:                     order : 
[2022/10/01 22:10:33] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:10:33] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:33] ppcls INFO:         loader : 
[2022/10/01 22:10:33] ppcls INFO:             num_workers : 4
[2022/10/01 22:10:33] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:10:33] ppcls INFO:         sampler : 
[2022/10/01 22:10:33] ppcls INFO:             batch_size : 16
[2022/10/01 22:10:33] ppcls INFO:             drop_last : False
[2022/10/01 22:10:33] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:10:33] ppcls INFO:             shuffle : False
[2022/10/01 22:10:33] ppcls INFO:     Train : 
[2022/10/01 22:10:33] ppcls INFO:         dataset : 
[2022/10/01 22:10:33] ppcls INFO:             cls_label_path : ./dataset/train_list.txt
[2022/10/01 22:10:33] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:10:33] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:10:33] ppcls INFO:             transform_ops : 
[2022/10/01 22:10:33] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:10:33] ppcls INFO:                     channel_first : False
[2022/10/01 22:10:33] ppcls INFO:                     to_rgb : True
[2022/10/01 22:10:33] ppcls INFO:                 RandCropImage : 
[2022/10/01 22:10:33] ppcls INFO:                     size : 224
[2022/10/01 22:10:33] ppcls INFO:                 RandFlipImage : 
[2022/10/01 22:10:33] ppcls INFO:                     flip_code : 1
[2022/10/01 22:10:33] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:10:33] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:33] ppcls INFO:                     order : 
[2022/10/01 22:10:33] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:10:33] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:33] ppcls INFO:         loader : 
[2022/10/01 22:10:33] ppcls INFO:             num_workers : 4
[2022/10/01 22:10:33] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:10:33] ppcls INFO:         sampler : 
[2022/10/01 22:10:33] ppcls INFO:             batch_size : 16
[2022/10/01 22:10:33] ppcls INFO:             drop_last : False
[2022/10/01 22:10:33] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:10:33] ppcls INFO:             shuffle : True
[2022/10/01 22:10:33] ppcls INFO: Global : 
[2022/10/01 22:10:33] ppcls INFO:     checkpoints : None
[2022/10/01 22:10:33] ppcls INFO:     device : gpu
[2022/10/01 22:10:33] ppcls INFO:     epochs : 10
[2022/10/01 22:10:33] ppcls INFO:     eval_during_train : True
[2022/10/01 22:10:33] ppcls INFO:     eval_interval : 1
[2022/10/01 22:10:33] ppcls INFO:     image_shape : [3, 224, 224]
[2022/10/01 22:10:33] ppcls INFO:     output_dir : ./output/
[2022/10/01 22:10:33] ppcls INFO:     pretrained_model : output/PPLCNet_x1_0/best_model
[2022/10/01 22:10:33] ppcls INFO:     print_batch_step : 10
[2022/10/01 22:10:33] ppcls INFO:     save_inference_dir : ./inference
[2022/10/01 22:10:33] ppcls INFO:     save_interval : 1
[2022/10/01 22:10:33] ppcls INFO:     use_visualdl : False
[2022/10/01 22:10:33] ppcls INFO: Infer : 
[2022/10/01 22:10:33] ppcls INFO:     PostProcess : 
[2022/10/01 22:10:33] ppcls INFO:         class_id_map_file : ./dataset/labels.txt
[2022/10/01 22:10:33] ppcls INFO:         name : Topk
[2022/10/01 22:10:33] ppcls INFO:         topk : 5
[2022/10/01 22:10:33] ppcls INFO:     batch_size : 1
[2022/10/01 22:10:33] ppcls INFO:     infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/10/01 22:10:33] ppcls INFO:     transforms : 
[2022/10/01 22:10:33] ppcls INFO:         DecodeImage : 
[2022/10/01 22:10:33] ppcls INFO:             channel_first : False
[2022/10/01 22:10:33] ppcls INFO:             to_rgb : True
[2022/10/01 22:10:33] ppcls INFO:         ResizeImage : 
[2022/10/01 22:10:33] ppcls INFO:             resize_short : 256
[2022/10/01 22:10:33] ppcls INFO:         CropImage : 
[2022/10/01 22:10:33] ppcls INFO:             size : 224
[2022/10/01 22:10:33] ppcls INFO:         NormalizeImage : 
[2022/10/01 22:10:33] ppcls INFO:             mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:33] ppcls INFO:             order : 
[2022/10/01 22:10:33] ppcls INFO:             scale : 1.0/255.0
[2022/10/01 22:10:33] ppcls INFO:             std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:33] ppcls INFO:         ToCHWImage : None
[2022/10/01 22:10:33] ppcls INFO: Loss : 
[2022/10/01 22:10:33] ppcls INFO:     Eval : 
[2022/10/01 22:10:33] ppcls INFO:         CELoss : 
[2022/10/01 22:10:33] ppcls INFO:             weight : 1.0
[2022/10/01 22:10:33] ppcls INFO:     Train : 
[2022/10/01 22:10:33] ppcls INFO:         CELoss : 
[2022/10/01 22:10:33] ppcls INFO:             epsilon : 0.1
[2022/10/01 22:10:33] ppcls INFO:             weight : 1.0
[2022/10/01 22:10:33] ppcls INFO: Metric : 
[2022/10/01 22:10:33] ppcls INFO:     Eval : 
[2022/10/01 22:10:33] ppcls INFO:         TopkAcc : 
[2022/10/01 22:10:33] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:10:33] ppcls INFO:     Train : 
[2022/10/01 22:10:33] ppcls INFO:         TopkAcc : 
[2022/10/01 22:10:33] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:10:33] ppcls INFO: Optimizer : 
[2022/10/01 22:10:33] ppcls INFO:     lr : 
[2022/10/01 22:10:33] ppcls INFO:         learning_rate : 0.00625
[2022/10/01 22:10:33] ppcls INFO:         name : Cosine
[2022/10/01 22:10:33] ppcls INFO:         warmup_epoch : 5
[2022/10/01 22:10:33] ppcls INFO:     momentum : 0.9
[2022/10/01 22:10:33] ppcls INFO:     name : Momentum
[2022/10/01 22:10:33] ppcls INFO:     regularizer : 
[2022/10/01 22:10:33] ppcls INFO:         coeff : 3e-05
[2022/10/01 22:10:33] ppcls INFO:         name : L2
[2022/10/01 22:10:33] ppcls INFO: train with paddle 2.3.2 and device Place(gpu:0)
W1001 22:10:33.581918  4800 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2
W1001 22:10:33.586396  4800 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.
[2022/10/01 22:10:41] ppcls INFO: [Eval][Epoch 0][Iter: 0/13]CELoss: 0.19519, loss: 0.19519, top1: 1.00000, top5: 1.00000, batch_cost: 6.40011s, reader_cost: 4.28009, ips: 2.49996 images/sec
[2022/10/01 22:10:47] ppcls INFO: [Eval][Epoch 0][Iter: 10/13]CELoss: 0.14239, loss: 0.14239, top1: 1.00000, top5: 1.00000, batch_cost: 0.65962s, reader_cost: 0.63862, ips: 24.25649 images/sec
[2022/10/01 22:10:49] ppcls INFO: [Eval][Epoch 0][Avg]CELoss: 0.11543, loss: 0.11543, 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/10/01 22:10:52] ppcls INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2022/10/01 22:10:52] ppcls INFO: Arch : 
[2022/10/01 22:10:52] ppcls INFO:     class_num : 10
[2022/10/01 22:10:52] ppcls INFO:     name : PPLCNet_x1_0
[2022/10/01 22:10:52] ppcls INFO: DataLoader : 
[2022/10/01 22:10:52] ppcls INFO:     Eval : 
[2022/10/01 22:10:52] ppcls INFO:         dataset : 
[2022/10/01 22:10:52] ppcls INFO:             cls_label_path : ./dataset/val_list.txt
[2022/10/01 22:10:52] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:10:52] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:10:52] ppcls INFO:             transform_ops : 
[2022/10/01 22:10:52] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:10:52] ppcls INFO:                     channel_first : False
[2022/10/01 22:10:52] ppcls INFO:                     to_rgb : True
[2022/10/01 22:10:52] ppcls INFO:                 ResizeImage : 
[2022/10/01 22:10:52] ppcls INFO:                     resize_short : 256
[2022/10/01 22:10:52] ppcls INFO:                 CropImage : 
[2022/10/01 22:10:53] ppcls INFO:                     size : 224
[2022/10/01 22:10:53] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:10:53] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:53] ppcls INFO:                     order : 
[2022/10/01 22:10:53] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:10:53] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:53] ppcls INFO:         loader : 
[2022/10/01 22:10:53] ppcls INFO:             num_workers : 4
[2022/10/01 22:10:53] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:10:53] ppcls INFO:         sampler : 
[2022/10/01 22:10:53] ppcls INFO:             batch_size : 16
[2022/10/01 22:10:53] ppcls INFO:             drop_last : False
[2022/10/01 22:10:53] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:10:53] ppcls INFO:             shuffle : False
[2022/10/01 22:10:53] ppcls INFO:     Train : 
[2022/10/01 22:10:53] ppcls INFO:         dataset : 
[2022/10/01 22:10:53] ppcls INFO:             cls_label_path : ./dataset/train_list.txt
[2022/10/01 22:10:53] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:10:53] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:10:53] ppcls INFO:             transform_ops : 
[2022/10/01 22:10:53] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:10:53] ppcls INFO:                     channel_first : False
[2022/10/01 22:10:53] ppcls INFO:                     to_rgb : True
[2022/10/01 22:10:53] ppcls INFO:                 RandCropImage : 
[2022/10/01 22:10:53] ppcls INFO:                     size : 224
[2022/10/01 22:10:53] ppcls INFO:                 RandFlipImage : 
[2022/10/01 22:10:53] ppcls INFO:                     flip_code : 1
[2022/10/01 22:10:53] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:10:53] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:53] ppcls INFO:                     order : 
[2022/10/01 22:10:53] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:10:53] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:53] ppcls INFO:         loader : 
[2022/10/01 22:10:53] ppcls INFO:             num_workers : 4
[2022/10/01 22:10:53] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:10:53] ppcls INFO:         sampler : 
[2022/10/01 22:10:53] ppcls INFO:             batch_size : 16
[2022/10/01 22:10:53] ppcls INFO:             drop_last : False
[2022/10/01 22:10:53] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:10:53] ppcls INFO:             shuffle : True
[2022/10/01 22:10:53] ppcls INFO: Global : 
[2022/10/01 22:10:53] ppcls INFO:     checkpoints : None
[2022/10/01 22:10:53] ppcls INFO:     device : gpu
[2022/10/01 22:10:53] ppcls INFO:     epochs : 10
[2022/10/01 22:10:53] ppcls INFO:     eval_during_train : True
[2022/10/01 22:10:53] ppcls INFO:     eval_interval : 1
[2022/10/01 22:10:53] ppcls INFO:     image_shape : [3, 224, 224]
[2022/10/01 22:10:53] ppcls INFO:     output_dir : ./output/
[2022/10/01 22:10:53] ppcls INFO:     pretrained_model : output/PPLCNet_x1_0/best_model
[2022/10/01 22:10:53] ppcls INFO:     print_batch_step : 10
[2022/10/01 22:10:53] ppcls INFO:     save_inference_dir : ./inference
[2022/10/01 22:10:53] ppcls INFO:     save_interval : 1
[2022/10/01 22:10:53] ppcls INFO:     use_visualdl : False
[2022/10/01 22:10:53] ppcls INFO: Infer : 
[2022/10/01 22:10:53] ppcls INFO:     PostProcess : 
[2022/10/01 22:10:53] ppcls INFO:         class_id_map_file : ./dataset/labels.txt
[2022/10/01 22:10:53] ppcls INFO:         name : Topk
[2022/10/01 22:10:53] ppcls INFO:         topk : 5
[2022/10/01 22:10:53] ppcls INFO:     batch_size : 1
[2022/10/01 22:10:53] ppcls INFO:     infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/10/01 22:10:53] ppcls INFO:     transforms : 
[2022/10/01 22:10:53] ppcls INFO:         DecodeImage : 
[2022/10/01 22:10:53] ppcls INFO:             channel_first : False
[2022/10/01 22:10:53] ppcls INFO:             to_rgb : True
[2022/10/01 22:10:53] ppcls INFO:         ResizeImage : 
[2022/10/01 22:10:53] ppcls INFO:             resize_short : 256
[2022/10/01 22:10:53] ppcls INFO:         CropImage : 
[2022/10/01 22:10:53] ppcls INFO:             size : 224
[2022/10/01 22:10:53] ppcls INFO:         NormalizeImage : 
[2022/10/01 22:10:53] ppcls INFO:             mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:53] ppcls INFO:             order : 
[2022/10/01 22:10:53] ppcls INFO:             scale : 1.0/255.0
[2022/10/01 22:10:53] ppcls INFO:             std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:53] ppcls INFO:         ToCHWImage : None
[2022/10/01 22:10:53] ppcls INFO: Loss : 
[2022/10/01 22:10:53] ppcls INFO:     Eval : 
[2022/10/01 22:10:53] ppcls INFO:         CELoss : 
[2022/10/01 22:10:53] ppcls INFO:             weight : 1.0
[2022/10/01 22:10:53] ppcls INFO:     Train : 
[2022/10/01 22:10:53] ppcls INFO:         CELoss : 
[2022/10/01 22:10:53] ppcls INFO:             epsilon : 0.1
[2022/10/01 22:10:53] ppcls INFO:             weight : 1.0
[2022/10/01 22:10:53] ppcls INFO: Metric : 
[2022/10/01 22:10:53] ppcls INFO:     Eval : 
[2022/10/01 22:10:53] ppcls INFO:         TopkAcc : 
[2022/10/01 22:10:53] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:10:53] ppcls INFO:     Train : 
[2022/10/01 22:10:53] ppcls INFO:         TopkAcc : 
[2022/10/01 22:10:53] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:10:53] ppcls INFO: Optimizer : 
[2022/10/01 22:10:53] ppcls INFO:     lr : 
[2022/10/01 22:10:53] ppcls INFO:         learning_rate : 0.00625
[2022/10/01 22:10:53] ppcls INFO:         name : Cosine
[2022/10/01 22:10:53] ppcls INFO:         warmup_epoch : 5
[2022/10/01 22:10:53] ppcls INFO:     momentum : 0.9
[2022/10/01 22:10:53] ppcls INFO:     name : Momentum
[2022/10/01 22:10:53] ppcls INFO:     regularizer : 
[2022/10/01 22:10:53] ppcls INFO:         coeff : 3e-05
[2022/10/01 22:10:53] ppcls INFO:         name : L2
[2022/10/01 22:10:53] ppcls INFO: train with paddle 2.3.2 and device Place(gpu:0)
W1001 22:10:53.005101  4874 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2
W1001 22:10:53.009593  4874 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.
invalid literal for int() with base 10: 'dianchi'
[{'class_ids': [4, 7, 9, 8, 2], 'scores': [0.93592, 0.01195, 0.00997, 0.00824, 0.00775], 'file_name': './dataset/taoci/IMG_7923.JPG', 'label_names': []}]

三、jetson nano部署

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/10/01 22:10:59] ppcls INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

[2022/10/01 22:10:59] ppcls INFO: Arch : 
[2022/10/01 22:10:59] ppcls INFO:     class_num : 10
[2022/10/01 22:10:59] ppcls INFO:     name : PPLCNet_x1_0
[2022/10/01 22:10:59] ppcls INFO: DataLoader : 
[2022/10/01 22:10:59] ppcls INFO:     Eval : 
[2022/10/01 22:10:59] ppcls INFO:         dataset : 
[2022/10/01 22:10:59] ppcls INFO:             cls_label_path : ./dataset/val_list.txt
[2022/10/01 22:10:59] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:10:59] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:10:59] ppcls INFO:             transform_ops : 
[2022/10/01 22:10:59] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:10:59] ppcls INFO:                     channel_first : False
[2022/10/01 22:10:59] ppcls INFO:                     to_rgb : True
[2022/10/01 22:10:59] ppcls INFO:                 ResizeImage : 
[2022/10/01 22:10:59] ppcls INFO:                     resize_short : 256
[2022/10/01 22:10:59] ppcls INFO:                 CropImage : 
[2022/10/01 22:10:59] ppcls INFO:                     size : 224
[2022/10/01 22:10:59] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:10:59] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:59] ppcls INFO:                     order : 
[2022/10/01 22:10:59] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:10:59] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:59] ppcls INFO:         loader : 
[2022/10/01 22:10:59] ppcls INFO:             num_workers : 4
[2022/10/01 22:10:59] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:10:59] ppcls INFO:         sampler : 
[2022/10/01 22:10:59] ppcls INFO:             batch_size : 16
[2022/10/01 22:10:59] ppcls INFO:             drop_last : False
[2022/10/01 22:10:59] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:10:59] ppcls INFO:             shuffle : False
[2022/10/01 22:10:59] ppcls INFO:     Train : 
[2022/10/01 22:10:59] ppcls INFO:         dataset : 
[2022/10/01 22:10:59] ppcls INFO:             cls_label_path : ./dataset/train_list.txt
[2022/10/01 22:10:59] ppcls INFO:             image_root : ./dataset/
[2022/10/01 22:10:59] ppcls INFO:             name : ImageNetDataset
[2022/10/01 22:10:59] ppcls INFO:             transform_ops : 
[2022/10/01 22:10:59] ppcls INFO:                 DecodeImage : 
[2022/10/01 22:10:59] ppcls INFO:                     channel_first : False
[2022/10/01 22:10:59] ppcls INFO:                     to_rgb : True
[2022/10/01 22:10:59] ppcls INFO:                 RandCropImage : 
[2022/10/01 22:10:59] ppcls INFO:                     size : 224
[2022/10/01 22:10:59] ppcls INFO:                 RandFlipImage : 
[2022/10/01 22:10:59] ppcls INFO:                     flip_code : 1
[2022/10/01 22:10:59] ppcls INFO:                 NormalizeImage : 
[2022/10/01 22:10:59] ppcls INFO:                     mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:59] ppcls INFO:                     order : 
[2022/10/01 22:10:59] ppcls INFO:                     scale : 1.0/255.0
[2022/10/01 22:10:59] ppcls INFO:                     std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:59] ppcls INFO:         loader : 
[2022/10/01 22:10:59] ppcls INFO:             num_workers : 4
[2022/10/01 22:10:59] ppcls INFO:             use_shared_memory : True
[2022/10/01 22:10:59] ppcls INFO:         sampler : 
[2022/10/01 22:10:59] ppcls INFO:             batch_size : 16
[2022/10/01 22:10:59] ppcls INFO:             drop_last : False
[2022/10/01 22:10:59] ppcls INFO:             name : DistributedBatchSampler
[2022/10/01 22:10:59] ppcls INFO:             shuffle : True
[2022/10/01 22:10:59] ppcls INFO: Global : 
[2022/10/01 22:10:59] ppcls INFO:     checkpoints : None
[2022/10/01 22:10:59] ppcls INFO:     device : gpu
[2022/10/01 22:10:59] ppcls INFO:     epochs : 10
[2022/10/01 22:10:59] ppcls INFO:     eval_during_train : True
[2022/10/01 22:10:59] ppcls INFO:     eval_interval : 1
[2022/10/01 22:10:59] ppcls INFO:     image_shape : [3, 224, 224]
[2022/10/01 22:10:59] ppcls INFO:     output_dir : ./output/
[2022/10/01 22:10:59] ppcls INFO:     pretrained_model : output/PPLCNet_x1_0/best_model
[2022/10/01 22:10:59] ppcls INFO:     print_batch_step : 10
[2022/10/01 22:10:59] ppcls INFO:     save_inference_dir : deploy/models/PPLCNet_x1_0_infer
[2022/10/01 22:10:59] ppcls INFO:     save_interval : 1
[2022/10/01 22:10:59] ppcls INFO:     use_visualdl : False
[2022/10/01 22:10:59] ppcls INFO: Infer : 
[2022/10/01 22:10:59] ppcls INFO:     PostProcess : 
[2022/10/01 22:10:59] ppcls INFO:         class_id_map_file : ./dataset/labels.txt
[2022/10/01 22:10:59] ppcls INFO:         name : Topk
[2022/10/01 22:10:59] ppcls INFO:         topk : 5
[2022/10/01 22:10:59] ppcls INFO:     batch_size : 1
[2022/10/01 22:10:59] ppcls INFO:     infer_imgs : ./dataset/taoci/IMG_7923.JPG
[2022/10/01 22:10:59] ppcls INFO:     transforms : 
[2022/10/01 22:10:59] ppcls INFO:         DecodeImage : 
[2022/10/01 22:10:59] ppcls INFO:             channel_first : False
[2022/10/01 22:10:59] ppcls INFO:             to_rgb : True
[2022/10/01 22:10:59] ppcls INFO:         ResizeImage : 
[2022/10/01 22:10:59] ppcls INFO:             resize_short : 256
[2022/10/01 22:10:59] ppcls INFO:         CropImage : 
[2022/10/01 22:10:59] ppcls INFO:             size : 224
[2022/10/01 22:10:59] ppcls INFO:         NormalizeImage : 
[2022/10/01 22:10:59] ppcls INFO:             mean : [0.485, 0.456, 0.406]
[2022/10/01 22:10:59] ppcls INFO:             order : 
[2022/10/01 22:10:59] ppcls INFO:             scale : 1.0/255.0
[2022/10/01 22:10:59] ppcls INFO:             std : [0.229, 0.224, 0.225]
[2022/10/01 22:10:59] ppcls INFO:         ToCHWImage : None
[2022/10/01 22:10:59] ppcls INFO: Loss : 
[2022/10/01 22:10:59] ppcls INFO:     Eval : 
[2022/10/01 22:10:59] ppcls INFO:         CELoss : 
[2022/10/01 22:10:59] ppcls INFO:             weight : 1.0
[2022/10/01 22:10:59] ppcls INFO:     Train : 
[2022/10/01 22:10:59] ppcls INFO:         CELoss : 
[2022/10/01 22:10:59] ppcls INFO:             epsilon : 0.1
[2022/10/01 22:10:59] ppcls INFO:             weight : 1.0
[2022/10/01 22:10:59] ppcls INFO: Metric : 
[2022/10/01 22:10:59] ppcls INFO:     Eval : 
[2022/10/01 22:10:59] ppcls INFO:         TopkAcc : 
[2022/10/01 22:10:59] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:10:59] ppcls INFO:     Train : 
[2022/10/01 22:10:59] ppcls INFO:         TopkAcc : 
[2022/10/01 22:10:59] ppcls INFO:             topk : [1, 5]
[2022/10/01 22:10:59] ppcls INFO: Optimizer : 
[2022/10/01 22:10:59] ppcls INFO:     lr : 
[2022/10/01 22:10:59] ppcls INFO:         learning_rate : 0.00625
[2022/10/01 22:10:59] ppcls INFO:         name : Cosine
[2022/10/01 22:10:59] ppcls INFO:         warmup_epoch : 5
[2022/10/01 22:10:59] ppcls INFO:     momentum : 0.9
[2022/10/01 22:10:59] ppcls INFO:     name : Momentum
[2022/10/01 22:10:59] ppcls INFO:     regularizer : 
[2022/10/01 22:10:59] ppcls INFO:         coeff : 3e-05
[2022/10/01 22:10:59] ppcls INFO:         name : L2
[2022/10/01 22:10:59] ppcls INFO: train with paddle 2.3.2 and device Place(gpu:0)
W1001 22:10:59.590785  4926 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2
W1001 22:10:59.595405  4926 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.
[2022/10/01 22:11:01] 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文件夹压缩并上传至jetson nano
%cd deploy/models
!zip -r PPLCNet_x1_0_infer.zip  PPLCNet_x1_0_infer/

# 将 data/data155466/垃圾检测.zip 上传至jetson nano
/home/aistudio/PaddleClas/deploy/models
updating: PPLCNet_x1_0_infer/ (stored 0%)
updating: PPLCNet_x1_0_infer/inference.pdmodel (deflated 97%)
updating: PPLCNet_x1_0_infer/inference.pdiparams (deflated 7%)
updating: PPLCNet_x1_0_infer/inference.pdiparams.info (deflated 82%)

3.2 Paddle Inference推理部署

  • Paddle Inference 是飞桨的原生推理库, 作用于服务器端和云端,提供高性能的推理能力。 由于能力直接基于飞桨的训练算子,因此Paddle Inference 可以通用支持飞桨训练出的所有模型。
  • Paddle Inference 功能特性丰富,性能优异,针对不同平台不同的应用场景进行了深度的适配优化,做到高吞吐、低时延,保证了飞桨模型在服务器端即训即用,快速部署。

3.2.1 环境准备

  • Python3.6.9
  • JetPack4.6.2,paddlepaddle_gpu-2.3.0
  • 最新的Paddle-Inference-Demo

查看本机JetPack版本和python版本,在PaddleInference官网下载与本机版本对应的paddlepaddle即可
在这里插入图片描述

# 如下图,我的JetPack版本为4.6.2,python版本为3.6.9
sudo apt-cache show nvidia-jetpack

# 下载对应的PaddlePaddle到指定目录
wget -O /home/nvidia/paddlepaddle.whl "https://paddle-inference-lib.bj.bcebos.com/2.3.0/python/Jetson/jetpack4.6_gcc7.5/nano/paddlepaddle_gpu-2.3.0-cp36-cp36m-linux_aarch64.whl"

# 安装PaddlePaddle
pip install paddlepaddle.whl

# 下载Paddle-Inference-Demo,若网络不好可在本机下载完毕之后通过ssh连接传输到nano上
git clone https://github.com/PaddlePaddle/Paddle-Inference-Demo.git

在这里插入图片描述

3.2.2 模型解压

# 将之前上传到nano上的inference模型压缩包:PPLCNet_x1_0_infer.zip,在nano上解压至/home/nvidia/Paddle-Inference-Demo/python/gpu/resnet50下
unzip PPLCNet_x1_0_infer.zip

# 对模型文件夹重命名
mv PPLCNet_x1_0_infer inference_model

四、本地推理部署

4.1 更换数据集

# 将之前上传到nano上的数据集:垃圾检测.zip,移动到Paddle-Inference-Demo/python/gpu/resnet50并解压
mv 垃圾检测.zip Paddle-Inference-Demo/python/gpu/resnet50
unzip 垃圾检测.zip 

# 对数据集重命名
mv 垃圾检测 dataset

# 将标签集labels.txt移动到Paddle-Inference-Demo/python/gpu/resnet50下
cd dataset
mv labels.txt ../

cd ../
nano infer_resnet.py
# 将下面的代码复制到infer_resnet.py中,ctrl+o保存,ctrl+x退出
import numpy as np
import argparse
import cv2
import sys
import time

from paddle.inference import Config
from paddle.inference import create_predictor
from paddle.inference import PrecisionType

from img_preprocess import preprocess

image_path = './dataset/test_list.txt'
labels_path = './labels.txt'

def init_predictor(args):
    # 创建 config
    if args.model_dir is not "":
        config = Config(args.model_dir)
    else:
        config = Config(args.model_file, args.params_file)

    config.disable_glog_info()        # 去除 Paddle Inference 运行中的 LOG
    config.enable_memory_optim()      # 开启内存 / 显存复用,优化 
    config.enable_use_gpu(1000, 0)    # 启用 GPU 进行预测

    if args.run_mode == "gpu_fp16":
        config.exp_enable_use_gpu_fp16()
    elif args.run_mode == "trt_fp32":
        config.enable_tensorrt_engine(workspace_size=1 << 30,
                                max_batch_size=1,
                                min_subgraph_size=5,
                                precision_mode=PrecisionType.Float32,
                                use_static=False,
                                use_calib_mode=False)
    elif args.run_mode == "trt_fp16":
        config.enable_tensorrt_engine(workspace_size=1 << 30,
                                max_batch_size=1,
                                min_subgraph_size=5,
                                precision_mode=PrecisionType.Half,
                                use_static=False,
                                use_calib_mode=False)
    elif args.run_mode == "trt_int8":
        config.enable_tensorrt_engine(workspace_size=1 << 30,
                                max_batch_size=1,
                                min_subgraph_size=5,
                                precision_mode=PrecisionType.Int8,
                                use_static=False,
                                use_calib_mode=True)

    if args.use_dynamic_shape:
        names = ["im_shape", "image", "scale_factor"]
        min_input_shape = [[1, 2], [1, 3, 112, 112], [1, 2]]
        max_input_shape = [[1, 2], [1, 3, 608, 608], [1, 2]]
        opt_input_shape = [[1, 2], [1, 3, 608, 608], [1, 2]]

        config.set_trt_dynamic_shape_info(
            {names[0]: min_input_shape[0],
             names[1]: min_input_shape[0],
             names[2]: min_input_shape[0],
            }, 
            {names[0]: max_input_shape[1],
             names[1]: max_input_shape[1],
             names[2]: max_input_shape[1],
            }, 
            {names[0]: opt_input_shape[2],
             names[1]: opt_input_shape[2],
             names[2]: opt_input_shape[2],
            }
        )

    predictor = create_predictor(config)
    return predictor


def run(predictor, img):
    # 复制img数据到输入张量
    input_names = predictor.get_input_names()
    for i, name in enumerate(input_names):
        input_tensor = predictor.get_input_handle(name)
        input_tensor.reshape(img[i].shape)
        input_tensor.copy_from_cpu(img[i].copy())

    # 做推理
    predictor.run()

    results = []
    # 从输出张量中得到数据
    output_names = predictor.get_output_names()
    for i, name in enumerate(output_names):
        output_tensor = predictor.get_output_handle(name)
        output_data = output_tensor.copy_to_cpu()
        results.append(output_data)

    return results


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_file",
        type=str,
        default="",
        help="模型文件名,当你的模型是一个组合模型时指定它。"
    )
    parser.add_argument(
        "--params_file",
        type=str,
        default="",
        help=
        "参数文件名,当你的模型是一个组合模型时指定它。"
    )
    parser.add_argument(
        "--model_dir",
        type=str,
        default="",
        help=
        "模型目录,如果你加载一个非组合模型,指定模型的目录。"
    )
    parser.add_argument(
        "--run_mode",
        type=str,
        default="",
        help=
        "运行模式,包括:trt_fp32、trt_fp16、trt_int8和gpu_fp16。"
    )
    parser.add_argument("--use_dynamic_shape",
                        type=int,
                        default=0,
                        help="是否使用trt动态形状。")

    return parser.parse_args()

# 加载标签集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

if __name__ == '__main__':
    args = parse_args()
    pred = init_predictor(args)   # 耗时6s
    labels = load_labels()

    if image_path[-3:] == 'txt':
        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('./dataset/' + img_path)  # 耗时260ms
            
            t1=time.time()
            
            img = preprocess(img)                      # 耗时18ms
            #img = np.ones((1, 3, 224, 224)).astype(np.float32)
            if args.run_mode == "gpu_fp16":
                img = img.astype(np.float16)
            result = run(pred, [img])                  # 耗时30ms
            print("类别: ", labels[np.argmax(result[0][0])])
            
            t2=time.time()
            print('程序运行时间:%.2f毫秒' % ((t2 - t1)*1000))

4.2 本地推理部署

nano run.sh
# 将下面的代码复制到run.sh中,ctrl+o保存,ctrl+x退出
python3 infer_resnet.py --model_file=./inference_model/model.pdmodel --params_file=./inference_model/model.pdiparams

# 运行预测脚本,对批量图片进行预测
python3 run.sh

在这里插入图片描述

4.3 软硬结合

  • 硬件部分由舵机控制器来实现垃圾的分类投放功能,超声波传感器来实现垃圾的满载检测
  • 软件部分通过Python的图形界面开发的库Tkinter来实现
  • 软硬件结合通过串口通信来实现

下面是软件方面的成果
在这里插入图片描述
在这里插入图片描述

# 播放软硬一体的实物视频
# 由于疫情封校原因,无法拿到网购的摄像头和底盘加固材料,所以视频中的投放过程摇摇晃晃,并且没有安装摄像头。
import IPython

IPython.display.Video('demo_video.mp4',width=400, height=200)
Your browser does not support the video element.

五、项目总结

  • 项目整体的设计难点在于最初通过paddlelite来对树莓派进行部署,与nano相比树莓派的计算性能不仅弱爆了,而且编译部署上也是问题重重,折磨了我快一个多月。在从百度申请到nano的开发板之后,我几乎只用了一个下午就完成了模型的部署与功能的修改,而且在准确率不变的前提下,性能提升达到了91%,所以选用一个合适的开发板真的很重要。

  • 在项目过程中总会遇到各种各样难以解决的问题,我认为持续不断的攻坚克难才是最终成功解决问题的关键,就比如我暑假留校,将两个月的时间都投入到了其中,每天学习,调试到深夜1,2点,虽然很苦很累,但当最终的项目成品正一步步呈现在自己眼前时,这一切努力就变得真的很值得!

  • 关于这个项目其实还有很多不足地方,特别是硬件控制部分,选用二维舵机虽然结构比较简单,但一次却只能投放一个垃圾来进行分类,不能同时进行多个垃圾的分类。此外,该装置对于恶劣环境下,光干扰时,摄像头采集数据的稳定性也是个问题。以及垃圾桶的防水和供电问题也需要好好想想。总之,还有很长的路要走,我相信,当我下次再来参加创造营的活动时,会带来一个设计更加完美,功能更加完备的智能垃圾桶2.0

个人介绍

姓名:肖雄

学校:长江大学

专业:物联网工程大三在读

爱好:喜欢专研技术,对深度学习产业落地的前景十分看好,同时也在学习Spring全家桶,提高自己的软件设计能力。

主要方向:CV,软件开发

个人博客:https://blog.csdn.net/weixin_46227276

此文章为搬运
原项目链接

Logo

学大模型,用大模型上飞桨星河社区!每天8点V100G算力免费领!免费领取ERNIE 4.0 100w Token >>>

更多推荐