IDM: An Intermediate Domain Module for Domain Adaptive Person Re-ID,

Related tags

Deep Learning IDM
Overview

Python >=3.7 PyTorch >=1.1

Intermediate Domain Module (IDM)

This repository is the official implementation for IDM: An Intermediate Domain Module for Domain Adaptive Person Re-ID, which is accepted by ICCV 2021 (Oral).

IDM achieves state-of-the-art performances on the unsupervised domain adaptation task for person re-ID.

Requirements

Installation

git clone https://github.com/SikaStar/IDM.git
cd IDM/idm/evaluation_metrics/rank_cylib && make all

Prepare Datasets

cd examples && mkdir data

Download the person re-ID datasets Market-1501, DukeMTMC-ReID, MSMT17, PersonX, and UnrealPerson. Then unzip them under the directory like

IDM/examples/data
├── dukemtmc
│   └── DukeMTMC-reID
├── market1501
│   └── Market-1501-v15.09.15
├── msmt17
│   └── MSMT17_V1
├── personx
│   └── PersonX
└── unreal
    ├── list_unreal_train.txt
    └── unreal_vX.Y

Prepare ImageNet Pre-trained Models for IBN-Net

When training with the backbone of IBN-ResNet, you need to download the ImageNet-pretrained model from this link and save it under the path of logs/pretrained/.

mkdir logs && cd logs
mkdir pretrained

The file tree should be

IDM/logs
└── pretrained
    └── resnet50_ibn_a.pth.tar

ImageNet-pretrained models for ResNet-50 will be automatically downloaded in the python script.

Training

We utilize 4 GTX-2080TI GPUs for training. Note that

  • The source and target domains are trained jointly.
  • For baseline methods, use -a resnet50 for the backbone of ResNet-50, and -a resnet_ibn50a for the backbone of IBN-ResNet.
  • For IDM, use -a resnet50_idm to insert IDM into the backbone of ResNet-50, and -a resnet_ibn50a_idm to insert IDM into the backbone of IBN-ResNet.
  • For strong baseline, use --use-xbm to implement XBM (a variant of Memory Bank).

Baseline Methods

To train the baseline methods in the paper, run commands like:

# Naive Baseline
CUDA_VISIBLE_DEVICES=0,1,2,3 sh scripts/run_naive_baseline.sh ${source} ${target} ${arch}

# Strong Baseline
CUDA_VISIBLE_DEVICES=0,1,2,3 sh scripts/run_strong_baseline.sh ${source} ${target} ${arch}

Some examples:

### market1501 -> dukemtmc ###

# ResNet-50
CUDA_VISIBLE_DEVICES=0,1,2,3 sh scripts/run_strong_baseline.sh market1501 dukemtmc resnet50 

# IBN-ResNet-50
CUDA_VISIBLE_DEVICES=0,1,2,3 sh scripts/run_strong_baseline.sh market1501 dukemtmc resnet_ibn50a

Training with IDM

To train the models with our IDM, run commands like:

# Naive Baseline + IDM
CUDA_VISIBLE_DEVICES=0,1,2,3 \
sh scripts/run_idm.sh ${source} ${target} ${arch} ${stage} ${mu1} ${mu2} ${mu3}

# Strong Baseline + IDM
CUDA_VISIBLE_DEVICES=0,1,2,3 \
sh scripts/run_idm_xbm.sh ${source} ${target} ${arch} ${stage} ${mu1} ${mu2} ${mu3}
  • Defaults: --stage 0 --mu1 0.7 --mu2 0.1 --mu3 1.0

Some examples:

### market1501 -> dukemtmc ###

# ResNet-50 + IDM
CUDA_VISIBLE_DEVICES=0,1,2,3 \
sh scripts/run_idm_xbm.sh market1501 dukemtmc resnet50_idm 0 0.7 0.1 1.0 

# IBN-ResNet-50 + IDM
CUDA_VISIBLE_DEVICES=0,1,2,3 \
sh scripts/run_idm_xbm.sh market1501 dukemtmc resnet_ibn50a_idm 0 0.7 0.1 1.0

