[NeurIPS-2020] Self-paced Contrastive Learning with Hybrid Memory for Domain Adaptive Object Re-ID.

Related tags

Deep Learning SpCL
Overview

Python >=3.5 PyTorch >=1.0

Self-paced Contrastive Learning (SpCL)

The official repository for Self-paced Contrastive Learning with Hybrid Memory for Domain Adaptive Object Re-ID, which is accepted by NeurIPS-2020. SpCL achieves state-of-the-art performances on both unsupervised domain adaptation tasks and unsupervised learning tasks for object re-ID, including person re-ID and vehicle re-ID.

framework

Updates

[2020-10-13] All trained models for the camera-ready version have been updated, see Trained Models for details.

[2020-09-25] SpCL has been accepted by NeurIPS on the condition that experiments on DukeMTMC-reID dataset should be removed, since the dataset has been taken down and should no longer be used.

[2020-07-01] We did the code refactoring to support distributed training, stronger performances and more features. Please see OpenUnReID.

Requirements

Installation

git clone https://github.com/yxgeee/SpCL.git
cd SpCL
python setup.py develop

Prepare Datasets

cd examples && mkdir data

Download the person datasets Market-1501, MSMT17, PersonX, and the vehicle datasets VehicleID, VeRi-776, VehicleX. Then unzip them under the directory like

SpCL/examples/data
├── market1501
│   └── Market-1501-v15.09.15
├── msmt17
│   └── MSMT17_V1
├── personx
│   └── PersonX
├── vehicleid
│   └── VehicleID -> VehicleID_V1.0
├── vehiclex
│   └── AIC20_ReID_Simulation -> AIC20_track2/AIC20_ReID_Simulation
└── veri
    └── VeRi -> VeRi_with_plate

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

SpCL/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-1080TI GPUs for training. Note that

  • The training for SpCL is end-to-end, which means that no source-domain pre-training is required.
  • use --iters 400 (default) for Market-1501 and PersonX datasets, and --iters 800 for MSMT17, VeRi-776, VehicleID and VehicleX datasets;
  • use --width 128 --height 256 (default) for person datasets, and --height 224 --width 224 for vehicle datasets;
  • use -a resnet50 (default) for the backbone of ResNet-50, and -a resnet_ibn50a for the backbone of IBN-ResNet.

Unsupervised Domain Adaptation

To train the model(s) in the paper, run this command:

CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_uda.py \
  -ds $SOURCE_DATASET -dt $TARGET_DATASET --logs-dir $PATH_OF_LOGS

Some examples:

### PersonX -> Market-1501 ###
# use all default settings is ok
CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_uda.py \
  -ds personx -dt market1501 --logs-dir logs/spcl_uda/personx2market_resnet50

### Market-1501 -> MSMT17 ###
# use all default settings except for iters=800
CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_uda.py --iters 800 \
  -ds market1501 -dt msmt17 --logs-dir logs/spcl_uda/market2msmt_resnet50

### VehicleID -> VeRi-776 ###
# use all default settings except for iters=800, height=224 and width=224
CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_uda.py --iters 800 --height 224 --width 224 \
  -ds vehicleid -dt veri --logs-dir logs/spcl_uda/vehicleid2veri_resnet50

Unsupervised Learning

To train the model(s) in the paper, run this command:

CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_usl.py \
  -d $DATASET --logs-dir $PATH_OF_LOGS

Some examples:

### Market-1501 ###
# use all default settings is ok
CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_usl.py \
  -d market1501 --logs-dir logs/spcl_usl/market_resnet50

### MSMT17 ###
# use all default settings except for iters=800
CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_usl.py --iters 800 \
  -d msmt17 --logs-dir logs/spcl_usl/msmt_resnet50

### VeRi-776 ###
# use all default settings except for iters=800, height=224 and width=224
CUDA_VISIBLE_DEVICES=0,1,2,3 \
python examples/spcl_train_usl.py --iters 800 --height 224 --width 224 \
  -d veri --logs-dir logs/spcl_usl/veri_resnet50

Evaluation

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

  • use --width 128 --height 256 (default) for person datasets, and --height 224 --width 224 for vehicle datasets;
  • use --dsbn for domain adaptive models, and add --test-source if you want to test on the source domain;
  • use -a resnet50 (default) for the backbone of ResNet-50, and -a resnet_ibn50a for the backbone of IBN-ResNet.

Unsupervised Domain Adaptation

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

CUDA_VISIBLE_DEVICES=0 \
python examples/test.py --dsbn \
  -d $DATASET --resume $PATH_OF_MODEL

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

