1.项目说明
转载自AI Studio
项目链接https://aistudio.baidu.com/aistudio/projectdetail/3497217?contributionType=1
近年来,电瓶车进楼入户发生的火灾事故屡见不鲜,针对该现象推出了相应的电瓶车入室检测模型,旨在从源头减少这一情况的发生。 针对室内摩托车模型可能会发生的误报情况,采用了额外的图像检索方式实现更为精确的识别。 本案例使用了飞桨目标检测套件PaddleDetection中的picodet模型以及图像识别套件PaddleClas中的轻量级通用识别模型。

2.数据集准备

本案例中picodet的模型数据集为VOC格式(使用labelimg制成),包括21903张电梯中的图片,其中训练集17522张,测试集4381张,皆来自日常的电梯场景中,共有14715个摩托车的框,23058个人的框,3750个自行车的框,由于picodet使用的是coco格式,所以需要将VOC格式转换成coco格式。
生成VOC数据集:使用python的labelimg图像标注工具为原始图片生成对应的标注xml文件作为原始的VOC格式数据集,生成的xml文件格式如下图所示,其中每个object代表框出的每一个对象,object中的name表明对象的名字而bndbox中包含框的具体坐标(左上角以及右下角)。

labelimg生成的xml文件如下图所示:

生成VOC数据集:
完成图片标注后,下一步就是生成数据集,将每个图片与其xml对应起来按比例生成对应的训练集以及测试集.

%cd /home/aistudio/data/data128282
!unzip -q picodet_motorcycle.zip
/home/aistudio/data/data128282

生成的数据集文件组织结构为:

├── classify_voc.py
├── picodet_motorcycle
│   ├── Annotations
│   │   ├── 1595214506200933-1604535322-[]-motorcycle.xml
│   │   ├── 1595214506200933-1604542813-[]-motorcycle.xml
│   │   ├── 1595214506200933-1604559538-[]-motorcycle.xml
|   ...
│   ├── ImageSets
│   │   └── Main
│   │       ├── test.txt
│   │       ├── train.txt
│   │       ├── trainval.txt
│   │       └── val.txt
│   └── JPEGImages
│       ├── 1595214506200933-1604535322-[]-motorcycle.jpg
│       ├── 1595214506200933-1604542813-[]-motorcycle.jpg
│       ├── 1595214506200933-1604559538-[]-motorcycle.jpg
│       |   ...
├── picodet_motorcycle.zip
├── prepare_voc_data.py
├── test.txt
└── trainval.txt

训练集与测试集转换:
使用PaddleDetection自带的转换工具以及教程完成数据集的转换。

%cd /home/aistudio/work/code
!python x2coco.py --dataset_type voc  --voc_anno_dir /home/aistudio/data/data128282/ --voc_anno_list /home/aistudio/data/data128282/trainval.txt --voc_label_list /home/aistudio/data/data128282/label_list.txt  --voc_out_name voc_train.json
!python x2coco.py --dataset_type voc --voc_anno_dir /home/aistudio/data/data128282/ --voc_anno_list /home/aistudio/data/data128282/test.txt --voc_label_list /home/aistudio/data/data128282/label_list.txt --voc_out_name voc_test.json
%mv voc_test.json /home/aistudio/data/data128282/
%mv voc_train.json /home/aistudio/data/data128282/
/home/aistudio/work/code
Start converting !
  0%|                                                    | 0/77 [00:00<?, ?it/s]/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601636847-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606526986-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601720615-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605687102-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603701038-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601014507-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602417498-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606987875-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605307744-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601392390-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601502491-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606474584-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604796549-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605567173-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603403665-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1607293952-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601606889-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605775243-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602286628-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1607478833-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601724771-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601983877-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601109625-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604908276-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601328865-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604962373-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1614551404-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603592908-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1607035104-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603279381-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1608023409-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1608680647-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602387947-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602451885-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601167689-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601714437-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1607334827-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605847099-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605942910-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1608676249-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606467984-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604704753-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601457250-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605918823-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604645508-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605320288-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603667719-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604906260-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605081236-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606519196-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1607166709-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605253355-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605430384-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604542813-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605831965-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602155170-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604535322-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1608106126-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601555685-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606951434-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605911905-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605319279-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603611971-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605078230-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602884126-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602652913-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603889312-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601675348-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601979307-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1616667058-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602034891-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601017453-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606347862-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601426959-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601156762-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606781280-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605685895-[]-motorcycle.xml
100%|████████████████████████████████████████| 77/77 [00:00<00:00, 12373.05it/s]
Start converting !
  0%|                                                    | 0/20 [00:00<?, ?it/s]/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604559538-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606603675-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603625601-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1606775597-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601810534-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605086179-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601280308-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603536254-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602661139-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605857758-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602247634-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601529066-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1604915966-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1607467016-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1605313712-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1603886590-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601036072-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1602411106-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506202667-1601278288-[]-motorcycle.xml
/home/aistudio/data/data128282/picodet_motorcycle/Annotations/1595214506200933-1610708817-[]-motorcycle.xml
100%|████████████████████████████████████████| 20/20 [00:00<00:00, 10206.36it/s]

3.目标检测模型训练

将数据集划分为训练集以及测试集后,使用picodet_lcnet_1_5x_416_coco.yml文件便可以开始训练(该文件在PaddleDetection-release-2.3/configs/picodet/more_config/ 下有样板只需要稍微修改一下)。

预训练模型选用PicoDet_LCNet 1.5x,训练完成后可以进行评估,训练与评估的命令如下。
picodet_lcnet_1_5x_416_coco.yml 文件的内容如下所示:
使用的预训练模型如图:

#安装依赖库
%cd /home/aistudio/work/code/train/
!pip install pycocotools
!pip install faiss-gpu
!pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple  
/home/aistudio/work/code/train
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pycocotools
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/75/5c/ac61ea715d7a89ecc31c090753bde28810238225ca8b71778dfe3e6a68bc/pycocotools-2.0.4.tar.gz (106 kB)
     |████████████████████████████████| 106 kB 5.3 MB/s            