Evaluation

We utilize 1 GTX-2080TI GPU for testing. Note that

  • use --dsbn for domain adaptive models, and add --test-source if you want to test on the source domain;
  • use -a resnet50 for the backbone of ResNet-50, and -a resnet_ibn50a for the backbone of IBN-ResNet.
  • use -a resnet50_idm for ResNet-50 + IDM, and -a resnet_ibn50a_idm for IBN-ResNet + IDM.

To evaluate the baseline model on the target-domain dataset, run:

CUDA_VISIBLE_DEVICES=0 \
python3 examples/test.py --dsbn -d ${dataset} -a ${arch} --resume ${resume} 

To evaluate the baseline model on the source-domain dataset, run:

CUDA_VISIBLE_DEVICES=0 \
python3 examples/test.py --dsbn --test-source -d ${dataset} -a ${arch} --resume ${resume} 

To evaluate the IDM model on the target-domain dataset, run:

CUDA_VISIBLE_DEVICES=0 \
python3 examples/test.py --dsbn-idm -d ${dataset} -a ${arch} --resume ${resume} --stage ${stage} 

To evaluate the IDM model on the source-domain dataset, run:

CUDA_VISIBLE_DEVICES=0 \
python3 examples/test.py --dsbn-idm --test-source -d ${dataset} -a ${arch} --resume ${resume} --stage ${stage} 

Some examples:

### market1501 -> dukemtmc ###

# evaluate the target domain "dukemtmc" on the strong baseline model
CUDA_VISIBLE_DEVICES=0 \
python3 examples/test.py --dsbn  -d dukemtmc -a resnet50 \
--resume logs/resnet50_strong_baseline/market1501-TO-dukemtmc/model_best.pth.tar 

# evaluate the source domain "market1501" on the strong baseline model
CUDA_VISIBLE_DEVICES=0 \
python3 examples/test.py --dsbn --test-source  -d market1501 -a resnet50 \
--resume logs/resnet50_strong_baseline/market1501-TO-dukemtmc/model_best.pth.tar 

# evaluate the target domain "dukemtmc" on the IDM model (after stage-0)
python3 examples/test.py --dsbn-idm  -d dukemtmc -a resnet50_idm \
--resume logs/resnet50_idm_xbm/market1501-TO-dukemtmc/model_best.pth.tar --stage 0

# evaluate the target domain "dukemtmc" on the IDM model (after stage-0)
python3 examples/test.py --dsbn-idm --test-source  -d market1501 -a resnet50_idm \
--resume logs/resnet50_idm_xbm/market1501-TO-dukemtmc/model_best.pth.tar --stage 0

Acknowledgement

Our code is based on MMT and SpCL. Thanks for Yixiao's wonderful works.

Citation

If you find our work is useful for your research, please kindly cite our paper

@inproceedings{dai2021idm,
  title={IDM: An Intermediate Domain Module for Domain Adaptive Person Re-ID},
  author={Dai, Yongxing and Liu, Jun and Sun, Yifan and Tong, Zekun and Zhang, Chi and Duan, Ling-Yu},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  year={2021}
}

If you have any questions, please leave an issue or contact me: [email protected]

