Skip to content

CMLD: Contrastive mutual learning distillation for unsupervised domain adaptive person re-identification

License

Notifications You must be signed in to change notification settings

ChienHsuan/CMLD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contrastive Mutual Learning Distillation (CMLD)

This repository presents the UDA person re-ID training method Contrastive Mutual Learning Distillation (CMLD), which is an improved method based on MMT. Use the EMA models to generate more stable soft pseudo labels which are used to supervise peer models, and use mutual learning training manner to improve model performance. In addition, the contrastive learning method CML is used to improve the feature space distribution and make the output features of the model more discriminative, thereby improving the model performance. In order to further improve the performance of the model, the knowledge distillation method CFLD is used to transfer the prediction probability and feature representation knowledge of the teacher model to the student model.

cmld.png

Table of Contents

Getting Started

Prerequisites

  • Python 3.7.11 conda environment
  • PyTorch 1.8.2 LTS with CUDA 11.1

Installation

git clone https://github.com/ChienHsuan/CMLD.git
cd CMLD
pip install -r requirements.txt

Datasets preparation

Download datasets DukeMTMC-ReID, Market1501 and MSMT17. Moreover, arrange the directory paths as follows:

/USER-DEFINED-PATH/Dataset/
                      ├── dukemtmc/
                      │       └── DukeMTMC-reID/
                      ├── market1501/
                      |       └── Market-1501-v15.09.15/
                      └── msmt17/
                              └── MSMT17_V1/

ImageNet pre-trained weights preparation

Download the ImageNet pre-trained weights of IBN-ResNet model from this link and arrange the model paths as follows:

CMLD/logs/
      └── pretrained/
              ├── resnet50_ibn_a.pth.tar
              └── resnet101_ibn_a.pth.tar

Download the ImageNet pre-trained weights of OSNet-AIN and OSNet models from this link, and these ImageNet pre-trained models are used for deep-person-reid. Moreover, arrange the model paths as follows:

deep-person-reid/imagenet_pretrained_models/
                              ├── osnet_ain_x0_5_imagenet.pth
                              ├── osnet_ain_x1_0_imagenet.pth
                              ├── osnet_x0_5_imagenet.pth
                              └── osnet_x1_0_imagenet.pth

Usage

Training

The whole training process is divided into two stages: stage l and stage ll. In stage l, use ImageNet pre-trained models for pre-training on the source domain, so that the models can have basic person recognition ability. In stage ll, use the source domain pre-trained models to perform unsupervised learning on the target domain, and train the models by the proposed UDA training method CMLD. Therefore, the source pre-trained models can be adapted to the target domain. The CMLD training architecture includes Baseline, ML, CML, and CFLD methods. Moreover, in order to verify the effectiveness of the CMLD architecture, the experiments with other related methods are also conducted to compare the pros and cons of the methods, including the contrastive learning and knowledge distillation methods.

Stage l: Source domain pre-training

Use ResNet and IBN-ResNet models for pre-training on the source domain, execute the command:

bash scripts\pretrain.sh

OSNet and OSNet-AIN models use deep-person-reid for source domain pre-training, execute the command:

bash train.sh

Change the dataset and model related arguments in training scripts as required.

Then arrange the paths of each source domain pre-training model in the following form:

/USER-DEFINED-PATH/models/
                      ├── dukemtmcTOmarket1501/
                      │           ├── resnet50-pretrain-0/
                      │           │           └── model_best.pth.tar
                      │           ├── resnet101-pretrain-0/
                      │           │           └── model_best.pth.tar
                      │           ├── resnet_ibn50a-pretrain-0/
                      │           │           └── model_best.pth.tar
                      │           └── resnet_ibn101a-pretrain-0/
                      │                       └── model_best.pth.tar
                      ├── market1501TOdukemtmc/...
                      ├── dukemtmcTOmsmt17/...
                      ├── market1501TOmsmt17/...
                      ├── osnet_ain_x0_5/
                      │          ├── dukemtmc/
                      │          │       ├── 0/
                      │          │       │    └── model.pth.tar-100
                      │          │       └── 1/
                      │          │            └── model.pth.tar-100
                      │          └── market1501/...
                      ├── osnet_ain_x1_0/...
                      ├── osnet_x0_5/...
                      └── osnet_x1_0/...