[?25h  Installing build dependencies ... [?25ldone
[?25h  Getting requirements to build wheel ... [?25ldone
[?25h  Preparing metadata (pyproject.toml) ... [?25ldone
[?25hRequirement already satisfied: numpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools) (1.19.5)
Requirement already satisfied: matplotlib>=2.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools) (2.2.3)
Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools) (2019.3)
Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools) (2.8.2)
Requirement already satisfied: six>=1.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools) (1.16.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>=2.1.0->pycocotools) (3.0.7)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools) (1.1.0)
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools) (0.10.0)
Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib>=2.1.0->pycocotools) (56.2.0)
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (pyproject.toml) ... [?25ldone
[?25h  Created wheel for pycocotools: filename=pycocotools-2.0.4-cp37-cp37m-linux_x86_64.whl size=273804 sha256=6b800906c05f05a1fcf114935c3a3ac61eb0d9f561d0a547e676c0052d6aa696
  Stored in directory: /home/aistudio/.cache/pip/wheels/c0/01/5f/670dfd20204fc9cc6bf843db4e014acb998f411922e3abc49f
Successfully built pycocotools
Installing collected packages: pycocotools
Successfully installed pycocotools-2.0.4
[33mWARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/opt/conda/envs/python35-paddle120-env/bin/python -m pip install --upgrade pip' command.[0m
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting faiss-gpu
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/44/cf/c26e522517c3bdd0899309f9d90c8c6c1654e059245ff0ca6a6140b550d5/faiss_gpu-1.7.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (85.5 MB)
     |████████████████████████████████| 85.5 MB 94 kB/s             
[?25hInstalling collected packages: faiss-gpu
Successfully installed faiss-gpu-1.7.2
[33mWARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/opt/conda/envs/python35-paddle120-env/bin/python -m pip install --upgrade pip' command.[0m
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (4.27.0)
Collecting typeguard
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9a/bb/d43e5c75054e53efce310e79d63df0ac3f25e34c926be5dffb7d283fb2a8/typeguard-2.13.3-py3-none-any.whl (17 kB)
Requirement already satisfied: visualdl>=2.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (2.2.0)
Requirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (4.1.1.26)
Requirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (5.1.2)
Collecting shapely
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9d/4d/4b0d86ed737acb29c5e627a91449470a9fb914f32640db3f1cb7ba5bc19e/Shapely-1.8.1.post1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.0 MB)
     |████████████████████████████████| 2.0 MB 4.6 MB/s            
[?25hRequirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (1.6.3)
Collecting terminaltables
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c4/fb/ea621e0a19733e01fe4005d46087d383693c0f4a8f824b47d8d4122c87e0/terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: Cython in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (0.29)
Requirement already satisfied: pycocotools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 10)) (2.0.4)
Requirement already satisfied: setuptools>=42.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 12)) (56.2.0)
Collecting lap
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bf/64/d9fb6a75b15e783952b2fec6970f033462e67db32dc43dfbb404c14e91c2/lap-0.4.0.tar.gz (1.5 MB)
     |████████████████████████████████| 1.5 MB 5.6 MB/s            
[?25h  Preparing metadata (setup.py) ... [?25ldone
[?25hRequirement already satisfied: sklearn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 14)) (0.0)
Collecting motmetrics
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9c/28/9c3bc8e2a87f4c9e7b04ab72856ec7f9895a66681a65973ffaf9562ef879/motmetrics-1.2.0-py3-none-any.whl (151 kB)
     |████████████████████████████████| 151 kB 4.2 MB/s            
[?25hRequirement already satisfied: openpyxl in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 16)) (3.0.5)
Collecting cython_bbox
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fa/b9/fc7d60e8c3b29cc0ff24a3bb3c4b7457e10b7610fbb2893741b623487b34/cython_bbox-0.1.3.tar.gz (41 kB)
     |████████████████████████████████| 41 kB 456 kB/s             
[?25h  Preparing metadata (setup.py) ... [?25ldone
[?25hRequirement already satisfied: Pillow>=7.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (8.2.0)
Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (0.8.53)
Requirement already satisfied: numpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.19.5)
Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.16.0)
Requirement already satisfied: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (0.7.1.1)
Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.5)
Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (3.14.0)
Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.1)
Requirement already satisfied: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.21.0)
Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (2.2.3)
Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (2.24.0)
Requirement already satisfied: flake8>=3.7.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (4.0.1)
Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.0.0)
Requirement already satisfied: scikit-learn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from sklearn->-r requirements.txt (line 14)) (0.24.2)
Collecting pytest-benchmark
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2c/60/423a63fb190a0483d049786a121bd3dfd7d93bb5ff1bb5b5cd13e5df99a7/pytest_benchmark-3.4.1-py2.py3-none-any.whl (50 kB)
     |████████████████████████████████| 50 kB 6.9 MB/s             
[?25hCollecting xmltodict>=0.12.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/fd/30d5c1d3ac29ce229f6bdc40bbc20b28f716e8b363140c26eff19122d8a5/xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)
Collecting pytest
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/38/93/c7c0bd1e932b287fb948eb9ce5a3d6307c9fc619db1e199f8c8bc5dad95f/pytest-7.0.1-py3-none-any.whl (296 kB)
     |████████████████████████████████| 296 kB 3.0 MB/s            
[?25hCollecting flake8-import-order
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ab/52/cf2d6e2c505644ca06de2f6f3546f1e4f2b7be34246c9e0757c6048868f9/flake8_import_order-0.18.1-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: jdcal in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from openpyxl->-r requirements.txt (line 16)) (1.4.1)
Requirement already satisfied: et-xmlfile in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from openpyxl->-r requirements.txt (line 16)) (1.0.1)
Requirement already satisfied: importlib-metadata<4.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (4.2.0)
Requirement already satisfied: pycodestyle<2.9.0,>=2.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.8.0)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.6.1)
Requirement already satisfied: pyflakes<2.5.0,>=2.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.4.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.1.0->-r requirements.txt (line 3)) (7.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.1.0->-r requirements.txt (line 3)) (1.1.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.1.0->-r requirements.txt (line 3)) (0.16.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.1.0->-r requirements.txt (line 3)) (2.11.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.1.0->-r requirements.txt (line 3)) (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.1.0->-r requirements.txt (line 3)) (2019.3)
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.1.0->-r requirements.txt (line 3)) (3.0.7)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.0)
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.1.0->-r requirements.txt (line 3)) (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.1.0->-r requirements.txt (line 3)) (2.8.2)
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.1.0->-r requirements.txt (line 3)) (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.1.0->-r requirements.txt (line 3)) (3.9.9)
Requirement already satisfied: toml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.10.0)
Requirement already satisfied: virtualenv>=15.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (16.7.9)
Requirement already satisfied: nodeenv>=0.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.3.4)
Requirement already satisfied: aspy.yaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.3.0)
Requirement already satisfied: cfgv>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.0.1)
Requirement already satisfied: identify>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pre-commit->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.4.10)
Requirement already satisfied: packaging in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pytest->motmetrics->-r requirements.txt (line 15)) (21.3)
Requirement already satisfied: attrs>=19.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pytest->motmetrics->-r requirements.txt (line 15)) (21.4.0)
Collecting iniconfig
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl (5.0 kB)
Collecting py>=1.8.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f6/f0/10642828a8dfb741e5f3fbaac830550a518a775c7fff6f04a007259b0548/py-1.11.0-py2.py3-none-any.whl (98 kB)
     |████████████████████████████████| 98 kB 2.6 MB/s             
