Giter Club home page Giter Club logo

hhcl-reid's Introduction

HHCL-ReID visitors

Tweet PWC PWC

This repository is the official implementation of our paper "Hard-sample Guided Hybrid Contrast Learning for Unsupervised Person Re-Identification!".

framework_HCCL

Requirements


git clone https://github.com/bupt-ai-cz/HHCL-ReID.git
cd HHCL-ReID
pip install -r requirements.txt
python setup.py develop

Prepare Datasets


Download the datasets Market-1501,MSMT17,DukeMTMC-reID from this link and unzip them under the directory like:

HHCL-ReID/examples/data
├── market1501
│   └── Market-1501-v15.09.15
└── dukemtmcreid
    └── DukeMTMC-reID

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 examples/pretrained/.

HHCL-ReID/examples
└── pretrained
    └── resnet50_ibn_a.pth.tar

Training


We utilize 4 GTX-2080TI GPUs for training. Examples:

Market-1501:

CUDA_VISIBLE_DEVICES=0,1,2,3 python examples/train.py -b 256 -a resnet50 -d market1501 --iters 200 --eps 0.45 --momentum 0.1 --num-instances 16 --pooling-type avg --memorybank CMhybrid --epochs 60 --logs-dir examples/logs/market1501/resnet50_avg_cmhybrid

DukeMTMC-reID:

CUDA_VISIBLE_DEVICES=0,1,2,3 python examples/train.py -b 256 -a resnet50 -d dukemtmcreid --iters 200 --eps 0.6 --momentum 0.1 --num-instances 16 --pooling-type avg --memorybank CMhybrid --epochs 60 --logs-dir examples/logs/dukemtmcreid/resnet50_avg_cmhybrid
  • use -a resnet50 (default) for the backbone of ResNet-50, and -a resnet_ibn50a for the backbone of IBN-ResNet;
  • use --pooling-type gem for Generalized Mean Pooling (GEM) pooling and --smooth for label smoothing.

Evaluation


To evaluate my model on ImageNet, run:

CUDA_VISIBLE_DEVICES=0 python examples/test.py -d $DATASET --resume $PATH --pooling-type avg

Results


Our model achieves the following performance on :

Dataset Market1501 DukeMTMC-reID
Setting mAP R1 R5 R10 mAP R1 R5 R10
Fully Unsupervised 84.2 93.4 97.7 98.5 73.3 85.1 92.4 94.6
Supervised 87.2 94.6 98.5 99.1 80.0 89.8 95.2 96.7

You can download the above models in the paper from Google Drive

Citation


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

@article{hu2021hard,
  title={Hard-sample Guided Hybrid Contrast Learning for Unsupervised Person Re-Identification},
  author={Hu, Zheng and Zhu, Chuang and He, Gang},
  journal={arXiv preprint arXiv:2109.12333},
  year={2021}
}

Acknowledgements


This project is not possible without multiple great opensourced codebases. We list them below.

hhcl-reid's People

Contributors

bupt-ai-cz avatar hu-zheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hhcl-reid's Issues

关于outlier的弃用

我发现这里训练的时候没有使用到outlier,这样会损失一部分的数据在模型更新上?请问有实验过加outlier的情况吗?

关于CMhybrid和CMhybrid_v2两种Memory Bank的理解疑惑

您好,感谢您进一步完善了相关代码。

在复现及阅读代码过程中遇到一些问题,经过一段时间还是有疑惑,在此提问,希望您能抽出宝贵时间来解惑。

在论文4.3节提到,新构建了一个P*C的instance features memory bank。在代码中,这一部分对应到train.py的206-212行代码,有CMhybrid和CMhybrid_v2两种类型bank。CMhybrid是直接加倍cluster_featuers;CMhybrid_v2则按照论文所说从每个类中随机抽取P个instace feature,相当于在cluster_features基础上新加了P*C个特征。

按照您提供的训练模型,性能较好的却是采用CMhybrid类型的bank,而CMhybrid没有构建论文4.3节中提出的P*C的instance feature memory bank.这个核心点。

请问我理解的对吗?

CMhybrid和CMhybrid_v2的区别您认为有何不同呢?

非常期待您的回复!

注:train.py和cm.py文件中,cmhybrid拼写出现了小错误。

可视化

请问有没有可视化的例子呢

ModuleNotFoundError: No module named 'hhcl.datasets.veri'