Comments
  • issue about reproduced results

    issue about reproduced results

    When I use the given example as follow

    # IBN-ResNet-50 + IDM
    CUDA_VISIBLE_DEVICES=0,1,2,3 \
    sh scripts/run_idm_xbm.sh market1501 dukemtmc resnet_ibn50a_idm 0 0.7 0.1 1.0
    

    , I can not reproduce the reported mAP by a margin of 9 % .
    Looking forward to your reply.

    opened by zaiquanyang 8
  • About source centroids

    About source centroids

    Hi,

    image In the code above and also for target domain centroids, why do you initialize source center features into the model fully-connected layer?

    Is this some kind of techique not metioned in the paper?

    opened by YangJae96 4
  • Question about TripletLoss code

    Question about TripletLoss code

    Hi. In the code of Triplet loss (naive version, not xbm version), I found out that the distance matrix was defined as L2 distance between two identical matrices: emb and emb, mat_dist = euclidean_dist(emb, emb) which will make no contribution to finding the hardest positive and negative samples. Not sure what it means.

    opened by SuperbTUM 4
  • Other loss than triplet loss

    Other loss than triplet loss

    Hi, Thank you for your great work.

    Was there a particular reason for applying triplet loss on source and target domains' features? I was just wondering whether you have applied contrastive loss rather than triplet loss.

    Would it also work on your network?

    Thanks in advance.!

    opened by duhyunkim1 3
  • Hi, during running the released codes, an error happens.

    Hi, during running the released codes, an error happens.

    During running the run_strong_baseline.sh, an error happens in the idm/evaluation_metrics/rank.py, line 108. The specific error information is as follows (For efficiently debugging, i directly run the evaluator.evaluate() function before training. Of course, this error happens during running the original codes): Traceback (most recent call last): File "examples/train_baseline.py", line 329, in main() File "examples/train_baseline.py", line 117, in main main_worker(args) File "examples/train_baseline.py", line 143, in main_worker _, mAP = evaluator.evaluate(test_loader_target, dataset_target.query, dataset_target.gallery, cmc_flag=True) File "./idm/evaluators.py", line 140, in evaluate results = evaluate_all(query_features, gallery_features, distmat, query=query, gallery=gallery, cmc_flag=cmc_flag) File "./idm/evaluators.py", line 118, in evaluate_all max_rank=50, use_metric_cuhk03=False, use_cython=True) File "./idm/evaluation_metrics/rank.py", line 209, in evaluate_rank use_metric_cuhk03 File "./idm/evaluation_metrics/rank.py", line 169, in evaluate_py distmat, q_pids, g_pids, q_camids, g_camids, max_rank File "./idm/evaluation_metrics/rank.py", line 112, in eval_market1501 matches = (g_pids[indices] == q_pids[:, np.newaxis]).astype(np.int32) TypeError: only integer tensors of a single element can be converted to an index Could you please give me some comments about this error?

    opened by ddghjikle 3
  • 代码不清晰

    代码不清晰

    您好,我最近在仔细的研究IDM的代码,然后有一个点我不清楚。 bs = x.size(0) assert (bs%2==0) split = torch.split(x, int(bs/2), 0) x_s = split[0].contiguous() # [B, C, H, W] [16,64,64,32] x_t = split[1].contiguous() 这里将输入的x进行分割,请问这是将输入进行分割,一半作为源域数据,一半作为目标域数据,还是别的意思,这里我不太理解,希望可以得到您的解答,谢谢!

    opened by shylie728 2
  • About multi-GPU

    About multi-GPU

    Hi,

    I can see you have used 4 GPU in the training which gives great result.

    Is there a technical reason for using 4gpu like stable training that was done in MoCO network. Or is it just because of the memory issue due to big batch size?

    opened by YangJae96 2
  • 关于resnet50_ibn训练示例的错误

    关于resnet50_ibn训练示例的错误

    您好,我按您的readme进行测试时,跑到 CUDA_VISIBLE_DEVICES=0,1,2,3 sh scripts/run_strong_baseline.sh market1501 dukemtmc resnet_ibn50a 这句后,出现了以下错误

    ==> Create pseudo labels for unlabeled target domain with DBSCAN clustering Computing original distance... Computing Jaccard distance... Time cost: 238.44885563850403Clustering and labeling... Clustered into 538 Traceback (most recent call last):
    File "examples/train_baseline.py", line 321, in
    main()
    File "examples/train_baseline.py", line 117, in main
    main_worker(args)
    File "examples/train_baseline.py", line 224, in main_worker
    print_freq=args.print_freq, train_iters=args.iters, use_xbm=args.use_xbm)
    File "./idm/trainers.py", line 62, in train
    prob, feats = self._forward(inputs) ValueError: too many values to unpack (expected 2)

    然后我查看了models/resnet_ibn.py,发现这个文件的forward函数仅返回x或prob或bn_x,即每次只返回一个值,与idm/trainers.py中出错的这句相矛盾。

    不知道这个出错确实是这个部分有代码错误,还是说有可能有别的原因呢?

    opened by Luxios22 2
  • TypeError: only integer tensors of a single element can be converted to an index

    TypeError: only integer tensors of a single element can be converted to an index

    epoh 0 结束后出现如下错误,请问这会是什么原因呢 Traceback (most recent call last): File "examples/train_idm.py", line 330, in <module> main() File "examples/train_idm.py", line 122, in main main_worker(args) File "examples/train_idm.py", line 235, in main_worker _, mAP = evaluator.evaluate(test_loader_target, dataset_target.query, dataset_target.gallery, cmc_flag=True) File "./idm/evaluators.py", line 140, in evaluate results = evaluate_all(query_features, gallery_features, distmat, query=query, gallery=gallery, cmc_flag=cmc_flag) File "./idm/evaluators.py", line 118, in evaluate_all max_rank=50, use_metric_cuhk03=False, use_cython=True) File "./idm/evaluation_metrics/rank.py", line 205, in evaluate_rank use_metric_cuhk03 File "./idm/evaluation_metrics/rank.py", line 165, in evaluate_py distmat, q_pids, g_pids, q_camids, g_camids, max_rank File "./idm/evaluation_metrics/rank.py", line 108, in eval_market1501 matches = (g_pids[indices] == q_pids[:, np.newaxis]).astype(np.int32) TypeError: only integer tensors of a single element can be converted to an index

    opened by xkxkx 2
  • Questions about running the source code

    Questions about running the source code

    Hello, author. In the process of self-training published source code, I used the configuration of one GPU and got a result about 10% different from the paper. Do you need 4 GPUs to achieve the latest effect? Is there another way to get out?

    opened by Estella218 1
  • Reduce memory usage

    Reduce memory usage

    The modification of torch.no_grad() in the reasoning stage can reduce a large amount of memory. The data loader needs to wait for the next batch of data, otherwise it will be easy to interlock.

    opened by xmy0916 1