[?25hRequirement already satisfied: pluggy<2.0,>=0.12 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pytest->motmetrics->-r requirements.txt (line 15)) (0.13.1)
Collecting tomli>=1.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl (12 kB)
Collecting py-cpuinfo
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e6/ba/77120e44cbe9719152415b97d5bfb29f4053ee987d6cb63f55ce7d50fadc/py-cpuinfo-8.0.0.tar.gz (99 kB)
     |████████████████████████████████| 99 kB 2.6 MB/s             
[?25h  Preparing metadata (setup.py) ... [?25ldone
[?25hRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.1.0->-r requirements.txt (line 3)) (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.1.0->-r requirements.txt (line 3)) (2.8)
Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.1.0->-r requirements.txt (line 3)) (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.1.0->-r requirements.txt (line 3)) (1.25.6)
Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->-r requirements.txt (line 14)) (2.1.0)
Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->-r requirements.txt (line 14)) (0.14.1)
Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (3.7.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata<4.3->flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (4.0.1)
Requirement already satisfied: MarkupSafe>=0.23 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.0.1)
Building wheels for collected packages: lap, cython-bbox, py-cpuinfo
  Building wheel for lap (setup.py) ... [?25ldone
[?25h  Created wheel for lap: filename=lap-0.4.0-cp37-cp37m-linux_x86_64.whl size=1593876 sha256=a28326569480a6df5fec4caaa6f9ac6e798b96d1bcdea9c0a11256eeb842481a
  Stored in directory: /home/aistudio/.cache/pip/wheels/5c/d0/d2/e331d17a999666b1e2eb99743cfa1742629f9d26c55c657001
  Building wheel for cython-bbox (setup.py) ... [?25ldone
[?25h  Created wheel for cython-bbox: filename=cython_bbox-0.1.3-cp37-cp37m-linux_x86_64.whl size=61630 sha256=bc148ae77ebdb3fa2ae098380eb98b8d8eaf3d35852f3254c1b1c10cb2c6fdb6
  Stored in directory: /home/aistudio/.cache/pip/wheels/3e/b3/6a/aae8832326545645e65d643a2aaf223ffa3a7d01e1a1bae01b
  Building wheel for py-cpuinfo (setup.py) ... [?25ldone
[?25h  Created wheel for py-cpuinfo: filename=py_cpuinfo-8.0.0-py3-none-any.whl size=22245 sha256=984feb634f3bf73074c8c5a1439b129e958b6d4f93e7dace54fafd694f8818c6
  Stored in directory: /home/aistudio/.cache/pip/wheels/88/c7/d0/6309c7cc9929894c11fe8e516c3e2a0d0a53ee4e198eac48b7
Successfully built lap cython-bbox py-cpuinfo
Installing collected packages: tomli, py, iniconfig, pytest, py-cpuinfo, xmltodict, pytest-benchmark, flake8-import-order, typeguard, terminaltables, shapely, motmetrics, lap, cython-bbox
Successfully installed cython-bbox-0.1.3 flake8-import-order-0.18.1 iniconfig-1.1.1 lap-0.4.0 motmetrics-1.2.0 py-1.11.0 py-cpuinfo-8.0.0 pytest-7.0.1 pytest-benchmark-3.4.1 shapely-1.8.1.post1 terminaltables-3.1.10 tomli-2.0.1 typeguard-2.13.3 xmltodict-0.12.0
[33mWARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/opt/conda/envs/python35-paddle120-env/bin/python -m pip install --upgrade pip' command.[0m
#训练模型,完成后生成在output文件夹下
%cd /home/aistudio/work/code/train/
!python3 train.py -c picodet_lcnet_1_5x_416_coco.yml -o pretrain_weights=https://paddledet.bj.bcebos.com/models/picodet_lcnet_1_5x_416_coco.pdparams   --eval
/home/aistudio/work/code/train
Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
W0222 13:03:47.626899   739 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0222 13:03:47.633911   739 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[02/22 13:03:52] ppdet.utils.download INFO: Downloading picodet_lcnet_1_5x_416_coco.pdparams from https://paddledet.bj.bcebos.com/models/picodet_lcnet_1_5x_416_coco.pdparams
100%|███████████████████████████████████| 12310/12310 [00:02<00:00, 5771.18KB/s]
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112] in pretrained weight head.head_cls0.bias is unmatched with the shape [35] in model head.head_cls0.bias. And the weight head.head_cls0.bias will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112, 128, 1, 1] in pretrained weight head.head_cls0.weight is unmatched with the shape [35, 128, 1, 1] in model head.head_cls0.weight. And the weight head.head_cls0.weight will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112] in pretrained weight head.head_cls1.bias is unmatched with the shape [35] in model head.head_cls1.bias. And the weight head.head_cls1.bias will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112, 128, 1, 1] in pretrained weight head.head_cls1.weight is unmatched with the shape [35, 128, 1, 1] in model head.head_cls1.weight. And the weight head.head_cls1.weight will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112] in pretrained weight head.head_cls2.bias is unmatched with the shape [35] in model head.head_cls2.bias. And the weight head.head_cls2.bias will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112, 128, 1, 1] in pretrained weight head.head_cls2.weight is unmatched with the shape [35, 128, 1, 1] in model head.head_cls2.weight. And the weight head.head_cls2.weight will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112] in pretrained weight head.head_cls3.bias is unmatched with the shape [35] in model head.head_cls3.bias. And the weight head.head_cls3.bias will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: The shape [112, 128, 1, 1] in pretrained weight head.head_cls3.weight is unmatched with the shape [35, 128, 1, 1] in model head.head_cls3.weight. And the weight head.head_cls3.weight will not be loaded
[02/22 13:03:55] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/.cache/paddle/weights/picodet_lcnet_1_5x_416_coco.pdparams
[02/22 13:03:55] ppdet.engine INFO: Epoch: [0] [0/3] learning_rate: 0.010000 loss_vfl: 1.263152 loss_bbox: 1.064944 loss_dfl: 0.518176 loss: 2.846272 eta: 0:00:20 batch_cost: 0.6679 data_cost: 0.0006 ips: 29.9460 images/s
[02/22 13:04:03] ppdet.engine INFO: Epoch: [1] [0/3] learning_rate: 0.010900 loss_vfl: 1.033099 loss_bbox: 1.136453 loss_dfl: 0.515825 loss: 2.680272 eta: 0:00:49 batch_cost: 1.8156 data_cost: 1.1352 ips: 11.0156 images/s
[02/22 13:04:11] ppdet.engine INFO: Epoch: [2] [0/3] learning_rate: 0.011800 loss_vfl: 0.916189 loss_bbox: 1.148422 loss_dfl: 0.512133 loss: 2.595586 eta: 0:00:44 batch_cost: 1.8745 data_cost: 1.2107 ips: 10.6698 images/s
[02/22 13:04:19] ppdet.engine INFO: Epoch: [3] [0/3] learning_rate: 0.012700 loss_vfl: 0.985893 loss_bbox: 1.105134 loss_dfl: 0.499413 loss: 2.571278 eta: 0:00:41 batch_cost: 1.9723 data_cost: 1.3542 ips: 10.1404 images/s
[02/22 13:04:28] ppdet.engine INFO: Epoch: [4] [0/3] learning_rate: 0.013600 loss_vfl: 0.923104 loss_bbox: 1.060779 loss_dfl: 0.495562 loss: 2.545417 eta: 0:00:36 batch_cost: 2.0552 data_cost: 1.4152 ips: 9.7316 images/s
[02/22 13:04:35] ppdet.engine INFO: Epoch: [5] [0/3] learning_rate: 0.014500 loss_vfl: 0.924571 loss_bbox: 1.001047 loss_dfl: 0.482511 loss: 2.525080 eta: 0:00:30 batch_cost: 2.0249 data_cost: 1.3878 ips: 9.8771 images/s
[02/22 13:04:43] ppdet.engine INFO: Epoch: [6] [0/3] learning_rate: 0.015400 loss_vfl: 0.916189 loss_bbox: 0.956332 loss_dfl: 0.465089 loss: 2.462843 eta: 0:00:24 batch_cost: 2.0367 data_cost: 1.3889 ips: 9.8196 images/s
[02/22 13:04:52] ppdet.engine INFO: Epoch: [7] [0/3] learning_rate: 0.016300 loss_vfl: 0.898742 loss_bbox: 0.872578 loss_dfl: 0.426290 loss: 2.198215 eta: 0:00:18 batch_cost: 2.2244 data_cost: 1.5780 ips: 8.9914 images/s
[02/22 13:05:00] ppdet.engine INFO: Epoch: [8] [0/3] learning_rate: 0.017200 loss_vfl: 0.819227 loss_bbox: 0.769483 loss_dfl: 0.416893 loss: 2.031344 eta: 0:00:12 batch_cost: 2.1973 data_cost: 1.5714 ips: 9.1022 images/s
[02/22 13:05:08] ppdet.engine INFO: Epoch: [9] [0/3] learning_rate: 0.018100 loss_vfl: 0.778409 loss_bbox: 0.735756 loss_dfl: 0.390064 loss: 1.939696 eta: 0:00:06 batch_cost: 2.2483 data_cost: 1.6170 ips: 8.8955 images/s
[02/22 13:05:11] ppdet.utils.checkpoint INFO: Save checkpoint: output/picodet_lcnet_1_5x_416_coco
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[02/22 13:05:16] ppdet.engine INFO: Eval iter: 0
[02/22 13:05:18] ppdet.metrics.metrics INFO: The bbox result is saved to bbox.json.
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[02/22 13:05:18] ppdet.metrics.coco_utils INFO: Start evaluate...
Loading and preparing results...
DONE (t=0.01s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=1.35s).
Accumulating evaluation results...
DONE (t=0.02s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.357
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.652
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.273
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.357
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.420
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.490
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.513
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.513
[02/22 13:05:20] ppdet.engine INFO: Total sample number: 20, averge FPS: 3.9130859681580548
[02/22 13:05:20] ppdet.engine INFO: Best test bbox ap is 0.357.
[02/22 13:05:20] ppdet.utils.checkpoint INFO: Save checkpoint: output/picodet_lcnet_1_5x_416_coco
#评估模型
%cd /home/aistudio/work/code/train/
!python3 eval.py -c picodet_lcnet_1_5x_416_coco.yml
/home/aistudio/work/code/train
Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly
W0221 10:42:54.973261  2954 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0221 10:42:54.978138  2954 device_context.cc:465] device: 0, cuDNN Version: 7.6.
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[02/21 10:42:58] ppdet.utils.checkpoint INFO: Finish loading model weights: output/picodet_lcnet_1_5x_416_coco/best_model.pdparams
[02/21 10:42:59] ppdet.engine INFO: Eval iter: 0
[02/21 10:43:00] ppdet.metrics.metrics INFO: The bbox result is saved to bbox.json.
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[02/21 10:43:00] ppdet.metrics.coco_utils INFO: Start evaluate...
Loading and preparing results...
DONE (t=0.01s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.29s).
Accumulating evaluation results...
DONE (t=0.02s).
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.199
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.471
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.076
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.199
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.279
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.401
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.410
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.410
[02/21 10:43:01] ppdet.engine INFO: Total sample number: 20, averge FPS: 9.823824561177508
#如果需要额外导出serving模型,即导出模型时--export_serving_model=true,那么还需要安装paddle_serving的相关包
!pip install paddle-serving-app==0.6.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
!pip install paddle-serving-client==0.6.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
!pip install paddle-serving-server-gpu==0.6.3.post102 -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting paddle-serving-app==0.6.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/16/51/cbbfd98654e5b5ea1294717f5bef699945881557f623368bd6d321120295/paddle_serving_app-0.6.2-py3-none-any.whl (52 kB)
     |████████████████████████████████| 52 kB 1.6 MB/s             
