/CVWC2019-Amur-Tiger-Re-ID

:trophy: Code for 1st Place Soluition in both the Tiger Re-ID in the plain track and Tiger Re-ID in the wild track (CVWC) @ ICCV19 Workshop.

Primary LanguagePythonApache License 2.0Apache-2.0

CVWC2019-Amur-Tiger-Re-ID

Example result of Rank-7 .

πŸ†Code for 1st Place Soluition in both the Tiger Re-ID in the plain track and Tiger Re-ID in the wild trackCVWC2019 @ICCV19 Workshop.


πŸƒ Getting Started

1️⃣ Clone the repo:

git clone https://github.com/LcenArthas/CWCV2019-Amur-Tiger-Re-ID.git

2️⃣ Dependencies

Tested under python3.6 Ubantu16.04

  • python packages
    • pytorch=1.0.1
    • torchvision==0.2.1
    • pytorch-ignite=0.1.2 (Note: V0.2.0 may result in an error)
    • yacs==0.1.6
    • tensorboardx
    • h5py==2.9.0
    • imgaug==0.2.9
    • matplotlib==3.1.0
    • numpy==1.16.4
    • opencv==4.1.0.15
    • pillow==6.0.0
    • scikit-image==0.15.0
    • scipy==1.3.0
    • tensorboardx==1.6
    • tqdm==4.32.1
    • yacs==0.1.6

πŸ‘‰ Section1 The Tiger Plain Re-ID:

πŸƒ Train

1️⃣ Data Prearation

πŸ”Έ Download the train dataset and put them(atrw_reid_train, atrw_anno_reid_train) into the {repo_root}/process_data/.

πŸ”Έ Transform the data style for the model

python data_process.py

2️⃣ Pre-trained weight

πŸ”Έ Creat a new folder named /pretrained_model/ under the {repo_root}/:

cd data
mkdir pretrained_model

πŸ”Έ Download the pre-trained weighte and put them into the {repo_root}/pretrained_model/.

And make sure the repo files as the following structure:

{repo_root}
 β”œβ”€β”€ config
 β”œβ”€β”€ configs
 β”œβ”€β”€ data
 |   β”œβ”€β”€ AmurTiger
 β”‚   β”‚   β”œβ”€β”€ flod0
 β”‚   β”‚   └── flod1
 β”‚   β”‚   β”œβ”€β”€ flod2
 β”‚   β”‚   └── flod3
 β”‚   β”œβ”€β”€ datasets
 β”‚   β”œβ”€β”€ samplers
 β”‚   └── ...
 β”œβ”€β”€ engine
 β”œβ”€β”€ layers
 β”œβ”€β”€ modeling
 β”œβ”€β”€ pre_data
 β”œβ”€β”€ pretrained_model
 β”œβ”€β”€ solver
 β”œβ”€β”€ tests
 β”œβ”€β”€ utils
 β”œβ”€β”€ check_result.py
 β”œβ”€β”€ data_process.py
 β”œβ”€β”€ medo.py
 β”œβ”€β”€ medo_wide.py
 β”œβ”€β”€ test.py
 └── train.py

πŸ‘ Train Now!

In this competition, I use 4-fold to train and ues the Resnet152 for the backbone.

python train.py --config_file ./configs/tiger_b_resnet152_34.yml --index_flod 0
python train.py --config_file ./configs/tiger_b_resnet152_34.yml --index_flod 1
python train.py --config_file ./configs/tiger_b_resnet152_34.yml --index_flod 2
python train.py --config_file ./configs/tiger_b_resnet152_34.yml --index_flod 3

Eventually the trained model will be saved in {repo_root}/tiger_out/b_resnet152_34/


πŸƒ Inference

1️⃣ Data Preparation

πŸ”Έ Creat a new folder named /reid_test/ under the {repo_root}/data/AmurTiger/:

cd data
cd AmurTiger
mkdir reid_test

πŸ”Έ Put the test images in the {repo_root}/data/AmurTiger/reid_test/.

2️⃣ Download Pretrained Model

The trained weights are following:

Download it and create a new folder under the {repo_root} named /trained_weight/

mkdir trained_weight

Unzip the model.zip(there will be 8 trained weights) and put them in the {repo_root}/trained_weight/.

