一、安装环境
# install requirements
pip install pycocotools numpy opencv-python tqdm tensorboard tensorboardX pyyaml
pip install torch==1.4.0
pip install torchvision==0.5.0
二、下载pytorch版efficientdet源码
git clone https://github.com/zylo117/Yet-Another-EfficientDet-Pytorch.git
三、准备数据集
datasets/
-coco/
-train2017/
-*.jpg
-val2017/
-*.jpg
-annotations
-instances_train2017.json
-instances_val2017.json
四、修改配置文件(projects文件夹中的coco.yml)
project_name: coco #datasets文件下的数据集名
train_set: train2017 #数据集下的训练集文件夹
val_set: val2017 #数据集下的测试集文件夹
num_gpus: 4 # 0 means using cpu, 1-N means using gpus
# mean and std in RGB order, actually this part should remain unchanged as long as your dataset is similar to coco.
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
# this is coco anchors, change it if necessary
anchors_scales: '[2 ** 0, 2 ** (1.0 / 3.0), 2 ** (2.0 / 3.0)]'
anchors_ratios: '[(1.0, 1.0), (1.4, 0.7), (0.7, 1.4)]'
# objects from all labels from your dataset with the order from your annotations.
# its index must match your dataset's category_id.
# category_id is one_indexed,
# for example, index of 'car' here is 2, while category_id of is 3
obj_list: ['person', 'bicycle', 'car', ...] #自己数据集的类别,与数据集的标签顺序要一致
五、训练coco数据集
python train.py -c 1 --batch_size 8 --lr 1e-5
#这里c与测试的c要一致,若project_name为coco,可以省略-p
六、评估模型性能
python coco_eval.py -w ./weights/efficientdet-d0.pth
.pth文件存放在weights文件夹中。
七、显示单张图片
python efficientdet_test.py