[?25hCollecting sentencepiece<=0.1.92
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1e/05/8d8d8fc7ef89d36bbdc9b4ff808def3db0dd52658e67f16779eb05ddb558/sentencepiece-0.1.92-cp37-cp37m-manylinux1_x86_64.whl (1.2 MB)
     |████████████████████████████████| 1.2 MB 3.4 MB/s            
[?25hRequirement already satisfied: opencv-python<=4.2.0.32 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-app==0.6.2) (4.1.1.26)
Collecting pyclipper
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c5/fa/2c294127e4f88967149a68ad5b3e43636e94e3721109572f8f17ab15b772/pyclipper-1.3.0.post2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (603 kB)
     |████████████████████████████████| 603 kB 52.7 MB/s            
[?25hRequirement already satisfied: six>=1.10.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-app==0.6.2) (1.16.0)
Requirement already satisfied: shapely in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-app==0.6.2) (1.8.1.post1)
Requirement already satisfied: pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-app==0.6.2) (8.2.0)
Requirement already satisfied: numpy>=1.14.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from opencv-python<=4.2.0.32->paddle-serving-app==0.6.2) (1.19.5)
Installing collected packages: sentencepiece, pyclipper, paddle-serving-app
  Attempting uninstall: sentencepiece
    Found existing installation: sentencepiece 0.1.96
    Uninstalling sentencepiece-0.1.96:
      Successfully uninstalled sentencepiece-0.1.96
