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.
- Python 3.7.11 conda environment
- PyTorch 1.8.2 LTS with CUDA 11.1
git clone https://github.com/ChienHsuan/CMLD.git
cd CMLD
pip install -r requirements.txt
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/
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
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.
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/...
Use only a single model for general clustering-based UDA training on the target domain.
bash scripts\cluster_base.sh
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
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.
bash scripts\contrastive_ML.sh
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
Instead, use the improved contrastive learning objective function as follows, which will enable the model to achieve better performance.
bash scripts\imp_contrastive_ML_distillation.sh
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
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.
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.
The following are experiment results using the ResNet-50 model.
Dukemtmc → Market1501 experiment results:
Dukemtmc → Market1501 experiment results:
For more details, please refer to Person re-identification and tracking for multiple embedded edge cameras.
The MIT License (MIT)
Copyright (c) 2022 Chien-Hsuan Yen
@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}
}