Owner
Yongxing Dai
I am now a fourth-year PhD student at National Engineering Lab for Video Technology in Peking University, Beijing, China
Yongxing Dai
[CVPR-2021] UnrealPerson: An adaptive pipeline for costless person re-identification

UnrealPerson: An Adaptive Pipeline for Costless Person Re-identification In our paper (arxiv), we propose a novel pipeline, UnrealPerson, that decreas

ZhangTianyu 70 Oct 10, 2022
Online Pseudo Label Generation by Hierarchical Cluster Dynamics for Adaptive Person Re-identification

Online Pseudo Label Generation by Hierarchical Cluster Dynamics for Adaptive Person Re-identification

TANG, shixiang 6 Nov 25, 2022
Woosung Choi 63 Nov 14, 2022
Official project website for the CVPR 2021 paper "Exploring intermediate representation for monocular vehicle pose estimation"

EgoNet Official project website for the CVPR 2021 paper "Exploring intermediate representation for monocular vehicle pose estimation". This repo inclu

Shichao Li 138 Dec 9, 2022
RIFE: Real-Time Intermediate Flow Estimation for Video Frame Interpolation

RIFE RIFE: Real-Time Intermediate Flow Estimation for Video Frame Interpolation Ported from https://github.com/hzwer/arXiv2020-RIFE Dependencies NumPy

null 49 Jan 7, 2023
This repo in the implementation of EMNLP'21 paper "SPARQLing Database Queries from Intermediate Question Decompositions" by Irina Saparina, Anton Osokin

SPARQLing Database Queries from Intermediate Question Decompositions This repo is the implementation of the following paper: SPARQLing Database Querie

Yandex Research 20 Dec 19, 2022
RIFE: Real-Time Intermediate Flow Estimation for Video Frame Interpolation