And make sure the repo files as the following structure:

  {repo_root}
  β”œβ”€β”€ config
  β”œβ”€β”€ configs
  β”œβ”€β”€ data
  |   β”œβ”€β”€ AmurTiger
  β”‚   β”‚   β”œβ”€β”€ flod0
  β”‚   β”‚   └── reid_test
  β”‚   β”‚       β”œβ”€β”€ 000000.jpg
  β”‚   β”‚       β”œβ”€β”€ 000004.jpg
  β”‚   β”‚       β”œβ”€β”€ 000005.jpg
  β”‚   β”‚       β”œβ”€β”€ 000006.jpg
  β”‚   β”‚       β”œβ”€β”€ 000008.jpg
  β”‚   β”‚       └── ...
  β”‚   β”œβ”€β”€ datasets
  β”‚   β”œβ”€β”€ samplers
  β”‚   └── ...
  β”œβ”€β”€ engine
  β”œβ”€β”€ layers
  β”œβ”€β”€ modeling
  β”œβ”€β”€ solver
  β”œβ”€β”€ tests
  β”œβ”€β”€ trained_weight
  β”‚   β”œβ”€β”€ resnet101-bsize_model_100.pth
  β”‚   β”œβ”€β”€ resnet101-bsize_model_300.pth       
  β”‚   β”œβ”€β”€ resnet101-bsize_model_301.pth
  β”‚   β”œβ”€β”€ resnet101-bsize_model_400.pth
  β”‚   └──...
  β”œβ”€β”€ utils
  β”œβ”€β”€ check_result.py
  β”œβ”€β”€ medo.py
  β”œβ”€β”€ medo_wide.py
  β”œβ”€β”€ test.py
  └── train.py
      

πŸ‘ Inference Now!

python demo.py

This process will take about 6 minutes, just a moment, please.

It will generate a submission in the {repo_root/}:

  • submission_plain.json β€”-you can submit to the Tiger Plain Re-ID track.

πŸ‘‰ Section2  The Tiger Wild Re-ID

πŸƒ Train

Same thing up here

πŸƒ Inference

In this task, it's a two-step process: Detection and Re-id

1️⃣ Detection

πŸ”Έ Please follow this repo: CWCV2019-Amur-Tiger-Detection

Note that the two repos depend on different environments(Re-ID is pytorch==1.0.1, Detection is pytorch==0.4.1)

πŸ”Έ Run scrip in above repo will generate 3 files in the {repo_root/}:

  • det_submission.json

  • wide_box.json

  • reid_test(a folder) --it contains images that have been detected and croped.

This wide_box.json and reid_test(a folder) are what we need next.

2️⃣ Re-ID

Use this reop.

πŸ”Έ Data Preparation

Put wide_box.json and reid_test(a folder)(created by the detector above) under the {repo_root}/data/AmurTiger/.

πŸ”Έ Download Pretrained Model(Same as the plain re-id)

The trained weight is following:

Download it and create a new folder under the {repo_root} named /trained_weight/

mkdir trained_weight

Unzip the model.zip and put them into the {repo_root}/trained_weight/.

And make sure the repo files as the following structure:

 {repo_root}
 β”œβ”€β”€ config
 β”œβ”€β”€ configs
 β”œβ”€β”€ data
 |   β”œβ”€β”€ AmurTiger
 β”‚   β”‚   β”œβ”€β”€ flod0
 β”‚   β”‚   β”œβ”€β”€ wide_box.json
 β”‚   β”‚   └── reid_test
 β”‚   β”‚       β”œβ”€β”€ 000000.jpg
 β”‚   β”‚       β”œβ”€β”€ 000004.jpg
 β”‚   β”‚       β”œβ”€β”€ 000005.jpg
 β”‚   β”‚       β”œβ”€β”€ 000006.jpg
 β”‚   β”‚       β”œβ”€β”€ 000008.jpg
 β”‚   β”‚       └── ...
 β”‚   β”œβ”€β”€ datasets
 β”‚   β”œβ”€β”€ samplers
 β”‚   └── ...
 β”œβ”€β”€ engine
 β”œβ”€β”€ layers
 β”œβ”€β”€ modeling
 β”œβ”€β”€ solver
 β”œβ”€β”€ tests
 β”œβ”€β”€ trained_weight
 β”‚   β”œβ”€β”€ best_model.pth
 β”‚   β”œβ”€β”€ resnet101-bsize_model_100.pth
 β”‚   β”œβ”€β”€ resnet101-bsize_model_300.pth       
 β”‚   β”œβ”€β”€ resnet101-bsize_model_301.pth
 β”‚   β”œβ”€β”€ resnet101-bsize_model_400.pth
 β”‚   └──...
 β”œβ”€β”€ utils
 β”œβ”€β”€ check_result.py
 β”œβ”€β”€ medo.py
 β”œβ”€β”€ medo_wide.py
 β”œβ”€β”€ test.py
 └── train.py
     

πŸ‘ Inference Now!

python demo_wide.py

This process will take about 15 minutes, just a moment, please.

It will generate a submission in the {repo_root/}:

  • submission_wide.json β€”-you can submit to the Tiger Wide Re-ID track.