Successfully installed paddle-serving-app-0.6.2 pyclipper-1.3.0.post2 sentencepiece-0.1.92
[33mWARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/opt/conda/envs/python35-paddle120-env/bin/python -m pip install --upgrade pip' command.[0m
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting paddle-serving-client==0.6.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c8/88/5fd2e8deabe660a9128b27d27f368ace8590adc39b3528f93c0f0adf9d56/paddle_serving_client-0.6.2-cp37-none-any.whl (42.3 MB)
     |████████████████████████████████| 42.3 MB 195 kB/s            
[?25hCollecting grpcio<=1.33.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7a/46/d08d8a5d0e0449f541fe9e7a226854019a41a4fa41fd14332e55b0e4394f/grpcio-1.33.2-cp37-cp37m-manylinux2014_x86_64.whl (3.8 MB)
     |████████████████████████████████| 3.8 MB 3.7 MB/s            
[?25hRequirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-client==0.6.2) (3.14.0)
Collecting grpcio-tools<=1.33.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/77/1e/91eaee901589ebee04c21df2f551502e7ba946bab99338f77a1f8a4237e1/grpcio_tools-1.33.2-cp37-cp37m-manylinux2014_x86_64.whl (2.5 MB)
     |████████████████████████████████| 2.5 MB 5.9 MB/s            
[?25hRequirement already satisfied: six>=1.10.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-client==0.6.2) (1.16.0)
Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-client==0.6.2) (2.24.0)
Requirement already satisfied: numpy>=1.12 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-client==0.6.2) (1.19.5)
Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->paddle-serving-client==0.6.2) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->paddle-serving-client==0.6.2) (2019.9.11)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->paddle-serving-client==0.6.2) (2.8)
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->paddle-serving-client==0.6.2) (1.25.6)
Installing collected packages: grpcio, grpcio-tools, paddle-serving-client
  Attempting uninstall: grpcio
    Found existing installation: grpcio 1.35.0
    Uninstalling grpcio-1.35.0:
      Successfully uninstalled grpcio-1.35.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.
parl 1.4.1 requires pyzmq==18.1.1, but you have pyzmq 22.3.0 which is incompatible.[0m
Successfully installed grpcio-1.33.2 grpcio-tools-1.33.2 paddle-serving-client-0.6.2
[33mWARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/opt/conda/envs/python35-paddle120-env/bin/python -m pip install --upgrade pip' command.[0m
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting paddle-serving-server-gpu==0.6.3.post102
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c2/08/cb57da763defad1649a81ef234759f94f5b7f2afb68f74f9e171f5472d07/paddle_serving_server_gpu-0.6.3.post102-py3-none-any.whl (8.2 MB)
     |████████████████████████████████| 8.2 MB 519 kB/s            
[?25hRequirement already satisfied: grpcio<=1.33.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-server-gpu==0.6.3.post102) (1.33.2)
Collecting MarkupSafe==1.1.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c2/37/2e4def8ce3739a258998215df907f5815ecd1af71e62147f5eea2d12d4e8/MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_x86_64.whl (33 kB)
Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-server-gpu==0.6.3.post102) (1.1.1)
Collecting click==7.1.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82 kB)
     |████████████████████████████████| 82 kB 1.4 MB/s             
[?25hCollecting Jinja2==2.11.3
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7e/c2/1eece8c95ddbc9b1aeb64f5783a9e07a286de42191b7204d67b7496ddf35/Jinja2-2.11.3-py2.py3-none-any.whl (125 kB)
     |████████████████████████████████| 125 kB 4.4 MB/s            
[?25hRequirement already satisfied: itsdangerous==1.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-server-gpu==0.6.3.post102) (1.1.0)
Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-server-gpu==0.6.3.post102) (3.14.0)
Collecting Werkzeug==1.0.1
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
     |████████████████████████████████| 298 kB 3.7 MB/s            
[?25hRequirement already satisfied: grpcio-tools<=1.33.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-server-gpu==0.6.3.post102) (1.33.2)
Requirement already satisfied: pyyaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-server-gpu==0.6.3.post102) (5.1.2)
Collecting func-timeout
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b3/0d/bf0567477f7281d9a3926c582bfef21bff7498fc0ffd3e9de21811896a0b/func_timeout-4.3.5.tar.gz (44 kB)
     |████████████████████████████████| 44 kB 3.3 MB/s             
