Joint Discriminative and Generative Learning for Person Re-identification. CVPR'19 (Oral)

Overview

License CC BY-NC-SA 4.0 Python 3.6 Language grade: Python

Joint Discriminative and Generative Learning for Person Re-identification

[Project] [Paper] [YouTube] [Bilibili] [Poster] [Supp]

Joint Discriminative and Generative Learning for Person Re-identification, CVPR 2019 (Oral)
Zhedong Zheng, Xiaodong Yang, Zhiding Yu, Liang Zheng, Yi Yang, Jan Kautz

Table of contents

News

  • 02/18/2021: We release DG-Net++: the extention of DG-Net for unsupervised cross-domain re-id.
  • 08/24/2019: We add the direct transfer learning results of DG-Net here.
  • 08/01/2019: We add the support of multi-GPU training: python train.py --config configs/latest.yaml --gpu_ids 0,1.

Features

We have supported:

  • Multi-GPU training (fp32)
  • APEX to save GPU memory (fp16/fp32)
  • Multi-query evaluation
  • Random erasing
  • Visualize training curves
  • Generate all figures in the paper

Prerequisites

  • Python 3.6
  • GPU memory >= 15G (fp32)
  • GPU memory >= 10G (fp16/fp32)
  • NumPy
  • PyTorch 1.0+
  • [Optional] APEX (fp16/fp32)

Getting Started

Installation

  • Install PyTorch
  • Install torchvision from the source:
git clone https://github.com/pytorch/vision
cd vision
python setup.py install
  • [Optional] You may skip it. Install APEX from the source:
git clone https://github.com/NVIDIA/apex.git
cd apex
python setup.py install --cuda_ext --cpp_ext
  • Clone this repo:
git clone https://github.com/NVlabs/DG-Net.git
cd DG-Net/

Our code is tested on PyTorch 1.0.0+ and torchvision 0.2.1+ .

Dataset Preparation

Download the dataset Market-1501 [Google Drive] [Baidu Disk]

Preparation: put the images with the same id in one folder. You may use

python prepare-market.py          # for Market-1501

Note to modify the dataset path to your own path.

Testing

Download the trained model

We provide our trained model. You may download it from Google Drive (or Baidu Disk password: rqvf). You may download and move it to the outputs.

├── outputs/
│   ├── E0.5new_reid0.5_w30000
├── models
│   ├── best/                   

Person re-id evaluation

  • Supervised learning
Market-1501 DukeMTMC-reID MSMT17 CUHK03-NP
Rank@1 94.8% 86.6% 77.2% 65.6%
mAP 86.0% 74.8% 52.3% 61.1%
  • Direct transfer learning
    To verify the generalizability of DG-Net, we train the model on dataset A and directly test the model on dataset B (with no adaptation). We denote the direct transfer learning protocol as A→B.
Market→Duke Duke→Market Market→MSMT MSMT→Market Duke→MSMT MSMT→Duke
Rank@1 42.62% 56.12% 17.11% 61.76% 20.59% 61.89%
Rank@5 58.57% 72.18% 26.66% 77.67% 31.67% 75.81%
Rank@10 64.63% 78.12% 31.62% 83.25% 37.04% 80.34%
mAP 24.25% 26.83% 5.41% 33.62% 6.35% 40.69%

Image generation evaluation

Please check the README.md in the ./visual_tools.

You may use the ./visual_tools/test_folder.py to generate lots of images and then do the evaluation. The only thing you need to modify is the data path in SSIM and FID.

Training

Train a teacher model

You may directly download our trained teacher model from Google Drive (or Baidu Disk password: rqvf). If you want to have it trained by yourself, please check the person re-id baseline repository to train a teacher model, then copy and put it in the ./models.

