Skip to content

thisisi3/Paddle-GHM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This project is trying to reproduce model GHM, which is proposed in paper Gradient Harmonized Single-stage Detector. There are two Pytorch-based implementations under consideration:

Official Implementation

MMDetection

But since the official implementation is based on MMDetection, they can be viewed as one.

GHM is essentially RetinaNet with it's classification loss and regression loss replaced by GHMC and GHMR. GHMC and GHMR are two novel losses proposed in the paper, where the loss weight of a loss is associated with distribution of the gradient. The purpose of GHM losses is the same as Focal Loss, they are all trying to balance loss between hard and easy samples. GHM is better than Focal Loss in that it also down-weights loss from potential noisy samples, according to the paper. Check out the paper for more details.

Implementation

The implementation is based on PaddleDetection. PaddleDetection has already implemented the backbone, the neck and the training utilities, so I directly used them. What I have added is the implementation of RetinaNet and GHM losses.

The design of RetinaNet follows PaddleDetection's GFL, the training process follows MMDetection's RetinaNet implementation.

The GHM losses follow official/MMDetection.

All the code is located at: PaddleDetection/ppdet/ghm.

Results

source backbone total epochs AP config model train-log
official R-50-FPN 12 37.0 NA NA NA
mmdet R-50-FPN 12 37.0 config model log
this R-50-FPN 12 37.4 config baidu[ahbr] log

The experiments are performed on coco 2017 dataset. The training and testing are both done at Baidu AIStudio. The model is trained on 4 V100 GPUs with 2 images per GPU.

Please check out the config for more information on the model.

Please check out the train-log for more information on the loss during training.

Data in the first two rows are directly taken from official and mmdet's github repo, their dataset should also be coco 2017 according to this.

NOTICE: official and mmdet are based on Pytorch and MMDetection while this is based on Paddle and PaddleDetection.

Usage

Requirements:

  • python 3.7+

  • Paddle v2.2: follow this to install

Clone this repo and install:

git clone https://github.com/thisisi3/Paddle-GHM.git
pip install -e Paddle-GHM/PaddleDetection -v

Follow this for more details on installation of PaddleDetection, follow this to learn how to use PaddleDetection.

Data preparation:

cd Paddle-GHM

wget http://images.cocodataset.org/annotations/annotations_trainval2017.zip
wget http://images.cocodataset.org/zips/train2017.zip
wget http://images.cocodataset.org/zips/val2017.zip

mkdir dataset
mkdir dataset/coco

unzip annotations_trainval2017.zip -d dataset/coco
unzip train2017.zip -d dataset/coco
unzip val2017.zip -d dataset/coco

You can also go to aistudio to download coco 2017 if official download is slow.

Train GHM on a single GPU:

python PaddleDetection/tools/train.py -c configs/retinanet_ghm_r50_fpn_1x_coco_2x4GPU.yml --eval

Train GHM on multiple GPUs:

python -m paddle.distributed.launch --gpus 0,1,2,3 PaddleDetection/tools/train.py -c configs/retinanet_ghm_r50_fpn_1x_coco_2x4GPU.yml --eval

Eval AP of GHM:

python PaddleDetection/tools/eval.py -c configs/retinanet_ghm_r50_fpn_1x_coco_2x4GPU.yml -o weights=path_to_model_final.pdparams

Quick demo:

PaddleDetection comes with a inference script that allows us to visualize detection results. I provide an example image at demo/ and by running the following command we can visualize detection results of GHM on the image:

python PaddleDetection/tools/infer.py -c configs/retinanet_ghm_r50_fpn_1x_coco_2x4GPU.yml -o weights=path_to_model_final.pdparams --infer_img demo/000000371552.jpg --output_dir demo/out/ --draw_threshold 0.6

The example image:

Add detection bboxes:

Acknowledgement

I want to thank Baidu AIStudio for providing good amount of GPU computing power.

As well as the following amazing open-source projects:

GHM Official Code Release

PaddleDetection

MMDetection

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published