(tf1.14) root@dl-220706210722719-pod-jupyter-58b598676f-pfb64:~/HHCL-ReID# CUDA_VISIBLE_DEVICES=0 python examples/train.py -b 256 -a resnet50 -d market1501 --iters 200 --eps 0.45 --momentum 0.1 --num-instances 16 --pooling-type avg --memorybank CMhybrid --epochs 60 --logs-dir examples/logs/market1501/resnet50_avg_cmhybrid
Traceback (most recent call last):
File "examples/train.py", line 20, in
from hhcl import datasets
File "/root/HHCL-ReID/hhcl/init.py", line 3, in
from . import datasets
File "/root/HHCL-ReID/hhcl/datasets/init.py", line 7, in
from .veri import VeRi
ModuleNotFoundError: No module named 'hhcl.datasets.veri'

hard sample

image
请问这段代码的意思是用hard positive去对当前质心做动量更新吗?这样可以对应论文中的使用hard positive做对比学习吗?那hard negtive如何在代码中体现呢?

难正负样本公式问题

您好,论文中公式(6)(7)采用余弦相似度来挑选难正样本和难负样本,但是为何难正样本是argmax,难负样本是argmin呢?不应该反过来吗?
非常期待您的回复~
image

精度偏低的原因

当我用两个GPU,选择batch_size为128时,在market1501数据集上的map只有75.0,与论文中数据对比降低了10个百分点。请问这个数据合理吗?

关于总loss公式

loss = self.hard_weight * (self.cross_entropy(output_hard, targets) + (1 - self.hard_weight) * self.cross_entropy(output_mean, targets))

您好,我想求教一下,这个loss公式和论文中的公式2吻合吗?

GPU显存

想问一下您的GPU显存是多少呢

GPU numbers

Is the number of GPUs or type of GPU effective in accuracy that achieved in the paper? and if yes, why?
If I don't have 4 GPUs and I have 1 GPU, what would happen when running the code?
and what should I have do to get the paper results with 1 GPU?

model下载链接指向SPCL;库中文件缺失

您好,感谢您非常出色的工作!

但是我在复现时遇到一些问题:

  1. model下载链接指向错误,指向了SPCL的训练后的模型,难道通用?
  2. evaluation_metrics文件夹中缺失ranking.py文件。我使用cluster-contrast-reid中的文件进行替换后可以运行,但不知是否有影响。
  3. utils文件夹下缺失serialization.py文件。解决方法同2。

非常期待您的回复,谢谢!

运行问题

运行过程中出现下面的问题 是什么原因呢 该怎么解决呢
==> Statistics for epoch 0: 1 clusters
Traceback (most recent call last):
File "/export/H/examples/hhcl/utils/data/init.py", line 24, in next
return next(self.iter)
File "/export/zhangshuorui/anacondagpu/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in next
data = self._next_data()
File "/export/anacondagpu/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1176, in _next_data
raise StopIteration
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "examples/train.py", line 397, in
main()
File "examples/train.py", line 122, in main
main_worker(args)
File "examples/train.py", line 314, in main_worker
trainer.train(epoch, train_loader, optimizer,
File "/export/H/examples/hhcl/trainers.py", line 25, in train
inputs = data_loader.next()
File "/export/H/examples/hhcl/utils/data/init.py", line 27, in next
return next(self.iter)
File "/export/anacondagpu/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in next
data = self._next_data()
File "/export/anacondagpu/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1176, in _next_data
raise StopIteration
StopIteration

运行命令
CUDA_VISIBLE_DEVICES=6,7 python examples/train.py -b 256 -a resnet50 -d market1501 --iters 200 --eps 0.45 --num-instances 16 --pooling-type avg --memorybank CMhybrid --epochs 60 --logs-dir examples/logs/market1501/resnet50_avg_cmhybrid
数据集存放路径
examples/data/market1501/Market-1501-v15.09.15

单卡训练降低10+ pp. 性能

你好,我用一块RTX 24g的卡在market1501数据集上使用命令训练:

PYTHONIOENCODING=utf-8 CUDA_VISIBLE_DEVICES=0 python train.py -b 256 -a resnet50 -d market1501 \
--iters 200 --eps 0.45 --num-instances 16 --pooling-type avg --memorybank CMhybrid --epochs 60 \
--logs-dir work_dirs/logs/market1501/resnet50_avg_cmhybrid�

但得到的结果mAP=71.4,Top-1=85.7,相差10个点以上,请问,单卡训练时有影响性能的情况么?其他的参数有什么需要另外设置的嘛?
谢谢!

关于算法最终性能的一些疑问

首先感谢您做出的杰出贡献!
最近在我复现您的代码的过程中,我发现我复现的结果和您论文中的结果存在一定的性能差距。我在market1501上不做任何修改使用run.sh中的命令执行,使用CMhybrid memory最终获得的性能是82.4%mAP,和84.2有些差距。请问下您还有使用一些别的技巧或者改进了代码进一步提高了性能?
期待得到您的回复,谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.