# [AI训练营]PaddleX实现目标检测baseline
手把手教你基于PaddleX实现目标检测。你需要实现以下任务:
> 1. 配置数据集(数据集选择、数据处理)
> 2. 配置模型并训练
> 3. 项目跑通即可达到结业要求
# 一、数据集说明
本项目使用的数据集是:[[AI训练营]目标检测数据集合集](https://aistudio.baidu.com/aistudio/datasetdetail/103743),包含口罩识别 、交通标志识别、火焰检测、锥桶识别以及中秋元素识别。
该数据集已加载至本环境中,位于:**data/data103743/objDataset.zip**
```python
# 解压数据集(解压一次即可,请勿重复解压)
!unzip -oq /home/aistudio/data/data103743/objDataset.zip
```
解压完成后,左侧文件夹处会多一个名为**objDataset**的文件夹,该文件夹下有5个子文件夹:
- **barricade**——Gazebo锥桶检测
- **facemask**——口罩检测
- **fire**——火焰检测
- **MidAutumn**——中秋元素检测
- **roadsign_voc**——交通路标检测
每个子文件夹下有2个文件夹,分别存放着图像(**JPEGImages**)和标注文件(**Annotations**),如下所示:
```python
# 查看数据集文件结构
!tree objDataset -L 2
```
objDataset
├── barricade
│ ├── Annotations
│ ├── JPEGImages
│ ├── labels.txt
│ ├── test_list.txt
│ ├── train_list.txt
│ └── val_list.txt
├── facemask
│ ├── Annotations
│ ├── JPEGImages
│ ├── labels.txt
│ ├── test_list.txt
│ ├── train_list.txt
│ └── val_list.txt
├── fire
│ ├── Annotations
│ └── JPEGImages
├── MidAutumn
│ ├── Annotations
│ └── JPEGImages
└── roadsign_voc
├── Annotations
└── JPEGImages
15 directories, 8 files
# 二、数据准备
本基线系统使用的数据格式是PascalVOC格式,开发者基于PaddleX开发目标检测模型时,无需对数据格式进行转换,开箱即用。
但为了进行训练,还需要将数据划分为训练集、验证集和测试集。划分之前首先需要**安装PaddleX**。
```python
# 安装PaddleX
!pip install paddlex
```
Looking in indexes: https://mirror.baidu.com/pypi/simple/
Collecting paddlex
[?25l Downloading https://mirror.baidu.com/pypi/packages/d6/a2/07435f4aa1e51fe22bdf06c95d03bf1b78b7bc6625adbb51e35dc0804cc7/paddlex-1.3.11-py3-none-any.whl (516kB)
[K |████████████████████████████████| 522kB 14.2MB/s eta 0:00:01
[?25hRequirement already satisfied: opencv-python in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (4.1.1.26)
Requirement already satisfied: psutil in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (5.7.2)
Requirement already satisfied: flask-cors in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (3.0.8)
Collecting xlwt (from paddlex)
[?25l Downloading https://mirror.baidu.com/pypi/packages/44/48/def306413b25c3d01753603b1a222a011b8621aed27cd7f89cbc27e6b0f4/xlwt-1.3.0-py2.py3-none-any.whl (99kB)
[K |████████████████████████████████| 102kB 24.8MB/s ta 0:00:01
[?25hRequirement already satisfied: pyyaml in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (5.1.2)
Requirement already satisfied: visualdl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (2.2.0)
Requirement already satisfied: colorama in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (0.4.4)
Collecting pycocotools; platform_system != "Windows" (from paddlex)
Downloading https://mirror.baidu.com/pypi/packages/de/df/056875d697c45182ed6d2ae21f62015896fdb841906fe48e7268e791c467/pycocotools-2.0.2.tar.gz
Collecting paddleslim==1.1.1 (from paddlex)
[?25l Downloading https://mirror.baidu.com/pypi/packages/d1/77/e257227bed9a70ff0d35a4a3c4e70ac2d2362c803834c4c52018f7c4b762/paddleslim-1.1.1-py2.py3-none-any.whl (145kB)
[K |████████████████████████████████| 153kB 24.0MB/s eta 0:00:01
[?25hCollecting shapely>=1.7.0 (from paddlex)
[?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 10.2MB/s eta 0:00:01
[?25hCollecting paddlehub==2.1.0 (from paddlex)
[?25l Downloading https://mirror.baidu.com/pypi/packages/7a/29/3bd0ca43c787181e9c22fe44b944b64d7fcb14ce66d3bf4602d9ad2ac76c/paddlehub-2.1.0-py3-none-any.whl (211kB)
[K |████████████████████████████████| 215kB 23.4MB/s eta 0:00:01
[?25hRequirement already satisfied: sklearn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (0.0)
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlex) (4.36.1)
Requirement already satisfied: numpy>=1.14.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from opencv-python->paddlex) (1.20.3)
Requirement already satisfied: Flask>=0.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask-cors->paddlex) (1.1.1)
Requirement already satisfied: Six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask-cors->paddlex) (1.15.0)
Requirement already satisfied: flake8>=3.7.9 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (3.8.2)
Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (1.1.5)
Requirement already satisfied: shellcheck-py in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (0.7.1.1)
Requirement already satisfied: Pillow>=7.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (7.1.2)
Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (3.14.0)
Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (2.2.3)
Requirement already satisfied: pre-commit in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (1.21.0)
Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (1.0.0)
Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (0.8.53)
Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.0.0->paddlex) (2.22.0)
Requirement already satisfied: setuptools>=18.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools; platform_system != "Windows"->paddlex) (56.2.0)
Requirement already satisfied: cython>=0.27.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pycocotools; platform_system != "Windows"->pad