EfficientNet應用於目標檢測的模型改造方法
EfficientNet應用於目標檢測的模型改造方法
Object Detection using EfficientNet
flyfish
下載地址
https://github.com/shaoshengsong/EfficientNet-SSD
環境
操作系統: Ubuntu18.04
Python: 3.6
PyTorch: 1.1.0
論文 EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks
為了實現將EfficientNet應用於目標檢測,需要對其網絡進行改造
改造后的結果,起名字就是EfficientNet-SSDLite 或者 EfficientNet-SSD
該代碼也可以在CPU下運行
還有一篇是改造MobileNetV3的,將MobileNetV3應用於目標檢測
https://github.com/shaoshengsong/MobileNetV3-SSD
以 efficient_net_b0_ssd300_voc0712 為例說明是如何改造的
其他的
EfficientNet-B1
EfficientNet-B2
EfficientNet-B3
EfficientNet-B4
EfficientNet-B5
EfficientNet-B6
EfficientNet-B7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
都可以按照此方法就行改造,改造后至於是否使用SSD的 其他變種就是另一碼事了
配置efficient_net_b0_ssd300_voc0712.yaml如下
MODEL:
NUM_CLASSES: 21
BOX_PREDICTOR: 'SSDLiteBoxPredictor'
BACKBONE:
NAME: 'efficient_net-b0'
OUT_CHANNELS: (40, 112, 320, 256, 256, 256)
INPUT:
IMAGE_SIZE: 300
DATASETS:
TRAIN: ("voc_2007_trainval","voc_2012_trainval")
TEST: ("voc_2007_test", )
SOLVER:
MAX_ITER: 160000
LR_STEPS: [105000, 135000]
GAMMA: 0.1
BATCH_SIZE: 2
LR: 1e-3
OUTPUT_DIR: 'outputs/efficient_net_b0_ssd300_voc0712'
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
代碼改造
efficientnet-b3的數據
INDICES = {
'efficientnet-b3': [7, 17, 25]
}
EXTRAS = {
'efficientnet-b3': [
# in, out, k, s, p
[(384, 128, 1, 1, 0), (128, 256, 3, 2, 1)], # 5 x 5
[(256, 128, 1, 1, 0), (128, 256, 3, 1, 0)], # 3 x 3
[(256, 128, 1, 1, 0), (128, 256, 3, 1, 0)], # 1 x 1
]
}
efficientnet-b0的數據
INDICES = {
'efficientnet-b0': [4, 10, 15]
}
EXTRAS = {
'efficientnet-b0': [
# in, out, k, s, p
[(320, 128, 1, 1, 0), (128, 256, 3, 2, 1)], # 5 x 5
[(256, 128, 1, 1, 0), (128, 256, 3, 1, 0)], # 3 x 3
[(256, 128, 1, 1, 0), (128, 256, 3, 1, 0)], # 1 x 1
]
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
其他詳細的改造見github
數據集的下載
下載VOC數據集
可以通過以下命令下載數據集
切換到項目的數據目錄
cd data
下載2007年的訓練數據
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
下載2007年的測試數據
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
下載2012年的訓練數據
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
解壓數據集
下載完成之后,要解壓數據集到當前目錄
tar xvf VOCtest_06-Nov-2007.tar
tar xvf VOCtrainval_06-Nov-2007.tar
tar xvf VOCtrainval_11-May-2012.tar
VOC的目錄是這樣的
VOC_ROOT
|__ VOC2007
|_ JPEGImages
|_ Annotations
|_ ImageSets
|_ SegmentationClass
|__ VOC2012
|_ JPEGImages
|_ Annotations
|_ ImageSets
|_ SegmentationClass
|__ ...
COCO的目錄是這樣的
COCO_ROOT
|__ annotations
|_ instances_valminusminival2014.json
|_ instances_minival2014.json
|_ instances_train2014.json
|_ instances_val2014.json
|_ ...
|__ train2014
|_ <im-1-name>.jpg
|_ ...
|_ <im-N-name>.jpg
|__ val2014
|_ <im-1-name>.jpg
|_ ...
|_ <im-N-name>.jpg
|__ ...
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
下載數據集之后唯一需要做的是更改數據集的路徑,
SSD/ssd/config/path_catlog.py
改成自己數據集的路徑
class DatasetCatalog:
DATA_DIR = ‘/media/santiago/b/dataset/VOC’
訓練方法
python train.py --config-file configs/efficient_net_b0_ssd300_voc0712.yaml
代碼部分嚴重參考以下repository
EfficientNet的PyTorch的實現
https://github.com/lukemelas/EfficientNet-PyTorch
High quality, fast, modular reference implementation of SSD in PyTorch
https://github.com/lufficc/SSD