[?25h  Preparing metadata (setup.py) ... [?25ldone
[?25hRequirement already satisfied: six>=1.10.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddle-serving-server-gpu==0.6.3.post102) (1.16.0)
Building wheels for collected packages: func-timeout
  Building wheel for func-timeout (setup.py) ... [?25ldone
[?25h  Created wheel for func-timeout: filename=func_timeout-4.3.5-py3-none-any.whl size=15077 sha256=6001cb8b3998d4816cd583779d540b843aec7558bf4e90d629f2df4445958dc6
  Stored in directory: /home/aistudio/.cache/pip/wheels/ea/6b/56/b7bcacbd1bd8cd29883e7f7a29cbd98b87b2d789b25bae5563
Successfully built func-timeout
Installing collected packages: MarkupSafe, Werkzeug, Jinja2, click, func-timeout, paddle-serving-server-gpu
  Attempting uninstall: MarkupSafe
    Found existing installation: MarkupSafe 2.0.1
    Uninstalling MarkupSafe-2.0.1:
      Successfully uninstalled MarkupSafe-2.0.1
  Attempting uninstall: Werkzeug
    Found existing installation: Werkzeug 0.16.0
    Uninstalling Werkzeug-0.16.0:
      Successfully uninstalled Werkzeug-0.16.0
  Attempting uninstall: Jinja2
    Found existing installation: Jinja2 2.11.0
    Uninstalling Jinja2-2.11.0:
      Successfully uninstalled Jinja2-2.11.0
  Attempting uninstall: click
    Found existing installation: Click 7.0
    Uninstalling Click-7.0:
      Successfully uninstalled Click-7.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.
parl 1.4.1 requires pyzmq==18.1.1, but you have pyzmq 22.3.0 which is incompatible.[0m
Successfully installed Jinja2-2.11.3 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 func-timeout-4.3.5 paddle-serving-server-gpu-0.6.3.post102
[33mWARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/opt/conda/envs/python35-paddle120-env/bin/python -m pip install --upgrade pip' command.[0m
#导出模型
%cd /home/aistudio/work/code/train/
!python export_model.py  --export_serving_model=true -c picodet_lcnet_1_5x_416_coco.yml --output_dir=./output_inference/
/home/aistudio/work/code/train
Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly
[02/22 13:06:15] ppdet.utils.checkpoint INFO: Finish loading model weights: output/picodet_lcnet_1_5x_416_coco/best_model.pdparams
[02/22 13:06:15] ppdet.engine INFO: Export inference config file to ./output_inference/picodet_lcnet_1_5x_416_coco/infer_cfg.yml
W0222 13:06:18.468817  2012 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0222 13:06:18.468895  2012 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[02/22 13:06:21] ppdet.engine INFO: Export model and saved in ./output_inference/picodet_lcnet_1_5x_416_coco

导出后会生成serving_server和serving_client文件夹,使用对应的py文件(文件中完成前置处理以及后置处理功能)以及配置文件完成主体检测模型的部署。

上述内容就是使用coco数据集训练一个picodet模型的完整流程

部署方式可以如图:

部署的config.yml文件内容如图所示

部署的web_service.py文件内容如图所示

%cd /home/aistudio/work/code/train/output_inference/picodet_lcnet_1_5x_416_coco/
%mv serving_server/ /home/aistudio/work/code/picodet_lcnet_1_5x_416_coco/
%mv serving_client/ /home/aistudio/work/code/picodet_lcnet_1_5x_416_coco/
/home/aistudio/work/code/train/output_inference/picodet_lcnet_1_5x_416_coco
#模型部署
%cd /home/aistudio/work/code/picodet_lcnet_1_5x_416_coco/
!python3 web_service.py
/home/aistudio/work/code/picodet_lcnet_1_5x_416_coco
2022/02/21 10:43:36 start proxy service
W0221 10:43:39.671136  3379 analysis_predictor.cc:795] The one-time configuration of analysis predictor failed, which may be due to native predictor called first and its configurations taken effect.
I0221 10:43:39.728690  3379 analysis_predictor.cc:576] TensorRT subgraph engine is enabled
I0221 10:43:39.728780  3379 analysis_predictor.cc:665] ir_optim is turned off, no IR pass will be executed
[1m[35m--- Running analysis [ir_graph_build_pass][0m
[1m[35m--- Running analysis [ir_graph_clean_pass][0m
[1m[35m--- Running analysis [ir_analysis_pass][0m
[1m[35m--- Running analysis [ir_params_sync_among_devices_pass][0m
I0221 10:43:39.807039  3379 ir_params_sync_among_devices_pass.cc:45] Sync params from CPU to GPU
[1m[35m--- Running analysis [adjust_cudnn_workspace_size_pass][0m
[1m[35m--- Running analysis [inference_op_replace_pass][0m
[1m[35m--- Running analysis [memory_optimize_pass][0m
I0221 10:43:39.855954  3379 memory_optimize_pass.cc:216] Cluster name : hardswish_79.tmp_0  size: 102400
I0221 10:43:39.856009  3379 memory_optimize_pass.cc:216] Cluster name : hardswish_53.tmp_0  size: 1228800
I0221 10:43:39.856015  3379 memory_optimize_pass.cc:216] Cluster name : batch_norm_2.tmp_3  size: 19660800
I0221 10:43:39.856031  3379 memory_optimize_pass.cc:216] Cluster name : conv2d_115.tmp_0  size: 2457600
I0221 10:43:39.856045  3379 memory_optimize_pass.cc:216] Cluster name : hardswish_56.tmp_0  size: 204800
I0221 10:43:39.856058  3379 memory_optimize_pass.cc:216] Cluster name : conv2d_105.tmp_0  size: 19660800
I0221 10:43:39.856070  3379 memory_optimize_pass.cc:216] Cluster name : batch_norm_61.tmp_0  size: 512
I0221 10:43:39.856081  3379 memory_optimize_pass.cc:216] Cluster name : depthwise_conv2d_1.tmp_0  size: 4915200
I0221 10:43:39.856084  3379 memory_optimize_pass.cc:216] Cluster name : image  size: 4915200
[1m[35m--- Running analysis [ir_graph_to_program_pass][0m
I0221 10:43:40.090010  3379 analysis_predictor.cc:714] ======= optimize end =======
I0221 10:43:40.105052  3379 naive_executor.cc:98] ---  skip [feed], feed -> image
I0221 10:43:40.113319  3379 naive_executor.cc:98] ---  skip [transpose_0.tmp_0], fetch -> fetch
I0221 10:43:40.113376  3379 naive_executor.cc:98] ---  skip [transpose_1.tmp_0], fetch -> fetch
I0221 10:43:40.113399  3379 naive_executor.cc:98] ---  skip [transpose_2.tmp_0], fetch -> fetch
I0221 10:43:40.113412  3379 naive_executor.cc:98] ---  skip [transpose_3.tmp_0], fetch -> fetch
I0221 10:43:40.113425  3379 naive_executor.cc:98] ---  skip [transpose_4.tmp_0], fetch -> fetch
I0221 10:43:40.113430  3379 naive_executor.cc:98] ---  skip [transpose_5.tmp_0], fetch -> fetch
I0221 10:43:40.113445  3379 naive_executor.cc:98] ---  skip [transpose_6.tmp_0], fetch -> fetch
I0221 10:43:40.113458  3379 naive_executor.cc:98] ---  skip [transpose_7.tmp_0], fetch -> fetch
^C
Traceback (most recent call last):
  File "web_service.py", line 116, in <module>
    ppyolo_mbv3_service.run_service()
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle_serving_server/web_service.py", line 69, in run_service
    self._server.run_server()
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle_serving_server/pipeline/pipeline_server.py", line 312, in run_server
    server.wait_for_termination()
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/grpc/_server.py", line 979, in wait_for_termination
    timeout=timeout)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/grpc/_common.py", line 141, in wait
    _wait_once(wait_fn, MAXIMUM_WAIT_TIMEOUT, spin_cb)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/grpc/_common.py", line 106, in _wait_once
    wait_fn(timeout=timeout)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 552, in wait
    signaled = self._cond.wait(timeout)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 300, in wait
    gotit = waiter.acquire(True, timeout)
KeyboardInterrupt


--------------------------------------
C++ Traceback (most recent call last):
--------------------------------------
No stack trace in paddle, may be caused by external reasons.

----------------------
Error Message Summary:
----------------------
FatalError: `Termination signal` is detected by the operating system.
  [TimeInfo: *** Aborted at 1645411431 (unix time) try "date -d @1645411431" if you are using GNU date ***]
  [SignalInfo: *** SIGTERM (@0x3e800000cb4) received by PID 3379 (TID 0x7fde098b2700) from PID 3252 ***]
#请求测试
%cd /home/aistudio/work/code/picodet_lcnet_1_5x_416_coco/
!python3 pipeline_http_client.py
/home/aistudio/work/code/picodet_lcnet_1_5x_416_coco
{'err_no': 0, 'err_msg': '', 'key': [], 'value': []}

由于本流程只是教程,因此模型训练只使用了极少部分的数据集以及训练轮次,因此请求不会有任何结果,在实际使用过程中需要大量的数据集和训练时间,其模型请求结果如下。

图像检索库生成与部署

在目标检测模型部署完毕后电瓶车入室检测的功能便可投入使用,但为了提高整体的准确度减少误报则还需要一个额外的检索方式。这里采用了PaddleClas下图像识别中的轻量级通用识别模型general_PPLCNet_x2_5_lite_v1.0_infer,首先根据已有图片集生成格式与下图格式相同的txt的文件,随后在PaddleClas的deploy文件夹下输入命令即可用数据集生成相应的索引库,其中IndexProcess.data_file是下图txt文件的名字,IndexProcess.index_dir是生成 索引库的名字,具体可以查看PaddleClas图像识别快速开始的建立新的索引库部分。(注意,确保build_general.yaml中rec_inference_model_dir路径的模型存在)

#下载模型并转换为serving模型
%cd /home/aistudio/work/code/
!wget -P models/ https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar
%cd models
!tar -xf general_PPLCNet_x2_5_lite_v1.0_infer.tar
!python3 -m paddle_serving_client.convert --dirname ./general_PPLCNet_x2_5_lite_v1.0_infer/ --model_filename inference.pdmodel  --params_filename inference.pdiparams --serving_server ./general_PPLCNet_x2_5_lite_v1.0_serving/  --serving_client ./general_PPLCNet_x2_5_lite_v1.0_client/
%cp  -r ./general_PPLCNet_x2_5_lite_v1.0_serving ../general_PPLCNet_x2_5_lite_v1.0/
/home/aistudio/work/code
--2022-02-22 13:27:22--  https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/rec/models/inference/general_PPLCNet_x2_5_lite_v1.0_infer.tar
Resolving paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com)... 182.61.200.195, 182.61.200.229, 2409:8c04:1001:1002:0:ff:b001:368a
Connecting to paddle-imagenet-models-name.bj.bcebos.com (paddle-imagenet-models-name.bj.bcebos.com)|182.61.200.195|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 34242560 (33M) [application/x-tar]
Saving to: ‘models/general_PPLCNet_x2_5_lite_v1.0_infer.tar’

general_PPLCNet_x2_ 100%[===================>]  32.66M  24.2MB/s    in 1.3s    

2022-02-22 13:27:24 (24.2 MB/s) - ‘models/general_PPLCNet_x2_5_lite_v1.0_infer.tar’ saved [34242560/34242560]

/home/aistudio/work/code/models
%cd /home/aistudio/data/data128448/
!unzip -q index_motorcycle.zip #解压数据集
/home/aistudio/data/data128448
replace index_motorcycle/人/0-10182.jpg? [y]es, [n]o, [A]ll, [N]one, [r]ename: ^C
%cd /home/aistudio/work/code/
!python make_label.py #数据集分类
!python python/build_gallery.py -c build_gallery/build_general.yaml -o IndexProcess.data_file="./index_label.txt" -o IndexProcess.index_dir="index_result" #生成检索库
/home/aistudio/work/code
/home/aistudio/data/data128448/index_motorcycle/摩托车/
/home/aistudio/data/data128448/index_motorcycle/人/
/home/aistudio/data/data128448/index_motorcycle/其他杂物/
/home/aistudio/data/data128448/index_motorcycle/自行车/
2022-02-22 13:27:50 INFO: 
===========================================================
==        PaddleClas is powered by PaddlePaddle !        ==
===========================================================
==                                                       ==
==   For more info please go to the following website.   ==
==                                                       ==
==       https://github.com/PaddlePaddle/PaddleClas      ==
===========================================================

2022-02-22 13:27:50 INFO: Global : 
2022-02-22 13:27:50 INFO:     batch_size : 32
2022-02-22 13:27:50 INFO:     cpu_num_threads : 10
2022-02-22 13:27:50 INFO:     enable_benchmark : True
2022-02-22 13:27:50 INFO:     enable_mkldnn : True
2022-02-22 13:27:50 INFO:     enable_profile : False
2022-02-22 13:27:50 INFO:     gpu_mem : 8000
2022-02-22 13:27:50 INFO:     ir_optim : True
2022-02-22 13:27:50 INFO:     rec_inference_model_dir : ./models/general_PPLCNet_x2_5_lite_v1.0_infer
2022-02-22 13:27:50 INFO:     use_fp16 : False
2022-02-22 13:27:50 INFO:     use_gpu : False
2022-02-22 13:27:50 INFO:     use_tensorrt : False
2022-02-22 13:27:50 INFO: IndexProcess : 
2022-02-22 13:27:50 INFO:     data_file : ./index_label.txt
2022-02-22 13:27:50 INFO:     delimiter : 	
2022-02-22 13:27:50 INFO:     dist_type : IP
2022-02-22 13:27:50 INFO:     embedding_size : 512
2022-02-22 13:27:50 INFO:     image_root : 
2022-02-22 13:27:50 INFO:     index_dir : index_result
2022-02-22 13:27:50 INFO:     index_method : HNSW32
2022-02-22 13:27:50 INFO:     index_operation : new
2022-02-22 13:27:50 INFO: RecPostProcess : None
2022-02-22 13:27:50 INFO: RecPreProcess : 
2022-02-22 13:27:50 INFO:     transform_ops : 
2022-02-22 13:27:50 INFO:         ResizeImage : 
2022-02-22 13:27:50 INFO:             size : 224
2022-02-22 13:27:50 INFO:         NormalizeImage : 
2022-02-22 13:27:50 INFO:             mean : [0.485, 0.456, 0.406]
2022-02-22 13:27:50 INFO:             order : 
2022-02-22 13:27:50 INFO:             scale : 0.00392157
2022-02-22 13:27:50 INFO:             std : [0.229, 0.224, 0.225]
2022-02-22 13:27:50 INFO:         ToCHWImage : None
100%|█████████████████████████████████████████| 144/144 [00:05<00:00, 25.24it/s]
2022-02-22 13:27:56 WARNING: The HNSW32 method dose not support 'remove' operation

索引库生成完成后接下来便是的部署,这里我们用到的模型general_PPLCNet_x2_5_lite_v1.0_infer,使用paddleClas中的两个文件便可以部署.

但由于我们只使用了其中的图像检索功能,因此需要将recognization_web_service.py的部分代码进行修改,原始文件在飞桨的github上(https://github.com/PaddlePaddle/PaddleClas/blob/release/2.3/deploy/paddleserving/recognition/recognition_web_service.py),用于部署图像检索服务的文件在/home/aistudio/work/code/general_PPLCNet_x2_5_lite_v1.0/文件夹下。

修改后的recognization_web_service.py代码如下:

config_onlyrec.yml的内容如下:

%cd /home/aistudio/work/code/
%mv index_result/ general_PPLCNet_x2_5_lite_v1.0/
/home/aistudio/work/code
%cd /home/aistudio/work/code/general_PPLCNet_x2_5_lite_v1.0/
!python recognition_web_service_onlyrec.py #启动服务
/home/aistudio/work/code/general_PPLCNet_x2_5_lite_v1.0
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle_serving_server/pipeline/pipeline_server.py:342: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  conf = yaml.load(f.read())
config use_encryption model here None
2022/02/22 13:28:11 start proxy service
W0222 13:28:13.646667  5999 analysis_predictor.cc:795] The one-time configuration of analysis predictor failed, which may be due to native predictor called first and its configurations taken effect.
I0222 13:28:13.665211  5999 analysis_predictor.cc:665] ir_optim is turned off, no IR pass will be executed
[1m[35m--- Running analysis [ir_graph_build_pass][0m
[1m[35m--- Running analysis [ir_graph_clean_pass][0m
[1m[35m--- Running analysis [ir_analysis_pass][0m
[1m[35m--- Running analysis [ir_params_sync_among_devices_pass][0m
I0222 13:28:13.716022  5999 ir_params_sync_among_devices_pass.cc:45] Sync params from CPU to GPU
[1m[35m--- Running analysis [adjust_cudnn_workspace_size_pass][0m
[1m[35m--- Running analysis [inference_op_replace_pass][0m
[1m[35m--- Running analysis [memory_optimize_pass][0m
I0222 13:28:13.745045  5999 memory_optimize_pass.cc:216] Cluster name : x  size: 602112
I0222 13:28:13.745075  5999 memory_optimize_pass.cc:216] Cluster name : depthwise_conv2d_2.tmp_0  size: 2007040
I0222 13:28:13.745079  5999 memory_optimize_pass.cc:216] Cluster name : batch_norm_24.tmp_1  size: 5120
I0222 13:28:13.745083  5999 memory_optimize_pass.cc:216] Cluster name : conv2d_33.tmp_0  size: 4014080
I0222 13:28:13.745087  5999 memory_optimize_pass.cc:216] Cluster name : batch_norm_2.tmp_3  size: 4014080
[1m[35m--- Running analysis [ir_graph_to_program_pass][0m
I0222 13:28:13.786020  5999 analysis_predictor.cc:714] ======= optimize end =======
I0222 13:28:13.788327  5999 naive_executor.cc:98] ---  skip [feed], feed -> x
I0222 13:28:13.789907  5999 naive_executor.cc:98] ---  skip [save_infer_model/scale_0.tmp_1], fetch -> fetch
W0222 13:28:17.437884  5999 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.0, Runtime API Version: 10.1
W0222 13:28:17.442231  5999 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[[1.0000004  0.6330568  0.5747858  0.5617034  0.55175585]]
%cd /home/aistudio/work/code/general_PPLCNet_x2_5_lite_v1.0/
ode/general_PPLCNet_x2_5_lite_v1.0/
!python pipeline_http_client.py #请求测试
/home/aistudio/work/code/general_PPLCNet_x2_5_lite_v1.0
0
{'err_no': 0, 'err_msg': '', 'key': ['result'], 'value': ["[{'rec_docs': '摩托车', 'rec_scores': 1.0000004}]"]}

由于使用的原图片请求,因此返回的置信度为1.0,在实际使用场景中同样也有着较高的置信度,结果如图所示。

请点击此处查看本环境基本用法.

Please click here for more detailed instructions.

Logo

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

更多推荐