基于PaddleDetection的PCB瑕疵检测
本项目使用PaddleDetection做PCB电路板瑕疵检测,利用Cascade FasterRCNN模型。
基于PaddleDetection的PCB瑕疵检测
数据集与框架介绍
-
印刷电路板(PCB)瑕疵数据集:数据下载链接,是一个公共的合成PCB数据集,由北京大学发布,其中包含1386张图像以及6种缺陷(缺失孔,鼠咬伤,开路,短路,杂散,伪铜),用于检测、分类和配准任务。我们选取了其中适用于检测任务的693张图像,随机选择593张图像作为训练集,100张图像作为验证集。
-
PaddleDetection:飞桨推出的PaddleDetection是端到端目标检测开发套件,旨在帮助开发者更快更好地完成检测模型的训练、精度速度优化到部署全流程。该框架中提供了丰富的数据增强、网络组件、损失函数等模块,集成了模型压缩和跨平台高性能部署能力。目前基于PaddleDetection已经完成落地的项目涉及工业质检、遥感图像检测、无人巡检等多个领域。
- awesome-DeepLearning:一站式深度学习在线百科,内容涵盖零基础入门深度学习、产业实践深度学习、特色课程;深度学习百问、产业实践(开发中) 等等。从理论到实践,从科研到产业应用,各类学习材料一应俱全,旨在帮助开发者高效地学习和掌握深度学习知识,快速成为AI跨界人才。
任务详情
利用RCNN系列算法完成印刷电路板瑕疵检测。评估方法是使用IoU=0.5,area=all的mAP作为评价指标,得分=mAP * 100,范围[0,100]。
数据准备
首先将印刷电路板(PCB)瑕疵数据集与PaddleDetection代码解压到~/work/
目录中:
# 解压数据集
!tar -xf /home/aistudio/data/data52914/PCB_DATASET.tar -C ~/work/
# 解压PaddleDetection源码
!unzip /home/aistudio/data/data103033/PaddleDetection-release-2.1.zip -d ~/work/
/home/aistudio/work/PaddleDetection-release-2.1/static/docs/advanced_tutorials/slim/prune/SENSITIVE.md -> ../../../../slim/sensitive/README.md
环境安装
进行训练前需要安装PaddleDetection所需的依赖包,执行以下命令即可安装:
%cd ~/work/PaddleDetection-release-2.1/
! pip install -r requirements.txt
! pip install pycocotools
/home/aistudio/work/PaddleDetection-release-2.1
Looking in indexes: https://mirror.baidu.com/pypi/simple/
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (4.36.1)
Collecting typeguard (from -r requirements.txt (line 2))
Downloading https://mirror.baidu.com/pypi/packages/a0/88/2a1613174e7d05540358b2f19881f369bfe6ba737f0a673177e69eb623df/typeguard-2.12.1-py3-none-any.whl
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 (from -r requirements.txt (line 6))
[?25l Downloading https://mirror.baidu.com/pypi/packages/98/f8/db4d3426a1aba9d5dfcc83ed5a3e2935d2b1deb73d350642931791a61c37/Shapely-1.7.1-cp37-cp37m-manylinux1_x86_64.whl (1.0MB)
[K |████████████████████████████████| 1.0MB 22.9MB/s eta 0:00:01
[?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 (from -r requirements.txt (line 8))
Downloading https://mirror.baidu.com/pypi/packages/9b/c4/4a21174f32f8a7e1104798c445dacdc1d4df86f2f26722767034e4de4bff/terminaltables-3.1.0.tar.gz
Requirement already satisfied: Cython in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (0.29)
Collecting pycocotools (from -r requirements.txt (line 10))
Downloading https://mirror.baidu.com/pypi/packages/de/df/056875d697c45182ed6d2ae21f62015896fdb841906fe48e7268e791c467/pycocotools-2.0.2.tar.gz
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 (from -r requirements.txt (line 13))
[?25l Downloading https://mirror.baidu.com/pypi/packages/bf/64/d9fb6a75b15e783952b2fec6970f033462e67db32dc43dfbb404c14e91c2/lap-0.4.0.tar.gz (1.5MB)
[K |████████████████████████████████| 1.5MB 20.2MB/s eta 0:00:01
[?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 (from -r requirements.txt (line 15))
[?25l Downloading https://mirror.baidu.com/pypi/packages/9c/28/9c3bc8e2a87f4c9e7b04ab72856ec7f9895a66681a65973ffaf9562ef879/motmetrics-1.2.0-py3-none-any.whl (151kB)
[K |████████████████████████████████| 153kB 59.8MB/s eta 0:00:01
[?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)
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)) (3.8.2)
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: 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: 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.15.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: 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: 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: numpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.1.0->-r requirements.txt (line 3)) (1.20.3)
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: 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: 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)) (7.1.2)
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.22.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: 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 xmltodict>=0.12.0 (from motmetrics->-r requirements.txt (line 15))
Downloading https://mirror.baidu.com/pypi/packages/28/fd/30d5c1d3ac29ce229f6bdc40bbc20b28f716e8b363140c26eff19122d8a5/xmltodict-0.12.0-py2.py3-none-any.whl
Collecting flake8-import-order (from motmetrics->-r requirements.txt (line 15))
Downloading https://mirror.baidu.com/pypi/packages/ab/52/cf2d6e2c505644ca06de2f6f3546f1e4f2b7be34246c9e0757c6048868f9/flake8_import_order-0.18.1-py2.py3-none-any.whl
Collecting pytest-benchmark (from motmetrics->-r requirements.txt (line 15))
[?25l Downloading https://mirror.baidu.com/pypi/packages/2c/60/423a63fb190a0483d049786a121bd3dfd7d93bb5ff1bb5b5cd13e5df99a7/pytest_benchmark-3.4.1-py2.py3-none-any.whl (50kB)
[K |████████████████████████████████| 51kB 14.7MB/s eta 0:00:01
[?25hCollecting pytest (from motmetrics->-r requirements.txt (line 15))
[?25l Downloading https://mirror.baidu.com/pypi/packages/40/76/86f886e750b81a4357b6ed606b2bcf0ce6d6c27ad3c09ebf63ed674fc86e/pytest-6.2.5-py3-none-any.whl (280kB)
[K |████████████████████████████████| 286kB 22.5MB/s eta 0:00:01
[?25hRequirement 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: 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: importlib-metadata; python_version < "3.8" 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.23)
Requirement already satisfied: pyflakes<2.3.0,>=2.2.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.2.0)
Requirement already satisfied: pycodestyle<2.7.0,>=2.6.0a1 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.6.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: pytz>=2017.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pandas->visualdl>=2.1.0->-r requirements.txt (line 3)) (2019.3)
Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pandas->visualdl>=2.1.0->-r requirements.txt (line 3)) (2.8.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: 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)) (2.4.2)
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: 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: Jinja2>=2.5 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.10.1)
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: 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: 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: 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: 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: 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: 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: chardet<3.1.0,>=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: idna<2.9,>=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: 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: 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: 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: 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)
Collecting py-cpuinfo (from pytest-benchmark->motmetrics->-r requirements.txt (line 15))
[?25l Downloading https://mirror.baidu.com/pypi/packages/e6/ba/77120e44cbe9719152415b97d5bfb29f4053ee987d6cb63f55ce7d50fadc/py-cpuinfo-8.0.0.tar.gz (99kB)
[K |████████████████████████████████| 102kB 23.8MB/s ta 0:00:01
[?25hRequirement 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)) (19.2.0)
Collecting py>=1.8.2 (from pytest->motmetrics->-r requirements.txt (line 15))
[?25l Downloading https://mirror.baidu.com/pypi/packages/67/32/6fe01cfc3d1a27c92fdbcdfc3f67856da8cbadf0dd9f2e18055202b2dc62/py-1.10.0-py2.py3-none-any.whl (97kB)
[K |████████████████████████████████| 102kB 60.6MB/s ta 0:00:01
[?25hRequirement already satisfied: packaging in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pytest->motmetrics->-r requirements.txt (line 15)) (20.9)
Collecting iniconfig (from pytest->motmetrics->-r requirements.txt (line 15))
Downloading https://mirror.baidu.com/pypi/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl
Requirement 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)
Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata; python_version < "3.8"->flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (0.6.0)
Requirement already satisfied: MarkupSafe>=0.23 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.5->Flask-Babel>=1.0.0->visualdl>=2.1.0->-r requirements.txt (line 3)) (1.1.1)
Requirement already satisfied: more-itertools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from zipp>=0.5->importlib-metadata; python_version < "3.8"->flake8>=3.7.9->visualdl>=2.1.0->-r requirements.txt (line 3)) (7.2.0)
Building wheels for collected packages: terminaltables, pycocotools, lap, py-cpuinfo
Building wheel for terminaltables (setup.py) ... [?25ldone
[?25h Created wheel for terminaltables: filename=terminaltables-3.1.0-cp37-none-any.whl size=15356 sha256=3e020412ea51a5a70f14016559e42307499411eddb79271d23c883251f85632e
Stored in directory: /home/aistudio/.cache/pip/wheels/38/ce/e7/382f63c6888f05daac9bffbdea230dc620ceda20bedb449dce
Building wheel for pycocotools (setup.py) ... [?25ldone
[?25h Created wheel for pycocotools: filename=pycocotools-2.0.2-cp37-cp37m-linux_x86_64.whl size=278368 sha256=7ceb48444d91e3428bc275f03bee4ab6936ce32e8a4f0cf34609f818c3c3fd63
Stored in directory: /home/aistudio/.cache/pip/wheels/fb/44/67/8baa69040569b1edbd7776ec6f82c387663e724908aaa60963
Building wheel for lap (setup.py) ... [?25ldone
[?25h Created wheel for lap: filename=lap-0.4.0-cp37-cp37m-linux_x86_64.whl size=1593866 sha256=7c222e7fc33ed2a6503efdf9f5c228ca44cfef9a39660db1e6249ada6a15b7a4
Stored in directory: /home/aistudio/.cache/pip/wheels/83/50/a9/e3660736bfb1fb50598b822551bb8c7ff04f1a4ecf69c42277
Building wheel for py-cpuinfo (setup.py) ... [?25ldone
[?25h Created wheel for py-cpuinfo: filename=py_cpuinfo-8.0.0-cp37-none-any.whl size=22245 sha256=9155c96ba67f657679fe2ac98b343d82b603df7a78fd02d0fe238f3319d92f52
Stored in directory: /home/aistudio/.cache/pip/wheels/a5/77/fe/bd2fe25844956ae1e2353d7b2ffc9a90ab8c3c1b4b0862e1e9
Successfully built terminaltables pycocotools lap py-cpuinfo
Installing collected packages: typeguard, shapely, terminaltables, pycocotools, lap, xmltodict, flake8-import-order, py-cpuinfo, py, iniconfig, pytest, pytest-benchmark, motmetrics
Successfully installed flake8-import-order-0.18.1 iniconfig-1.1.1 lap-0.4.0 motmetrics-1.2.0 py-1.10.0 py-cpuinfo-8.0.0 pycocotools-2.0.2 pytest-6.2.5 pytest-benchmark-3.4.1 shapely-1.7.1 terminaltables-3.1.0 typeguard-2.12.1 xmltodict-0.12.0
Looking in indexes: https://mirror.baidu.com/pypi/simple/
Requirement already satisfied: pycocotools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (2.0.2)
Requirement already satisfied: setuptools>=18.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools) (56.2.0)
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: cython>=0.27.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools) (0.29)
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.0)
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.15.0)
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: 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: 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) (2.4.2)
Requirement already satisfied: numpy>=1.7.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib>=2.1.0->pycocotools) (1.20.3)
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)
数据集分析
在调整配置之前,请首先对数据有一个大概的了解。由于是个小数据,这里只简单分析了几项跟配置息息相关的内容。
import json
from collections import defaultdict
import matplotlib.pyplot as plt
%matplotlib inline
with open("/home/aistudio/work/PCB_DATASET/Annotations/train.json") as f:
data = json.load(f)
imgs = {}
for img in data['images']:
imgs[img['id']] = {
'h': img['height'],
'w': img['width'],
'area': img['height'] * img['width'],
}
hw_ratios = []
area_ratios = []
label_count = defaultdict(int)
for anno in data['annotations']:
hw_ratios.append(anno['bbox'][3]/anno['bbox'][2])
area_ratios.append(anno['area']/imgs[anno['image_id']]['area'])
label_count[anno['category_id']] += 1
label_count, len(data['annotations']) / len(data['images'])
(defaultdict(int, {3: 399, 5: 416, 2: 435, 6: 447, 4: 412, 1: 418}),
4.261382799325464)
- 从标签来看,总共6个类别。
- 各类别之间的框数量相对较平均,不需要调整默认的损失函数。(如果类别之间相差较大,建议调整损失函数,如BalancedL1Loss)
- 平均每张图的框数量在4个左右,属于比较稀疏的检测,使用默认的keep_top_k即可。
- 多类别检测后处理使用MultiClassNMS。
plt.hist(hw_ratios, bins=100, range=[0, 2])
plt.show()
这是真实框的宽高比,可以看到大部分集中在1.0左右,但也有部分在0.51之间,少部分在1.252.0之间。虽说anchor会进行回归得到更加准确的框,但是一开始给定一个相对靠近的anchor宽高比会让回归更加轻松。这里使用默认的 [0.5, 1, 2]即可。
plt.hist(area_ratios, bins=100, range=[0, 0.005])
plt.show()
这是真实框在原图的大小比例,可以看到大部分框只占到了原图的0.1%,甚至更小,因此基本都是很小的目标,这个也可以直接看一下原图和真实框就能发现。所以在初始的anchor_size设计时需要考虑到这一点,我这里anchor_size是从8开始的,也可以考虑从4开始,应该都可以的。
在本实验中,anchor_sizes设置为:anchor_sizes: [[8],[16],[32], [64], [128]]
,在work/PaddleDetection-release-2.1/configs/cascade_rcnn/_base_/cascade_rcnn_r50_fpn.yml
文件中。
数据配置
本实验用到的数据配置文件在work/PaddleDetection-release-2.1/configs/datasets/coco_detection.yml
中,具体修改后的内容如下:
metric: COCO
num_classes: 6 # 不包括背景
TrainDataset:
!COCODataSet
image_dir: images
anno_path: Annotations/train.json
dataset_dir: /home/aistudio/work/PCB_DATASET
data_fields: ['image', 'gt_bbox', 'gt_class', 'is_crowd']
EvalDataset:
!COCODataSet
image_dir: images
anno_path: Annotations/val.json
dataset_dir: /home/aistudio/work/PCB_DATASET
TestDataset:
!ImageFolder
anno_path: /home/aistudio/work/PCB_DATASET/Annotations/val.json
其他配置的调整
-
预训练模型:
建议直接到PaddleDection的MODEL_ZOO文档中找相关的模型参数。预训练能大大缩短收敛时间。本实验预训练模型参数为https://paddledet.bj.bcebos.com/models/pretrained/ResNet50_cos_pretrained.pdparams/ -
FPN通道数:
本实验FPN模块通道数默认是256通道,训练时间较长,为了压缩这个训练时间,我将通道数缩减为了64。具体修改为work/PaddleDetection-release-2.1/configs/cascade_rcnn/_base_/cascade_rcnn_r50_fpn.yml
文件中FPN: out_channel: 64
和RPNHead: rpn_target_assign: batch_size_per_im: 64
。 -
学习率和衰减:
学习率按照默认的学习率除以8,即0.000125。衰减轮数milestones一般配置在max_iters的2/3和8/9处,尽量靠后。具体对应的配置文件为work/PaddleDetection-release-2.1/configs/cascade_rcnn/_base_/optimizer_1x.yml
,修改LearningRate: base_lr: 0.00125
。 -
数据增强:
这里使用的数据增强方式有RandomResize、RandomFlip、NormalizeImage。
# 训练脚本
!CUDA_VISIBLE_DEVICES=0
!python3.7 -u tools/train.py -c configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.yml --eval
/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
/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/ops.py:542: DeprecationWarning: invalid escape sequence \_
"""
/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/ops.py:1375: DeprecationWarning: invalid escape sequence \l
"""
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
loading annotations into memory...
Done (t=0.09s)
creating index...
index created!
W0913 19:13:46.472611 674 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0913 19:13:46.478024 674 device_context.cc:422] device: 0, cuDNN Version: 7.6.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
[09/13 19:13:49] ppdet.utils.download INFO: Downloading ResNet50_cos_pretrained.pdparams from https://paddledet.bj.bcebos.com/models/pretrained/ResNet50_cos_pretrained.pdparams
100%|██████████████████████████████████| 92063/92063 [00:01<00:00, 65819.16KB/s]
[09/13 19:13:51] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/.cache/paddle/weights/ResNet50_cos_pretrained.pdparams
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[09/13 19:13:51] ppdet.engine INFO: Epoch: [0] [ 0/593] learning_rate: 0.000001 loss_rpn_cls: 0.697280 loss_rpn_reg: 0.031664 loss_bbox_cls_stage0: 0.735053 loss_bbox_reg_stage0: 0.000138 loss_bbox_cls_stage1: 0.648889 loss_bbox_reg_stage1: 0.000265 loss_bbox_cls_stage2: 0.642100 loss_bbox_reg_stage2: 0.000457 loss: 2.755846 eta: 0:18:58 batch_cost: 0.1600 data_cost: 0.0004 ips: 6.2487 images/s
[09/13 19:13:54] ppdet.engine INFO: Epoch: [0] [ 20/593] learning_rate: 0.000026 loss_rpn_cls: 0.696808 loss_rpn_reg: 0.056438 loss_bbox_cls_stage0: 0.665093 loss_bbox_reg_stage0: 0.000073 loss_bbox_cls_stage1: 0.638169 loss_bbox_reg_stage1: 0.000155 loss_bbox_cls_stage2: 0.628870 loss_bbox_reg_stage2: 0.000236 loss: 2.683045 eta: 0:16:32 batch_cost: 0.1388 data_cost: 0.0002 ips: 7.2052 images/s
[09/13 19:13:57] ppdet.engine INFO: Epoch: [0] [ 40/593] learning_rate: 0.000051 loss_rpn_cls: 0.696619 loss_rpn_reg: 0.047299 loss_bbox_cls_stage0: 0.557011 loss_bbox_reg_stage0: 0.000094 loss_bbox_cls_stage1: 0.515861 loss_bbox_reg_stage1: 0.000205 loss_bbox_cls_stage2: 0.518766 loss_bbox_reg_stage2: 0.000299 loss: 2.346453 eta: 0:15:57 batch_cost: 0.1305 data_cost: 0.0002 ips: 7.6640 images/s
[09/13 19:13:59] ppdet.engine INFO: Epoch: [0] [ 60/593] learning_rate: 0.000076 loss_rpn_cls: 0.697658 loss_rpn_reg: 0.042460 loss_bbox_cls_stage0: 0.037034 loss_bbox_reg_stage0: 0.000147 loss_bbox_cls_stage1: 0.030499 loss_bbox_reg_stage1: 0.000318 loss_bbox_cls_stage2: 0.030750 loss_bbox_reg_stage2: 0.000649 loss: 0.873187 eta: 0:15:40 batch_cost: 0.1293 data_cost: 0.0002 ips: 7.7339 images/s
[09/13 19:14:02] ppdet.engine INFO: Epoch: [0] [ 80/593] learning_rate: 0.000101 loss_rpn_cls: 0.683219 loss_rpn_reg: 0.050110 loss_bbox_cls_stage0: 0.019129 loss_bbox_reg_stage0: 0.000185 loss_bbox_cls_stage1: 0.019823 loss_bbox_reg_stage1: 0.000433 loss_bbox_cls_stage2: 0.019747 loss_bbox_reg_stage2: 0.000714 loss: 0.801777 eta: 0:15:38 batch_cost: 0.1335 data_cost: 0.0002 ips: 7.4930 images/s
[09/13 19:14:05] ppdet.engine INFO: Epoch: [0] [100/593] learning_rate: 0.000126 loss_rpn_cls: 0.641044 loss_rpn_reg: 0.057100 loss_bbox_cls_stage0: 0.050942 loss_bbox_reg_stage0: 0.000329 loss_bbox_cls_stage1: 0.047029 loss_bbox_reg_stage1: 0.000560 loss_bbox_cls_stage2: 0.046340 loss_bbox_reg_stage2: 0.000886 loss: 0.839477 eta: 0:15:36 batch_cost: 0.1337 data_cost: 0.0002 ips: 7.4782 images/s
[09/13 19:14:07] ppdet.engine INFO: Epoch: [0] [120/593] learning_rate: 0.000151 loss_rpn_cls: 0.502041 loss_rpn_reg: 0.051631 loss_bbox_cls_stage0: 0.058352 loss_bbox_reg_stage0: 0.000240 loss_bbox_cls_stage1: 0.057758 loss_bbox_reg_stage1: 0.000567 loss_bbox_cls_stage2: 0.057330 loss_bbox_reg_stage2: 0.000826 loss: 0.730823 eta: 0:15:38 batch_cost: 0.1376 data_cost: 0.0002 ips: 7.2692 images/s
[09/13 19:14:10] ppdet.engine INFO: Epoch: [0] [140/593] learning_rate: 0.000176 loss_rpn_cls: 0.258168 loss_rpn_reg: 0.050298 loss_bbox_cls_stage0: 0.062788 loss_bbox_reg_stage0: 0.000303 loss_bbox_cls_stage1: 0.065374 loss_bbox_reg_stage1: 0.000849 loss_bbox_cls_stage2: 0.060197 loss_bbox_reg_stage2: 0.001549 loss: 0.507770 eta: 0:15:31 batch_cost: 0.1304 data_cost: 0.0002 ips: 7.6689 images/s
[09/13 19:14:13] ppdet.engine INFO: Epoch: [0] [160/593] learning_rate: 0.000201 loss_rpn_cls: 0.193648 loss_rpn_reg: 0.052191 loss_bbox_cls_stage0: 0.040497 loss_bbox_reg_stage0: 0.000375 loss_bbox_cls_stage1: 0.044253 loss_bbox_reg_stage1: 0.001090 loss_bbox_cls_stage2: 0.040505 loss_bbox_reg_stage2: 0.001863 loss: 0.381232 eta: 0:15:29 batch_cost: 0.1342 data_cost: 0.0002 ips: 7.4498 images/s
[09/13 19:14:16] ppdet.engine INFO: Epoch: [0] [180/593] learning_rate: 0.000226 loss_rpn_cls: 0.174198 loss_rpn_reg: 0.044281 loss_bbox_cls_stage0: 0.026620 loss_bbox_reg_stage0: 0.000269 loss_bbox_cls_stage1: 0.029924 loss_bbox_reg_stage1: 0.000748 loss_bbox_cls_stage2: 0.027804 loss_bbox_reg_stage2: 0.001435 loss: 0.314368 eta: 0:15:28 batch_cost: 0.1355 data_cost: 0.0002 ips: 7.3812 images/s
[09/13 19:14:18] ppdet.engine INFO: Epoch: [0] [200/593] learning_rate: 0.000251 loss_rpn_cls: 0.160981 loss_rpn_reg: 0.046810 loss_bbox_cls_stage0: 0.028095 loss_bbox_reg_stage0: 0.000315 loss_bbox_cls_stage1: 0.026326 loss_bbox_reg_stage1: 0.000604 loss_bbox_cls_stage2: 0.026103 loss_bbox_reg_stage2: 0.001056 loss: 0.314169 eta: 0:15:25 batch_cost: 0.1339 data_cost: 0.0002 ips: 7.4677 images/s
[09/13 19:14:21] ppdet.engine INFO: Epoch: [0] [220/593] learning_rate: 0.000276 loss_rpn_cls: 0.162685 loss_rpn_reg: 0.045351 loss_bbox_cls_stage0: 0.023775 loss_bbox_reg_stage0: 0.000313 loss_bbox_cls_stage1: 0.023748 loss_bbox_reg_stage1: 0.000600 loss_bbox_cls_stage2: 0.023331 loss_bbox_reg_stage2: 0.001040 loss: 0.283127 eta: 0:15:22 batch_cost: 0.1326 data_cost: 0.0002 ips: 7.5394 images/s
[09/13 19:14:24] ppdet.engine INFO: Epoch: [0] [240/593] learning_rate: 0.000301 loss_rpn_cls: 0.166816 loss_rpn_reg: 0.047582 loss_bbox_cls_stage0: 0.027426 loss_bbox_reg_stage0: 0.003095 loss_bbox_cls_stage1: 0.025591 loss_bbox_reg_stage1: 0.000841 loss_bbox_cls_stage2: 0.024981 loss_bbox_reg_stage2: 0.001400 loss: 0.302733 eta: 0:15:21 batch_cost: 0.1371 data_cost: 0.0002 ips: 7.2933 images/s
[09/13 19:14:26] ppdet.engine INFO: Epoch: [0] [260/593] learning_rate: 0.000326 loss_rpn_cls: 0.147262 loss_rpn_reg: 0.044232 loss_bbox_cls_stage0: 0.025150 loss_bbox_reg_stage0: 0.001952 loss_bbox_cls_stage1: 0.023441 loss_bbox_reg_stage1: 0.000622 loss_bbox_cls_stage2: 0.023094 loss_bbox_reg_stage2: 0.001334 loss: 0.289993 eta: 0:15:18 batch_cost: 0.1331 data_cost: 0.0002 ips: 7.5108 images/s
[09/13 19:14:29] ppdet.engine INFO: Epoch: [0] [280/593] learning_rate: 0.000351 loss_rpn_cls: 0.166053 loss_rpn_reg: 0.055038 loss_bbox_cls_stage0: 0.029527 loss_bbox_reg_stage0: 0.004480 loss_bbox_cls_stage1: 0.026308 loss_bbox_reg_stage1: 0.001137 loss_bbox_cls_stage2: 0.024665 loss_bbox_reg_stage2: 0.001997 loss: 0.308855 eta: 0:15:14 batch_cost: 0.1311 data_cost: 0.0002 ips: 7.6258 images/s
[09/13 19:14:32] ppdet.engine INFO: Epoch: [0] [300/593] learning_rate: 0.000376 loss_rpn_cls: 0.151672 loss_rpn_reg: 0.049369 loss_bbox_cls_stage0: 0.024999 loss_bbox_reg_stage0: 0.000352 loss_bbox_cls_stage1: 0.024625 loss_bbox_reg_stage1: 0.001019 loss_bbox_cls_stage2: 0.023440 loss_bbox_reg_stage2: 0.001985 loss: 0.304269 eta: 0:15:10 batch_cost: 0.1319 data_cost: 0.0002 ips: 7.5840 images/s
^C
Traceback (most recent call last):
File "tools/train.py", line 139, in <module>
main()
File "tools/train.py", line 135, in main
run(FLAGS, cfg)
File "tools/train.py", line 110, in run
trainer.train(FLAGS.eval)
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/engine/trainer.py", line 306, in train
outputs = model(data)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
outputs = self.forward(*inputs, **kwargs)
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/architectures/meta_arch.py", line 26, in forward
out = self.get_loss()
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/architectures/cascade_rcnn.py", line 125, in get_loss
rpn_loss, bbox_loss, mask_loss = self._forward()
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/architectures/cascade_rcnn.py", line 87, in _forward
body_feats = self.backbone(self.inputs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
outputs = self.forward(*inputs, **kwargs)
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/backbones/resnet.py", line 577, in forward
x = stage(x)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
outputs = self.forward(*inputs, **kwargs)
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/backbones/resnet.py", line 427, in forward
block_out = block(block_out)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
outputs = self.forward(*inputs, **kwargs)
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/backbones/resnet.py", line 365, in forward
out = self.branch2b(out)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
outputs = self.forward(*inputs, **kwargs)
File "/home/aistudio/work/PaddleDetection-release-2.1/ppdet/modeling/backbones/resnet.py", line 133, in forward
out = self.norm(out)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
outputs = self.forward(*inputs, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/nn.py", line 1342, in forward
mean_out, variance_out, *attrs)
KeyboardInterrupt
评估与预测
如果在训练中加了--eval
参数,在模型训练完就可得到mAP指标,如果要对模型单独计算mAP,可以运行下列命令。
本实验提供了一个训练好的baseline模型,修改
/home/aistudio/work/PaddleDetection-release-2.1/configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.yml
中weights即可对baseline模型进行评估:
weights: /home/aistudio/work/PaddleDetection-release-2.1/models/best_model
!cd /home/aistudio/work/PaddleDetection-release-2.1
!python -u /home/aistudio/work/PaddleDetection-release-2.1/tools/eval.py -c configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.yml
/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
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
W0913 19:17:47.394450 1020 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0913 19:17:47.400025 1020 device_context.cc:422] device: 0, cuDNN Version: 7.6.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[09/13 19:17:52] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/work/PaddleDetection-release-2.1/models/best_model.pdparams
[09/13 19:17:52] ppdet.engine INFO: Eval iter: 0
[09/13 19:18: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!
[09/13 19:18: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.41s).
Accumulating evaluation results...
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:378: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pycocotools/cocoeval.py:379: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
fp_sum = np.cumsum(fps, axis=1).astype(dtype=np.float)
DONE (t=0.08s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.351
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.864
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.157
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.207
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.363
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.191
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.107
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.438
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.445
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.425
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.451
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.321
[09/13 19:18:00] ppdet.engine INFO: Total sample number: 100, averge FPS: 12.847098054265162
模型推理,用训练出来的模型在一个PCB图像上进行测试。测试结果保存在work/PaddleDetection-release-2.1/output/04_missing_hole_10.jpg
! python -u tools/infer.py -c configs/cascade_rcnn/cascade_rcnn_r50_fpn_1x_coco.yml \
--infer_img=../PCB_DATASET/images/04_missing_hole_10.jpg \
-o weights=/home/aistudio/work/PaddleDetection-release-2.1/models/best_model
/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
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
W0913 19:21:15.096993 1332 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 10.1, Runtime API Version: 10.1
W0913 19:21:15.102478 1332 device_context.cc:422] device: 0, cuDNN Version: 7.6.
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
if data.dtype == np.object:
[09/13 19:21:19] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/work/PaddleDetection-release-2.1/models/best_model.pdparams
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[09/13 19:21:20] ppdet.engine INFO: Detection bbox results save in output/04_missing_hole_10.jpg
推理结果可视化:
%matplotlib inline
import matplotlib.pyplot as plt
import cv2
infer_img = cv2.imread("output/04_missing_hole_10.jpg")
plt.figure(figsize=(15, 10))
plt.imshow(cv2.cvtColor(infer_img, cv2.COLOR_BGR2RGB))
plt.show()
可优化方向
数据层面
数据增广(Mixup、AutoAugment、GridMask等)、测试时增强。
模型层面
预训练模型、backbone,fpn,head,后处理、正则化、损失函数(如Balanced L1 Loss)。
训练层面
学习率,优化器、参数更新策略。
更多推荐
所有评论(0)