Skip to content

Commit

Permalink
feat: update naic20 1-st solution
Browse files Browse the repository at this point in the history
  • Loading branch information
L1aoXingyu committed Jan 29, 2021
1 parent 6b4b935 commit db8670d
Show file tree
Hide file tree
Showing 17 changed files with 341,345 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FastReID is a research platform that implements state-of-the-art re-identificati

## What's New

- [Jan 2021] NAIC20(reid track) [1-st solution](https://github.com/JDAI-CV/fast-reid/tree/master/projects/NAIC20) based on fastreid has been released!
- [Jan 2021] FastReID V1.0 has been released!🎉
Support many tasks beyond reid, such image retrieval and face recognition. See [release notes](https://github.com/JDAI-CV/fast-reid/releases/tag/v1.0.0).
- [Oct 2020] Added the [Hyper-Parameter Optimization](https://github.com/JDAI-CV/fast-reid/tree/master/projects/FastTune) based on fastreid. See `projects/FastTune`.
Expand Down
64 changes: 64 additions & 0 deletions projects/NAIC20/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# NAIC20 Competition (ReID Track)

This repository contains the 1-st place solution of ReID Competition of NAIC. We got the first place in the final stage.

## Introduction

Detailed information about the NAIC competition can be found [here](https://naic.pcl.ac.cn/homepage/index.html).

## Useful Tricks

- [x] DataAugmentation (RandomErasing + ColorJitter + Augmix + RandomAffine + RandomHorizontallyFilp + Padding + RandomCrop)
- [x] LR Scheduler (Warmup + CosineAnnealing)
- [x] Optimizer (Adam)
- [x] FP16 mixed precision training
- [x] CircleSoftmax
- [x] Pairwise Cosface
- [x] GeM pooling
- [x] Remove Long Tail Data (pid with single image)
- [x] Channel Shuffle
- [x] Distmat Ensemble

1. Due to the competition's rule, pseudo label is not allowed in the preliminary and semi-finals, but can be used in finals.
2. We combine naic19, naic20r1 and naic20r2 datasets, but there are overlap and noise between these datasets. So we
use an automatic data clean strategy for data clean. The cleaned txt files are put here. Sorry that this part cannot ben open sourced.
3. Due to the characteristics of the encrypted dataset, we found **channel shuffle** very helpful.
It's an offline data augmentation method. Specifically, for each id, random choice an order of channel,
such as `(2, 1, 0)`, then apply this order for all images of this id, and make it a new id.
With this method, you can enlarge the scale of identities. Theoretically, each id can be enlarged to 5 times.
Considering computational efficiency and marginal effect, we just enlarge each id once.
But this trick is no effect in normal dataset.
4. Due to the distribution of dataset, we found pairwise cosface can greatly boost model performance.
5. The performance of `resnest` is far better than `ibn`.
We choose `resnest101`, `resnest200` with different resolution (192x256, 192x384) to ensemble.

## Training & Submission in Command Line

Before starting, please see [GETTING_STARTED.md](https://github.com/JDAI-CV/fast-reid/blob/master/GETTING_STARTED.md) for the basic setup of FastReID.
All configs are made for 2-GPU training.

1. To train a model, first set up the corresponding datasets following [datasets/README.md](https://github.com/JDAI-CV/fast-reid/tree/master/datasets), then run:

```bash
python3 projects/NAIC20/train_net.py --config-file projects/NAIC20/configs/r34-ibn.yml --num-gpus 2
```

2. After the model is trained, you can start to generate submission file. First, modify the content of `MODEL` in `submit.yml` to
adapt your trained model, and set `MODEL.WEIGHTS` to the path of your trained model, then run:

```bash
python3 projects/NAIC20/train_net.py --config-file projects/NAIC20/configs/submit.yml --eval-only --commit --num-gpus 2
```

You can find `submit.json` and `distmat.npy` in `OUTPUT_DIR` of `submit.yml`.

## Ablation Study

To quickly verify the results, we use resnet34-ibn as backbone to conduct ablation study.
The datasets are `naic19`, `naic20r1` and `naic20r2`.

| Setting | Rank-1 | mAP |
| ------ | ------ | --- |
| Baseline | 70.11 | 63.29 |
| w/ tripletx10 | 73.79 | 67.01 |
| w/ cosface | 75.61 | 70.07 |
96 changes: 96 additions & 0 deletions projects/NAIC20/configs/Base-naic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
MODEL:
META_ARCHITECTURE: Baseline

FREEZE_LAYERS: [ backbone ]

HEADS:
NAME: EmbeddingHead
NORM: BN
EMBEDDING_DIM: 0
NECK_FEAT: after
POOL_LAYER: gempool
CLS_LAYER: circleSoftmax
SCALE: 64
MARGIN: 0.35

LOSSES:
NAME: ("CrossEntropyLoss", "Cosface",)

CE:
EPSILON: 0.
SCALE: 1.

TRI:
MARGIN: 0.
HARD_MINING: True
NORM_FEAT: True
SCALE: 1.

COSFACE:
MARGIN: 0.35
GAMMA: 64
SCALE: 1.

INPUT:
SIZE_TRAIN: [ 256, 128 ]
SIZE_TEST: [ 256, 128 ]

DO_AUGMIX: True
AUGMIX_PROB: 0.5

DO_AFFINE: True

REA:
ENABLED: True
VALUE: [ 0., 0., 0. ]

CJ:
ENABLED: True
BRIGHTNESS: 0.15
CONTRAST: 0.1
SATURATION: 0.
HUE: 0.

DATALOADER:
PK_SAMPLER: True
NAIVE_WAY: True
NUM_INSTANCE: 2
NUM_WORKERS: 8

SOLVER:
FP16_ENABLED: False
OPT: Adam
SCHED: CosineAnnealingLR
MAX_EPOCH: 30
BASE_LR: 0.0007
BIAS_LR_FACTOR: 1.
WEIGHT_DECAY: 0.0005
WEIGHT_DECAY_BIAS: 0.0005
IMS_PER_BATCH: 256

DELAY_EPOCHS: 5
ETA_MIN_LR: 0.0000007

FREEZE_ITERS: 1000
FREEZE_FC_ITERS: 0

WARMUP_FACTOR: 0.1
WARMUP_ITERS: 4000

CHECKPOINT_PERIOD: 3

DATASETS:
NAMES: ("NAIC20_R2", "NAIC20_R1", "NAIC19",)
TESTS: ("NAIC20_R2",)
RM_LT: True

TEST:
EVAL_PERIOD: 3
IMS_PER_BATCH: 256
RERANK:
ENABLED: False
K1: 20
K2: 3
LAMBDA: 0.5

CUDNN_BENCHMARK: True
10 changes: 10 additions & 0 deletions projects/NAIC20/configs/nest101-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_BASE_: Base-naic.yml

MODEL:
BACKBONE:
NAME: build_resnest_backbone
DEPTH: 101x
WITH_IBN: False
PRETRAIN: True

OUTPUT_DIR: projects/NAIC20/logs/nest101-128x256
11 changes: 11 additions & 0 deletions projects/NAIC20/configs/r34-ibn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_BASE_: Base-naic.yml

MODEL:
BACKBONE:
NAME: build_resnet_backbone
DEPTH: 34x
FEAT_DIM: 512
WITH_IBN: True
PRETRAIN: True

OUTPUT_DIR: projects/NAIC20/logs/r34_ibn-128x256
24 changes: 24 additions & 0 deletions projects/NAIC20/configs/submit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
_BASE_: Base-naic.yml

MODEL:
BACKBONE:
NAME: build_resnet_backbone
DEPTH: 34x
FEAT_DIM: 512
WITH_IBN: True

WEIGHTS: projects/NAIC20/logs/reproduce/r34-tripletx10/model_best.pth

DATASETS:
TESTS: ("NAIC20_R2A",)

TEST:
RERANK:
ENABLED: True
K1: 20
K2: 3
LAMBDA: 0.8

SAVE_DISTMAT: True

OUTPUT_DIR: projects/NAIC20/logs/r34_ibn-128x256-submit
Loading

0 comments on commit db8670d

Please sign in to comment.