RIFE - Real Time Video Interpolation arXiv | YouTube | Colab | Tutorial | Demo Table of Contents Introduction Collection Usage Evaluation Training and

hzwer 3k Jan 4, 2023
Llvlir - Low Level Variable Length Intermediate Representation

Low Level Variable Length Intermediate Representation Low Level Variable Length

Michael Clark 2 Jan 24, 2022
RIFE - Real-Time Intermediate Flow Estimation for Video Frame Interpolation

RIFE - Real-Time Intermediate Flow Estimation for Video Frame Interpolation YouTube | BiliBili 16X interpolation results from two input images: Introd

旷视天元 MegEngine 28 Dec 9, 2022
Prototypical Pseudo Label Denoising and Target Structure Learning for Domain Adaptive Semantic Segmentation (CVPR 2021)

Prototypical Pseudo Label Denoising and Target Structure Learning for Domain Adaptive Semantic Segmentation (CVPR 2021, official Pytorch implementatio

Microsoft 247 Dec 25, 2022
Code for our paper Domain Adaptive Semantic Segmentation with Self-Supervised Depth Estimation

CorDA Code for our paper Domain Adaptive Semantic Segmentation with Self-Supervised Depth Estimation Prerequisite Please create and activate the follo

Qin Wang 60 Nov 30, 2022
Official implementation of "DSP: Dual Soft-Paste for Unsupervised Domain Adaptive Semantic Segmentation"

DSP Official implementation of "DSP: Dual Soft-Paste for Unsupervised Domain Adaptive Semantic Segmentation". Accepted by ACM Multimedia 2021. Authors

null 20 Oct 24, 2022
An official implementation of the paper Exploring Sequence Feature Alignment for Domain Adaptive Detection Transformers

Sequence Feature Alignment (SFA) By Wen Wang, Yang Cao, Jing Zhang, Fengxiang He, Zheng-jun Zha, Yonggang Wen, and Dacheng Tao This repository is an o

WangWen 79 Dec 24, 2022
IAST: Instance Adaptive Self-training for Unsupervised Domain Adaptation (ECCV 2020)

This repo is the official implementation of our paper "Instance Adaptive Self-training for Unsupervised Domain Adaptation". The purpose of this repo is to better communicate with you and respond to your questions. This repo is almost the same with Another-Version, and you can also refer to that version.

CVSM Group -  email: czhu@bupt.edu.cn 84 Dec 12, 2022
Pytorch Implementation for NeurIPS (oral) paper: Pixel Level Cycle Association: A New Perspective for Domain Adaptive Semantic Segmentation

Pixel-Level Cycle Association This is the Pytorch implementation of our NeurIPS 2020 Oral paper Pixel-Level Cycle Association: A New Perspective for D

null 87 Oct 19, 2022
LoveDA: A Remote Sensing Land-Cover Dataset for Domain Adaptive Semantic Segmentation (NeurIPS2021 Benchmark and Dataset Track)

LoveDA: A Remote Sensing Land-Cover Dataset for Domain Adaptive Semantic Segmentation by Junjue Wang, Zhuo Zheng, Ailong Ma, Xiaoyan Lu, and Yanfei Zh

Kingdrone 174 Dec 22, 2022
Implementation of "Semi-supervised Domain Adaptive Structure Learning"

Semi-supervised Domain Adaptive Structure Learning - ASDA This repo contains the source code and dataset for our ASDA paper. Illustration of the propo

null 3 Dec 13, 2021
Implementation of "Unsupervised Domain Adaptive 3D Detection with Multi-Level Consistency"

Unsupervised Domain Adaptive 3D Detection with Multi-Level Consistency (ICCV2021) Paper Link: https://arxiv.org/abs/2107.11355 This implementation bui

null 32 Nov 17, 2022
Frequency Spectrum Augmentation Consistency for Domain Adaptive Object Detection

Frequency Spectrum Augmentation Consistency for Domain Adaptive Object Detection Main requirements torch >= 1.0 torchvision >= 0.2.0 Python 3 Environm

null 15 Apr 4, 2022