Stage ll: UDA training

1. Baseline

Use only a single model for general clustering-based UDA training on the target domain.

bash scripts\cluster_base.sh
2. ML

Use EMA models to generate more stable soft pseudo labels to supervise peer models, and use mutual learning method for training.

bash scripts\mutual_learning.sh
3. CML

Use contrastive mutual learning (CML) methods based on ML methods to improve the output feature space distribution of the model. The objective function of contrastive learning is as follows.

$$ \mathcal L_{cont}(\theta) = - \frac{1}{PN_t} \sum_{j=1}^{P} \sum_{i=1}^{N_t} \left(\log \frac{S_{i,j}^+(\theta)}{S_{i,j}^+(\theta) + S_{i}^-(\theta)}\right) $$

bash scripts\contrastive_ML.sh
4. CFLD

Transfer the prediction probability and feature representation knowledge of the teacher model to the student model by Using the contrastive feature learning distillation (CFLD) method. Therefore, the student model has much lower model complexity and can achieve similar performance to the teacher model.

bash scripts\contrastive_ML_distillation.sh
Further improvement

Instead, use the improved contrastive learning objective function as follows, which will enable the model to achieve better performance.

$$ \mathcal L_{cont}(\theta) = - \frac{1}{PN_t} \sum_{j=1}^{P} \sum_{i=1}^{N_t} \left(\log \frac{S_{i,j}^+(\theta)}{S_{i,j}^+(\theta) + S_{i}^-(\theta)}\right) - \frac{1}{NN_t} \sum_{j=1}^{N} \sum_{i=1}^{N_t} \left(\log \left(1 - \frac{S_{i,j}^-(\theta)}{S_{i}^+(\theta) + S_{i,j}^-(\theta)}\right) \right) $$

bash scripts\imp_contrastive_ML_distillation.sh
Method comparisons
1. Contrastive learning method comparisons

Contrastive learning comparison methods are MoCo and CAP, which can be changed with the --cl-method argument ("moco" and "cap").

bash scripts\cl_comparison.sh
2. Knowledge distillation method comparisons

Knowledge distillation comparison methods are KD and CRD, which can be changed with the --kd-method argument ("kd" and "crd").

bash scripts\kd_comparison.sh

Change the dataset and model related arguments in training scripts as required.

Test

Use evaluation metrics mean Average Precision (mAP) and Cumulative Matching Characteristics (CMC) to evaluate the identification accuracy of person re-ID models.

bash scripts\test_model.sh

Change the dataset and model related arguments in test scripts as required.

Effectiveness Analysis Experiments

The following are experiment results using the ResNet-50 model.

Ablation study

resnet50_ablation_study.png

t-SNE visualization

Dukemtmc → Market1501 experiment results:

d2m_baseline_ml.png
d2m_cml_cmld.png

Rank-5 visualization

Dukemtmc → Market1501 experiment results:

d2m_rank_5.png

For more details, please refer to Person re-identification and tracking for multiple embedded edge cameras.

License

The MIT License (MIT)
Copyright (c) 2022 Chien-Hsuan Yen

Citation

@mastersthesis{yen2022person,
    author = {Yen, Chien-Hsuan},
    title = {Person re-identification and tracking for multiple embedded edge cameras},
    type = {M.S. thesis},
    institution = {Dept. of Elect. Eng., Natl. Taipei Univ. of Tech.},
    location = {Taipei, Taiwan},
    year = {2022},
    url = {https://hdl.handle.net/11296/8vzvt2}
}

Acknowledgments

MMT
deep-person-reid
MoCo
CAP
CRD

Releases

No releases published

Packages

No packages published