CUDA_VISIBLE_DEVICES=0 \
python examples/test.py --dsbn --test-source \
  -d $DATASET --resume $PATH_OF_MODEL

Some examples:

### Market-1501 -> MSMT17 ###
# test on the target domain
CUDA_VISIBLE_DEVICES=0 \
python examples/test.py --dsbn \
  -d msmt17 --resume logs/spcl_uda/market2msmt_resnet50/model_best.pth.tar
# test on the source domain
CUDA_VISIBLE_DEVICES=0 \
python examples/test.py --dsbn --test-source \
  -d market1501 --resume logs/spcl_uda/market2msmt_resnet50/model_best.pth.tar

Unsupervised Learning

To evaluate the model, run:

CUDA_VISIBLE_DEVICES=0 \
python examples/test.py \
  -d $DATASET --resume $PATH

Some examples:

### Market-1501 ###
CUDA_VISIBLE_DEVICES=0 \
python examples/test.py \
  -d market1501 --resume logs/spcl_usl/market_resnet50/model_best.pth.tar

Trained Models

framework

You can download the above models in the paper from [Google Drive] or [Baidu Yun](password: w3l9).

Citation

If you find this code useful for your research, please cite our paper

@inproceedings{ge2020selfpaced,
    title={Self-paced Contrastive Learning with Hybrid Memory for Domain Adaptive Object Re-ID},
    author={Yixiao Ge and Feng Zhu and Dapeng Chen and Rui Zhao and Hongsheng Li},
    booktitle={Advances in Neural Information Processing Systems},
    year={2020}
}
Comments
  • Problem with the MSMT dataset

    Problem with the MSMT dataset

    Hello, I think there is something wrong with my MSMT17 dataset, with which I have mAP 6.5% and rank-1 15.3%. I believe that there must be something different. Would you like to provide your MSMT17 dataset ? Thank you very much.

    opened by AyiStar 14
  • Question on the baseline model constructed from your code

    Question on the baseline model constructed from your code

    Hi, I constructed a clustering-based unsupervised baseline from your code, which obtains much higher performance (Market: rank1=91.1%,mAP=79.5%) than the pure unsupervised version in your paper (w/o source data, Market: rank1=88.1%, mAP=73.1%), so i got a little confused and curious, have you ever experimented with the baseline described below:

    Using the same network and hyper-parameter setting, the baseline differs from your method in the following:

    1. Before each epoch, the image features $f_i$ are extracted by the recent model and utilized for DBSCAN clustering (without the self-paced independence and compactness refinement);
    2. A cluster-level memory bank is re-constructed with shape=(num_clusters, num_features), and initialized by the averaged image feature $f_i$ for each cluster;
    3. the model is trained by removing the outliers from training;

    Since such a memory-based clustering-fine-tuning baseline seems very naive, i'm confused why it performs so well. Any advice or insight would be much appreciated~

    opened by Terminator8758 9
  • hello, anyone meet this error?

    hello, anyone meet this error?

    Computing jaccard distance... bruteForceKnn is deprecated; call bfKnn instead Faiss assertion 'err__ == cudaSuccess' failed in void faiss::gpu::runL2Norm(faiss::gpu::Tensor<T, 2, true, IndexType>&, bool, faiss::gpu::Tensor<float, 1, true, IndexType>&, bool, cudaStream_t) [with T = float; TVec = float4; IndexType = int; cudaStream_t = CUstream_st*] at gpu/impl/L2Norm.cu:292; details: CUDA error 11 invalid argument Aborted (core dumped)

    env info:

    torch1.7.0 cuda11.1 2080TI

    opened by Bobo-y 8
  • About the dataset centroid initialization

    About the dataset centroid initialization

    image About two hours passed,the ‘Initialize source-domain class centroids in the hybrid memory’ is still there. Is this normal?

    the nvidia-smi screen shot(it seem like normal): image target-domin question: image

    image

    opened by ShiMinghao0208 8
  • the update of the hybrid memory

    the update of the hybrid memory

    how can i debug the hybrid memory's features. i just change the moemtumn update function to the simple ctx.features = ctx.features +1 . And when i debug the hm.py, the self.features is never changed.

    opened by crazydemo 7
  • about personx dataset

    about personx dataset

    In spcl/datasets/personx.py, it shows that # images: 9840 (train) + 5136 (query) + 30816 (gallery), I just find the personx_v1 dataset in https://github.com/sxzrt/Instructions-of-the-PersonX-dataset, but this train number and query number doesn't match the code. And the camera id doesn't match too. So I want to know which version of personx did you use?

    opened by darcyzhc 7
  • num of gpus

    num of gpus

    Hi, I tried to run this program with two GPUs, and it turned out to be very different from the result of 4 GPUs, and the loss of using 2 GPUs drops quickly. Is this program related to the number of GPUs?

    opened by sxwenny 7
  • An error occurred when creating a pseudo label

    An error occurred when creating a pseudo label

    ==> Create pseudo labels for unlabeled target domain with self-paced policy Computing jaccard distance... Traceback (most recent call last): File "examples/spcl_train_uda.py", line 341, in main() File "examples/spcl_train_uda.py", line 109, in main main_worker(args) File "examples/spcl_train_uda.py", line 175, in main_worker rerank_dist = compute_jaccard_distance(target_features, k1=args.k1, k2=args.k2) File "/home/amax/SpCL/spcl/utils/faiss_rerank.py", line 41, in compute_jaccard_distance _, initial_rank = search_raw_array_pytorch(res, target_features, target_features, k1) File "/home/amax/SpCL/spcl/utils/faiss_utils.py", line 82, in search_raw_array_pytorch I_ptr = swig_ptr_from_LongTensor(I) File "/home/amax/SpCL/spcl/utils/faiss_utils.py", line 15, in swig_ptr_from_LongTensor return faiss.cast_integer_to_long_ptr( AttributeError: module 'faiss' has no attribute 'cast_integer_to_long_ptr'

    opened by Wang-pengfei 5
  • cannot reproduce the results in the paper

    cannot reproduce the results in the paper

    Thanks for your insightful work. I have runned the uda code for duke to market. The result is rank1: 86.9%, mAP:71.6, which are 3.39% less than that in the paper (rank1: 90.3%, map: 76.7%). Why?

    opened by shuxjweb 4
  • gap between single 2080ti GPU and double 2080ti GPU

    gap between single 2080ti GPU and double 2080ti GPU

    Hi!thx to your work!My question is that when I train the spcl with default config from two 2080ti gpus to single 2080ti gpu,the result drops about 6% in mAP. So I want to know the reason about it, thank u !

    opened by JackyZDHu 3
  • errors occured when testing

    errors occured when testing

    While run the examples/test.py, there are some errors: 1、It failed in examples/test.py[line:70] model = models.create(args.arch, pretrained=False, num_features=args.features, dropout=args.dropout, num_classes=0), the solution is to set pretrained=True

    2、It failed in examples/test.py[line:90] evaluator.evaluate(test_loader, dataset.query, dataset.gallery, cmc_flag=True, rerank=args.rerank), where the args.rerank is True. The reason is that AttributeError: 'tuple' object has no attribute 'numpy' in spcl/evaluators.py[line:121] distmat = re_ranking(distmat.numpy(), distmat_qq.numpy(), distmat_gg.numpy()), the distmat_qq and distmat_gg is tuple but not tensor. I don't know how to solve this problem.

    Please help to solve these problems.

    opened by darcyzhc 3
  • About the momentum update

    About the momentum update

    Hello, when I debug the program with a one-step, I can't run to the location where the memory bank is updated, which is lines 28 to 32 of hm.py, is there something wrong with my debugging method?

    opened by KLJ-70 0
  • Memory Error

    Memory Error

    Hello All, Please has a fix been identified for this error. RuntimeError: Error in void faiss::gpu::allocMemorySpaceV(faiss::gpu::MemorySpace, void**, size_t) at gpu/utils/MemorySpace.cpp:26: Error: 'err == cudaSuccess' failed: failed to cudaMalloc 1610612736 bytes (error 2 out of memory) Your suggestions are welcomed. I tried to changes the K2 and K1 parameters to no avail. I hope to hear from you.

    opened by Akola-Mbey-Denis 0
  • Is there anybody meet this problem?

    Is there anybody meet this problem?

    bruteForceKnn is deprecated; call bfKnn instead Faiss assertion 'err__ == cudaSuccess' failed in void faiss::gpu::runL2Norm(faiss::gpu::Tensor<T, 2, true, IndexType>&, bool, faiss::gpu::Tensor<float, 1, true, IndexType>&, bool, cudaStream_t) [with T = float; TVec = float4; IndexType = int; cudaStream_t = CUstream_st*] at gpu/impl/L2Norm.cu:292; details: CUDA error 11 invalid argument

    opened by m250317460 0
  • There are some questions related to the cluster center in the code

    There are some questions related to the cluster center in the code

    I found that when calculating the loss in the dynamic memory bank, the cluster center feature is not used, or the instance-level feature is used. May I be the one who made a mistake?

    opened by WentaoTan 1
Owner
Yixiao Ge
Ph.D Candidate @ CUHK-MMLab
Yixiao Ge
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
The Dual Memory is build from a simple CNN for the deep memory and Linear Regression fro the fast Memory

Simple-DMA a simple Dual Memory Architecture for classifications. based on the paper Dual-Memory Deep Learning Architectures for Lifelong Learning of

null 1 Jan 27, 2022
This is an official PyTorch implementation of Task-Adaptive Neural Network Search with Meta-Contrastive Learning (NeurIPS 2021, Spotlight).

NeurIPS 2021 (Spotlight): Task-Adaptive Neural Network Search with Meta-Contrastive Learning This is an official PyTorch implementation of Task-Adapti

Wonyong Jeong 15 Nov 21, 2022
Implementation of a memory efficient multi-head attention as proposed in the paper, "Self-attention Does Not Need O(n²) Memory"

Memory Efficient Attention Pytorch Implementation of a memory efficient multi-head attention as proposed in the paper, Self-attention Does Not Need O(

Phil Wang 180 Jan 5, 2023
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
An adaptive hierarchical energy management strategy for hybrid electric vehicles

An adaptive hierarchical energy management strategy This project contains the source code of an adaptive hierarchical EMS combining heuristic equivale

null 19 Dec 13, 2022
Official pytorch implementation of "Feature Stylization and Domain-aware Contrastive Loss for Domain Generalization" ACMMM 2021 (Oral)

Feature Stylization and Domain-aware Contrastive Loss for Domain Generalization This is an official implementation of "Feature Stylization and Domain-

null 22 Sep 22, 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
[NeurIPS 2021 Spotlight] Aligning Pretraining for Detection via Object-Level Contrastive Learning

SoCo [NeurIPS 2021 Spotlight] Aligning Pretraining for Detection via Object-Level Contrastive Learning By Fangyun Wei*, Yue Gao*, Zhirong Wu, Han Hu,

Yue Gao 139 Dec 14, 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
PyTorch Code of "Memory In Memory: A Predictive Neural Network for Learning Higher-Order Non-Stationarity from Spatiotemporal Dynamics"

Memory In Memory Networks It is based on the paper Memory In Memory: A Predictive Neural Network for Learning Higher-Order Non-Stationarity from Spati

Yang Li 12 May 30, 2022
:hot_pepper: R²SQL: "Dynamic Hybrid Relation Network for Cross-Domain Context-Dependent Semantic Parsing." (AAAI 2021)

R²SQL The PyTorch implementation of paper Dynamic Hybrid Relation Network for Cross-Domain Context-Dependent Semantic Parsing. (AAAI 2021) Requirement

huybery 60 Dec 31, 2022
Run Effective Large Batch Contrastive Learning on Limited Memory GPU

Gradient Cache Gradient Cache is a simple technique for unlimitedly scaling contrastive learning batch far beyond GPU memory constraint. This means tr

Luyu Gao 198 Dec 29, 2022
Diverse Image Captioning with Context-Object Split Latent Spaces (NeurIPS 2020)

Diverse Image Captioning with Context-Object Split Latent Spaces This repository is the PyTorch implementation of the paper: Diverse Image Captioning

Visual Inference Lab @TU Darmstadt 34 Nov 21, 2022
Segcache: a memory-efficient and scalable in-memory key-value cache for small objects

Segcache: a memory-efficient and scalable in-memory key-value cache for small objects This repo contains the code of Segcache described in the followi

TheSys Group @ CMU CS 78 Jan 7, 2023
Episodic-memory - Ego4D Episodic Memory Benchmark

Ego4D Episodic Memory Benchmark EGO4D is the world's largest egocentric (first p

null 3 Feb 18, 2022
[WWW 2021] Source code for "Graph Contrastive Learning with Adaptive Augmentation"

GCA Source code for Graph Contrastive Learning with Adaptive Augmentation (WWW 2021) For example, to run GCA-Degree under WikiCS, execute: python trai

Big Data and Multi-modal Computing Group, CRIPAC 97 Jan 7, 2023
BossNAS: Exploring Hybrid CNN-transformers with Block-wisely Self-supervised Neural Architecture Search

BossNAS This repository contains PyTorch evaluation code, retraining code and pretrained models of our paper: BossNAS: Exploring Hybrid CNN-transforme

Changlin Li 127 Dec 26, 2022
Self-supervised Multi-modal Hybrid Fusion Network for Brain Tumor Segmentation

JBHI-Pytorch This repository contains a reference implementation of the algorithms described in our paper "Self-supervised Multi-modal Hybrid Fusion N

FeiyiFANG 5 Dec 13, 2021