├── models/
│   ├── best/                   /* teacher model for Market-1501
│       ├── net_last.pth        /* model file
│       ├── ...

Train DG-Net

  1. Setup the yaml file. Check out configs/latest.yaml. Change the data_root field to the path of your prepared folder-based dataset, e.g. ../Market-1501/pytorch.

  2. Start training

python train.py --config configs/latest.yaml

Or train with low precision (fp16)

python train.py --config configs/latest-fp16.yaml

Intermediate image outputs and model binary files are saved in outputs/latest.

  1. Check the loss log
 tensorboard --logdir logs/latest

DG-Market

We provide our generated images and make a large-scale synthetic dataset called DG-Market. This dataset is generated by our DG-Net and consists of 128,307 images (613MB), about 10 times larger than the training set of original Market-1501 (even much more can be generated with DG-Net). It can be used as a source of unlabeled training dataset for semi-supervised learning. You may download the dataset from Google Drive (or Baidu Disk password: qxyh).

DG-Market Market-1501 (training)
#identity - 751
#images 128,307 12,936

Tips

Note the format of camera id and number of cameras. For some datasets (e.g., MSMT17), there are more than 10 cameras. You need to modify the preparation and evaluation code to read the double-digit camera id. For some vehicle re-id datasets (e.g., VeRi) having different naming rules, you also need to modify the preparation and evaluation code.

Citation

Please cite this paper if it helps your research:

@inproceedings{zheng2019joint,
  title={Joint discriminative and generative learning for person re-identification},
  author={Zheng, Zhedong and Yang, Xiaodong and Yu, Zhiding and Zheng, Liang and Yang, Yi and Kautz, Jan},
  booktitle={IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2019}
}

Related Work

Other GAN-based methods compared in the paper include LSGAN, FDGAN and PG2GAN. We forked the code and made some changes for evaluatation, thank the authors for their great work. We would also like to thank to the great projects in person re-id baseline, MUNIT and DRIT.

License

Copyright (C) 2019 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 (Attribution-NonCommercial-ShareAlike 4.0 International). The code is released for academic research use only. For commercial use, please contact [email protected].

Comments
  • did you resize MSMT17 images to the same size while you training them?

    did you resize MSMT17 images to the same size while you training them?

    hi guys, thanks for your greate contributions. I am just curious while you do the supervised learning for MSMT17 datasets, did you reisze the images to the same size?(since the shape of the images vary in that dataset). If not, how did you deal with that?

    opened by yian2271368 8
  • Reconstruction id embedding loss after detach

    Reconstruction id embedding loss after detach

    Hello, in your ft_netAB id encoder defined in reIDmodel.py you detach the id_embedding:

    f = self.model.partpool(x)
    f = f.view(f.size(0),f.size(1)*self.
    f = f.detach() # no gradient 
    

    In the gen_update loss function in trainer.py you calculate the id embedding reconstruction loss (as specified in your paper) but you are using the detached embeddings:

    self.loss_gen_recon_f_a = self.recon_criterion(f_a_recon, f_a) if hyperparameters['recon_f_w'] > 0 else 0
    self.loss_gen_recon_f_b = self.recon_criterion(f_b_recon, f_b) if hyperparameters['recon_f_w'] > 0 else 0 
    

    Because the embeddings are detached these losses are not constraining the model, did I miss something ?

    opened by juliendenize 7
  • size mismatch

    size mismatch

    Thank you for your code. I try to use MSMT and cuhk03 to train this model, but when I try to enter 'python train.py --config configs/latest.yaml' , command line output an error: ‘size mismatch for classifier.classifier.0.bias: copying a param with shape torch.Size([751]) from checkpoint, the shape in current model is torch.Size([2559]).' I have found out that I must change the param in latest-fp16.yaml and config.yaml(I think config.yaml may be useless in this issue). And I have found out that this error is from /models/best/net_last.pth. The input kinds isn't suitable for this net. Do you have any solution to this or should I change the file? @layumi

    opened by 869250498 7
  • Cross-dataset testing?

    Cross-dataset testing?

    Have you tried cross-dataset testing - training on one dataset, say market1501 and testing on another, say cuhk03 or duke? Have you come across any model with code which has tried this? Will be really grateful to you, thanks in advance.

    opened by ghost 7
  • Some questions about the detach of the f in the ft_netAB

    Some questions about the detach of the f in the ft_netAB

    Hello, thank you very much for providing the implementation code of the DG-Net model. I encountered some problems during the implementation of the project. I will be honored if you can give me some suggestions.

    I found the f=f.detch() in the ft_netAB. This causes the vector f to have no gradient. Then the loss_gen_recon_f_* has no no contribution to model parameter update. Is there something wrong with me or something wrong with the code? 1 2020-04-10 19-50-10屏幕截图

    I will be grateful if you can give me some suggestions. Thank you!

    opened by Liu-1994 6
  • issue with 'net_last.pth'

    issue with 'net_last.pth'

    Hi Thanks for your great work. I use the pre-trained model for feature extraction using function “extract_feature” in the file “test2_label.py”. There is no problem with ‘.pt’ models in the “outputs” folder, but when I want to use the ‘net_last.pth’ model in folder “model” I receive the following error: KeyError Traceback (most recent call last) in () KeyError: 'a' Would you please guide me to debug this error? Is it about the “config.yaml” file exists in folder “outputs” and does not exist in folder “model”? Thank you very much and looking forward to hearing you Regards Hossein

    opened by khodabakhshih 5
  • using feature matrix to calculate loss?

    using feature matrix to calculate loss?

    https://github.com/NVlabs/DG-Net/blob/0abf564a853ea6ec3f38ab71a4a69f7f23b19d24/networks.py#L147

    hey there, here the "outs0" is a feature matrix in shape of 8x1x64x32, and you used it to minus 1 and take the mean of them as loss. what is the principle behind this?

    opened by yian2271368 4
  • Network structure

    Network structure

    Hi @layumi , I was a bit confuse when read your code. I can't find appearance encoder and discriminator like your describe in your paper in your code. are they style encoder and MsImageDis in networks.py right ?

    opened by CuongNguyen218 4
  • One question about generating images

    One question about generating images

    Hello, can you tell me if you have only implemented the change of appearance space, but not the transformation of structure space. For example, to generate a visual Angle image that does not exist in the structure space. Thank u

    opened by muzishen 4
  • What is the meaning of

    What is the meaning of "a,b" in trainer?

    Hi, in DGNet_Trainer, you have gen_a, gen_b. I'm confused that in a single dataset training, do you need two generators a and b? What is the meaning of feeding image a and image b in your trainer? Thanks!

    opened by jackie840129 4
  • Train fp16 interrupt

    Train fp16 interrupt

    Defaults for this optimization level are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic Processing user overrides (additional kwargs that are not None)... After processing overrides, optimization options are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic Selected optimization level O1: Insert automatic casts around Pytorch functions and Tensor methods.

    Defaults for this optimization level are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic Processing user overrides (additional kwargs that are not None)... After processing overrides, optimization options are: enabled : True opt_level : O1 cast_model_type : None patch_torch_functions : True keep_batchnorm_fp32 : None master_weights : None loss_scale : dynamic 1500 265 1500 265 Every epoch need 188 iterations Note that dataloader may hang with too much nworkers. DLoss: 6.0000 Reg: 0.0000

    Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) I installed apex, and use the fp16 config, output this.

    opened by 5Yesterday 3
  • online feeding and identity supervision

    online feeding and identity supervision

    Hi, author. I have a question about your paper. You used online feeding and identity supervision to get the high quality of the generated image. Is it Primary feature learning and Fine-grained feature mining loss, respectively?

    opened by Wooks-git 1
  • IndexError:Dimension out of range(excepted to be in range of [-1,0],but got 1)

    IndexError:Dimension out of range(excepted to be in range of [-1,0],but got 1)

    Hello,can you help me ?thank you! When I use Market data set ,report an error:

    problem: /home/waq/anaconda3/envs/re_person/bin/python /home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py -------test----------- /home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py:182: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. config = yaml.load(stream) Traceback (most recent call last): File "/home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py", line 204, in gallery_feature = extract_feature(model,dataloaders['gallery']) File "/home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py", line 131, in extract_feature x[0] = norm(x[0]) File "/home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py", line 109, in norm fnorm = torch.norm(f, p=2, dim=1, keepdim=True) File "/home/waq/anaconda3/envs/re_person/lib/python3.6/site-packages/torch/functional.py", line 1337, in norm return _VF.norm(input, p, _dim, keepdim=keepdim) # type: ignore IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

    Process finished with exit code 1

    Thank you!

    opened by aiqiangbrave 4
  • when I run train.py, print there error message. Can you help to solve the issue? Thank you !

    when I run train.py, print there error message. Can you help to solve the issue? Thank you !

    Every epoch need 404 iterations Note that dataloader may hang with too much nworkers. Traceback (most recent call last): File "", line 1, in File "C:\Users\hcytech\anaconda3\envs\Python38_yolos\lib\multiprocessing\spawn.py", line 116, in spawn_main exitcode = _main(fd, parent_sentinel) File "C:\Users\hcytech\anaconda3\envs\Python38_yolos\lib\multiprocessing\spawn.py", line 125, in _main prepare(preparation_data) File "C:\Users\hcytech\anaconda3\envs\Python38_yolos\lib\multiprocessing\spawn.py", line 236, in prepare _fixup_main_from_path(data['init_main_from_path']) File "C:\Users\hcytech\anaconda3\envs\Python38_yolos\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path main_content = runpy.run_path(main_path, File "C:\Users\hcytech\anaconda3\envs\Python38_yolos\lib\runpy.py", line 265, in run_path

    opened by yuanqs 1
  • Out of memory error while training the model

    Out of memory error while training the model

    Hello, When I try to train your model, I am getting the Runtime error:CUDA: out of memory error. Can you suggest me anything to get rid of this error?

    Thank you.

    opened by Haneesha123 1
  • How to use DG-Net for vehicle reid?

    How to use DG-Net for vehicle reid?

    Hi, author. I appreciate your work.

    I am a new learner of reid. I want to do some vehicle reid with this project. The dataset i use is VeRi, whose structure is like this: ├── veri/ │ ├── image_train/ │ ├── image_test/
    │ ├── image_query

    我想知道如果训练车辆再识别,项目提供的teacher model和config配置文件等是否还可用?如果不可用,需要对项目做哪些修改。以后项目会不会更新车辆再识别的相关功能呢,请求您的指点。

    thanks a lot.

    opened by twj1999 2
  • Doubt about dis_opt and gen_opt

    Doubt about dis_opt and gen_opt

    In trainer.py, why only update the parameters of dis_a and gen_a and ignore the parameters of dis_b and gen_b? https://github.com/NVlabs/DG-Net/blob/a067be117b43c7c553275b6570b3a3bf8da465e0/trainer.py#L242-L248

    opened by songbo0925 2
Owner
NVIDIA Research Projects
NVIDIA Research Projects
Two-Stream Adaptive Graph Convolutional Networks for Skeleton-Based Action Recognition in CVPR19

2s-AGCN Two-Stream Adaptive Graph Convolutional Networks for Skeleton-Based Action Recognition in CVPR19 Note PyTorch version should be 0.3! For PyTor

LShi 547 Dec 26, 2022
[TIP2020] Adaptive Graph Representation Learning for Video Person Re-identification

Introduction This is the PyTorch implementation for Adaptive Graph Representation Learning for Video Person Re-identification. Get started git clone h

WuYiming 41 Dec 12, 2022
IAUnet: Global Context-Aware Feature Learning for Person Re-Identification

IAUnet This repository contains the code for the paper: IAUnet: Global Context-Aware Feature Learning for Person Re-Identification Ruibing Hou, Bingpe

null 30 Jul 14, 2022
Implementation of "Learning Multi-Granular Hypergraphs for Video-Based Person Re-Identification"

hypergraph_reid Implementation of "Learning Multi-Granular Hypergraphs for Video-Based Person Re-Identification" If you find this help your research,

null 62 Dec 21, 2022
Torchreid: Deep learning person re-identification in PyTorch.

Torchreid Torchreid is a library for deep-learning person re-identification, written in PyTorch. It features: multi-GPU training support both image- a

Kaiyang 3.7k Jan 5, 2023
[BMVC2021] The official implementation of "DomainMix: Learning Generalizable Person Re-Identification Without Human Annotations"

DomainMix [BMVC2021] The official implementation of "DomainMix: Learning Generalizable Person Re-Identification Without Human Annotations" [paper] [de

Wenhao Wang 17 Dec 20, 2022
Paper: Cross-View Kernel Similarity Metric Learning Using Pairwise Constraints for Person Re-identification

Cross-View Kernel Similarity Metric Learning Using Pairwise Constraints for Person Re-identification T M Feroz Ali, Subhasis Chaudhuri, ICVGIP-20-21

T M Feroz Ali 3 Jun 17, 2022
Code of paper Interact, Embed, and EnlargE (IEEE): Boosting Modality-specific Representations for Multi-Modal Person Re-identification.

Interact, Embed, and EnlargE (IEEE): Boosting Modality-specific Representations for Multi-Modal Person Re-identification We provide the codes for repr

null 12 Dec 12, 2022
offical implement of our Lifelong Person Re-Identification via Adaptive Knowledge Accumulation in CVPR2021

LifelongReID Offical implementation of our Lifelong Person Re-Identification via Adaptive Knowledge Accumulation in CVPR2021 by Nan Pu, Wei Chen, Yu L

PeterPu 76 Dec 8, 2022
[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
Unsupervised Pre-training for Person Re-identification (LUPerson)

LUPerson Unsupervised Pre-training for Person Re-identification (LUPerson). The repository is for our CVPR2021 paper Unsupervised Pre-training for Per

null 143 Dec 24, 2022
Person Re-identification

Person Re-identification Final project of Computer Vision Table of content Person Re-identification Table of content Students: Proposed method Dataset

Nguyễn Hoàng Quân 4 Jun 17, 2021
Experiment about Deep Person Re-identification with EfficientNet-v2

We evaluated the baseline with Resnet50 and Efficienet-v2 without using pretrained models. Also Resnet50-IBN-A and Efficientnet-v2 using pretrained on ImageNet. We used two datasets: Market-1501 and CUHK03.

lan.nguyen2k 77 Jan 3, 2023
CM-NAS: Cross-Modality Neural Architecture Search for Visible-Infrared Person Re-Identification (ICCV2021)

CM-NAS Official Pytorch code of paper CM-NAS: Cross-Modality Neural Architecture Search for Visible-Infrared Person Re-Identification in ICCV2021. Vis

JDAI-CV 40 Nov 25, 2022
Exploiting Robust Unsupervised Video Person Re-identification

Exploiting Robust Unsupervised Video Person Re-identification Implementation of the proposed uPMnet. For the preprint, please refer to [Arxiv]. Gettin

null 1 Apr 9, 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
Open source person re-identification library in python

Open-ReID Open-ReID is a lightweight library of person re-identification for research purpose. It aims to provide a uniform interface for different da

Tong Xiao 1.3k Jan 1, 2023
Self-Supervised Pre-Training for Transformer-Based Person Re-Identification

Self-Supervised Pre-Training for Transformer-Based Person Re-Identification [pdf] The official repository for Self-Supervised Pre-Training for Transfo

Hao Luo 45 Dec 3, 2021
Large-Scale Pre-training for Person Re-identification with Noisy Labels (LUPerson-NL)

LUPerson-NL Large-Scale Pre-training for Person Re-identification with Noisy Labels (LUPerson-NL) The repository is for our CVPR2022 paper Large-Scale

null 43 Dec 26, 2022