Git Product home page Git Product logo

light-reid's Introduction

light-reid

a toolbox of light reid for fast feature extraction and search

  • light-model: model distillation (3x faster feature extraction)
  • light-feature: binary code learning (6x faster retrieval)
  • light-search: coarse2fine search (2x faster retrieval)

it features

  • easy switch between light and non-light reid
  • simple modules for reid implementation
  • implementations of state-of-the-art deep reid models

What's New

  • [2021.06]: we support vision transformers as cnn backbones. please refer base_config_duke_vit.yaml
  • [2020.12]: we release a strong pipeline for occluded/partial re-id. please refer occluded_reid
  • [2020.11]: we support pca_reduction to 128d with almost no accuracy drop. please refer bagtricks_pca
  • [2020.11]: we support build with config files, making coding more simple. please refer bagtricks_buildwithconfigs
  • [2020.08]: We release a toolbox of light-reid learning for faster inference, getting >30x faster speed.
  • [2020.03]: We implement BagTricks and support IBN-Net, MSMT17, combineall, multi-dataset train. Please see branch version_py3.7_bot.
  • [2019.03]: We give a clean implemention of BagTricks with python2.7. Please see branch version_py2.7.

Find our Works

  • [2020.07]: [ECCV'20] Our work about Fast ReID has been accepted by ECCV'20. (Paper, Code)
  • [2020.03]: [CVPR'20] Our work about Occluded ReID has been accepted by CVPR'20. (Paper, Code).
  • [2020.01]: [AAAI'20] Our work about RGB-Infrared(IR) ReID has been accepted by AAAI'20. (Paper, Code).
  • [2019.10]: [ICCV'19] Our work about RGB-Infrared(IR) ReID has been accepted by ICCV'19. (Paper, Code).
  • [2019.05]: We implement PCB and achieve better performance than the offical one. (Code)

Installation

# clone this repo
git clone https://github.com/wangguanan/light-reid.git

# create environment
cd light-reid
conda create -n lightreid python=3.7
conda activate lightreid

# install dependencies
pip install -r requirements

# install torch and torchvision (select the proper cuda version to suit your machine)
conda install pytorch==1.4.0 torchvision -c pytorch
# install faiss for stable search
conda install faiss-cpu -c pytorch

Prepare Datasets

Quick Start

1 step to build a SOTA reid model with configs

Implemented reid methods and experimental results

Acknowledge

Our light-reid partially refers open-sourced torch-reid and fast-reid, we thank their awesome contribution to reid community.

If you have any question about this reid toolbox, please feel free to contact me. E-mail: [email protected]

LICENSE

light-reid is released released under the MIT License.

Citation

if you find the repo is useful, please kindly cite our works

@article{wang2020faster,
 title="Faster Person Re-Identification.",
 author="Guan'an {Wang} and Shaogang {Gong} and Jian {Cheng} and Zengguang {Hou}",
 journal="In Proceedings of the European Conference on Computer Vision (ECCV)",
 year="2020"
}

@article{wang2020honet,
 title="High-Order Information Matters: Learning Relation and Topology for Occluded Person Re-Identification.",
 author="Guan'an {Wang} and Shuo {Yang} and Huanyu {Liu} and Zhicheng {Wang} and Yang {Yang} and Shuliang {Wang} and Gang {Yu} and Erjin {Zhou} and Jian {Sun}",
 journal="In Proceedings of the 2020 IEEE Conference on Computer Vision and Pattern Recognition (CVPR)",
 year="2020"
}

light-reid's People

Contributors

wangguanan 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

light-reid's Issues

你好,感谢您的分享

feature dim的multiple指的是什么呢?

以及表格最后一列的搜索耗时是否使用了faiss?

What's the licence?

Can I use your code/model in an open source plugin (MPL-2.0) for a commercial application (Video Management System)?

通用reid (非仅遮挡)

您好作者,
谢谢您的工作^^, 这里有个问题请教您,您的实验结果主要是在遮挡问题的描述, 您觉得在通用问题上用您的方式,可以又更好的模型性能吗?您做过相关实验吗?

关于Lpro损失

感谢您的工作,给我非常大的启发。但是我刚入门对一些知识还没有想明白,比如说您在论文中的Lpro distillation loss,
zk+1和zk应该是属于不同的长度的(k更长,k+1),为什么它可以用交叉熵损失来计算呢,一般情况下,比如我们的特征和最后的标签采用交叉熵损失计算一般都需要保持维度的相同,Lsim也是同样的道理不知道这里为什么可以直接计算,不是很明白,我看了您的代码应该在这部分
loss = torch.sum(prob2 * torch.log(mini + prob2 / (prob1 + mini)), 1) +
torch.sum(prob1 * torch.log(mini + prob1 / (prob2 + mini)), 1)
为啥可以直接相除,期待您的回复^^

你好,请教一下知识蒸馏方面的问题

在代码中看到蒸馏部分的loss主要是
class KLLoss:
'''KL Divergence'''

def __init__(self, t=4):
    self.t = t

def __call__(self, logits_s, logits_t):
    p_s = F.log_softmax(logits_s / self.t, dim=1)
    p_t = F.softmax(logits_t / self.t, dim=1)
    loss = F.kl_div(p_s, p_t, reduction='sum') * (self.t ** 2) / logits_s.shape[0]
    return loss

请问关于这里的原理相应论文可以用来学习吗,感谢~

typo

Hi, thanks for your awesome work!
I found that there is a typo in line44 in loss.py. (def _label2similarity(**sekf**, label1, label2): )

Pretrained models

Hi, thanks for your work. I have a question.
Are some pre-trained models available or will be available soon ?

base_config_duke_res18_lightmodel_lightfeat.yaml

作者您好:
我想問我在使用bagtricks_buildwithconfigs時使用python train.py --config_file ./configs/base_config_duke_res19_lightmodel_lightfeat.yaml,由於我沒有pretrain的model我將light_model功能關閉,的時候會出現

home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/_reduction.py:43: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
  warnings.warn(warning.format(ret))
Traceback (most recent call last):
  File "train.py", line 22, in <module>
    solver.train(eval_freq=10)
  File "../../lightreid/engine/engine.py", line 209, in train
    self.eval(onebyone=False)
  File "../../lightreid/engine/engine.py", line 273, in eval
    query_feats, query_pids, query_camids = self.extract_feats(query_loader, time_meter=time_meter)
  File "../../lightreid/engine/engine.py", line 426, in extract_feats
    feats = self.model(imgs)
  File "/home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 150, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "../../lightreid/models/architectures/base_arch.py", line 41, in forward
    res = self.head(feats_vec, y)
  File "/home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "../../lightreid/models/heads/code_pyramid.py", line 62, in forward
    binary_codes = neck(feats, use_tanh=use_tanh)
  File "/home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'use_tanh'

這是再有開啟clean engine之下,如果將clean engine關閉會出現

/home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/_reduction.py:43: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
  warnings.warn(warning.format(ret))
Traceback (most recent call last):
  File "train.py", line 19, in <module>
    solver = lightreid.build_engine(config)
  File "../../lightreid/build.py", line 50, in build_engine
    **cfg.env, **cfg.lightreid)
  File "../../lightreid/engine/engine.py", line 107, in __init__
    self.model.enable_tanh()
  File "/home/pp/anaconda3/envs/lightreid/lib/python3.7/site-packages/torch/nn/modules/module.py", line 576, in __getattr__
    type(self).__name__, name))
AttributeError: 'BaseReIDModel' object has no attribute 'enable_tanh'

我在project之中找不到enable_tanh的function
如果將light model,light feat, light search關閉,則可以正常運作。
還請作者幫忙解答了,謝謝!

Wrong result about visualization

Hi, author, thank you for your excellent work. I add some visualization code in the file "retrieval.py" to show the top 10 similar images with the query image by the method "evaluate". But I got the wrong result as the following picture. It seems something wrong with the pids of gallery images which are different from each other. To say, the labels are the same but not the correct ones, so I think the labeling process or the "evaluate" method are not right.

图片

WildTrackCrop dataset

Dear @wangguanan
Thanks for sharing your work.
I have tried to download the Wildtrack dataset. When I crop person images using the information provided in the annotation_positions, I see boxes are not fitted to persons.
How do you get the WildTrackCrop? Could you share me via Googledrive?

'CleanEngine' object has no attribute 'evaluator'

蒸馏时出现的问题

在我完成base_config_duke_res50.yaml的训练后,我想使用lightmodel的方式蒸馏得到较好的res18模型,我修改了base_config_duke_res18_lightmodel_lightfeat.yamlteacher_path的路径后开始加载训练配置,出现如下的问题:

...
******************** light-reid settings ******************** 
light_model:  True 
light_feat:  True 
light_search:  False 
******************** light-reid settings ********************
 
[light_model was enabled] load teacher model from /home/rosy/MySpace/ReID/light-reid/results/duke/resnet50/lightmodel(False)-lightfeat(False)-lightsearch(False)/final_model.pth.tar 
[light_model was enabled] add KLLoss for model distillation 
[light_feat was enabled] model learn binary codes, and is evaluated with hamming distance 
[light_feat was enabled] update eval_metric from cosine to hamming by setting self.eval_metric=hamming 
[Feature Extraction] feature extraction time per batch (64) is 0.0305269001597199s 
Traceback (most recent call last):
  File "examples/bagtricks_buildwithconfigs/train.py", line 22, in <module>
    solver.train(eval_freq=10)
  File "./lightreid/engine/engine.py", line 219, in train
    self.eval(onebyone=False)
  File "./lightreid/engine/engine.py", line 290, in eval
    mAP, CMC = self.evaluator.evaluate(
AttributeError: 'CleanEngine' object has no attribute 'evaluator'

我想问下是哪里出了问题。

我训练出res50(duke)的rank-1只有0.8658,mAP为0.76,在仅仅使用bag的trick的情况下,这个结果稍低于了我的预期,是我训练的方式有为题吗?

get error in max_pool2d layer

I try to implement this repo, i get a error like this:
max_pool2d_with_indices_out_cuda_frame failed with error code 0

how to I fix that?

about reproducing the results

I want to understand that “bagtricks_pca” and “occluded_reid” are trained according to the configured parameters, but they cannot reach the accuracy you posted. The results are still very different. I don’t know why this is.
the results:
“bagtricks_pca”:
+--------------+---------------------+---------------------+--------------------+--------------------+
| dataset | map | rank-1 | rank-5 | rank-10 |
+--------------+---------------------+---------------------+--------------------+--------------------+
| Market1501 | 0.17728540318946004 | 0.40498812351543945 | 0.5881828978622328 | 0.6591448931116389 |
| DukeMTMCreID | 0.6451677264561732 | 0.8074506283662477 | 0.9124775583482945 | 0.9340215439856373 |
+--------------+---------------------+---------------------+--------------------+--------------------+

“occluded_reid” with occludedreid_resnet50ibna_config
+--------------+--------------------+--------------------+--------------------+--------------------+
| dataset | map | rank-1 | rank-5 | rank-10 |
+--------------+--------------------+--------------------+--------------------+--------------------+
| OccludedReID | 0.5465391874335267 | 0.577 | 0.745 | 0.806 |
| PartialReID | 0.6881890106551225 | 0.7333333333333333 | 0.8566666666666667 | 0.9233333333333333 |
+--------------+--------------------+--------------------+--------------------+--------------------+

awesome

hi there,the accuracy of this model is very high.If I use your model as a baseline, it may be easier to reach SOTA.so, can i use your code as the baseline for my experiment?

Re-ranking?

I read this: Note that our implementation uses no the center loss and re-ranking

Does this mean that this isn't using re-ranking. Also, do you have a pre-trained model I can test with?

'NoneType' object is not iterable

Hi, I am trying to train the model but the following error is appearing.

/usr/local/lib/python3.6/dist-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Traceback (most recent call last):
  File "main.py", line 134, in <module>
    main(config)
  File "main.py", line 14, in main
    loaders = Loaders(config)
  File "/home/zamra/PYreps/Person_ReId/Pytorch-Person-REID-Baseline-Bag-of-Tricks/core/data_loader/__init__.py", line 52, in __init__
    self._load()
  File "/home/zamra/PYreps/Person_ReId/Pytorch-Person-REID-Baseline-Bag-of-Tricks/core/data_loader/__init__.py", line 68, in _load
    self.duke_query_samples, self.duke_gallery_samples = self._get_test_samples('duke_test')
  File "/home/zamra/PYreps/Person_ReId/Pytorch-Person-REID-Baseline-Bag-of-Tricks/core/data_loader/__init__.py", line 93, in _get_test_samples
    query_samples = Samples4Duke(query_data_path, reorder=False)
  File "/home/zamra/PYreps/Person_ReId/Pytorch-Person-REID-Baseline-Bag-of-Tricks/core/data_loader/dataset.py", line 23, in __init__
    samples = self._load_images_path(self.samples_path)
  File "/home/zamra/PYreps/Person_ReId/Pytorch-Person-REID-Baseline-Bag-of-Tricks/core/data_loader/dataset.py", line 54, in _load_images_path
    root_path, _, files_name = os_walk(folder_dir)
TypeError: 'NoneType' object is not iterable

BNHead中降维报错

Traceback (most recent call last):
File "examples/stronger_baseline/main.py", line 77, in
margin=0.35))
File "/dahuafs/userdata/233540/workdir/light-reid/lightreid/models/heads/bn_head.py", line 49, in init
classifier['in_dim'] = in_dim if middle_dim is None else middle_dim
TypeError: 'Circle' object does not support item assignment

期待您的回复!

增加类别后的推理时间增加问题?

您好,我使用您的代码训练自己数据进行训练时增加了类别,但对应的推理时间也程近似的线性增加,而且推理时间增加在backbone的推理过程,请问下是什么原因呢?能否有解决的方法?

Is there something wrong with the function 'def _reorder_labels' in dataset.py?

Why the function def _reorder_labels in dataset.py can realize reordering the label? It just traverses through the list samples and changes the value of sample , but does not do anything with the list samples.

def _reorder_labels(self, samples, label_index): ids = [] for sample in samples: ids.append(sample[label_index]) # delete repetitive elments and order ids = list(set(ids)) ids.sort() # reorder for sample in samples: sample[label_index] = ids.index(sample[label_index]) return samples

learning rate may be wrong

while I was checking the learning rate, some discrepancies were noticed from the original paper

`def get_lr(self):
current_epoch = self.last_epoch + 1

	if current_epoch <= self.warmup_iters  :

		return [ base_lr / 10 * float(self.last_epoch + 1 ) / float(self.warmup_iters) for base_lr in self.base_lrs ]

	elif current_epoch <= 40:

		return [base_lr  for base_lr in self.base_lrs ]

	elif current_epoch <= 70:

		return [base_lr / 10 for base_lr in self.base_lrs ]

	elif current_epoch <= 120:

		return [base_lr / 100  for base_lr in self.base_lrs ]

`

about speed

In the paper table2, why compare Hamming-distance+counting-sort with Euclidean-distance+quick-sort? If choose Euclidean-distance+count-sort, the difference between them will be much small.

No return_time argument

lightreid.evaluation

mAP, CMC, ranktime, evaltime = CmcMapEvaluatorC2F(metric=metric, mode='inter-camera').compute(
TypeError: compute() got an unexpected keyword argument 'return_time'

There's no return_time in the compute() function in rank1b1 and rankc2f but engine uses the parameter. Plz fix it.

Error

when finish training, there is a error in eval function.
how to solve it?

Traceback (most recent call last):
File "main.py", line 60, in
solver.eval(onebyone=True)
File "../../lightreid/engine/engine.py", line 277, in eval
mAP, CMC, ranktime, evaltime = CmcMapEvaluator1b1(metric=metric, mode='inter-camera').compute(
File "../../lightreid/evaluations/rank/rank_1b1.py", line 45, in init
progressbar.SimpleProgress(format='%(value_s)s/%(max_value_s)s'),
TypeError: init() got an unexpected keyword argument 'format'

Regarding some details in Faster Person Re-Identification

Hi. I have some questions about the implementation of the paper Faster Person Re-Identification.


1. In the paper you have mentioned the loss formulation:
image
I am wondering should the L_ce and L_tri be added on all the codes or just on the output of the main bnneck?


2. In the paper you have mentioned the loss formulation of self-distilation loss:
image
which use previous code outputs as soft labels to supervise latter code outputs. But in your code https://github.com/wangguanan/light-reid/blob/master/lightreid/losses/self_distill_loss.py#L27 , seems it's only using the first one as teacher. What's the difference here?

Looking forward to your feekback!

how to reproduce your eccv2020 paper?

Hey, your eccv 2020 papaer is great! I want to try some ideas based on your work. I think there is an convinient way to reproduce the results of your paper. I, however, could not find it duo to some reason.

I also tried to modify this base config to reproduce your work by setting light_feat and light_search to True. However, a lot of errors came. After I fixed some, more appeared. So I think maybe I didn't do it the right way.

Could you please help me by pointing out the right way to reproduce your eccv 2020 paper or telling me I need to reimplemente it from scratch? Thanks in advance.

执行lightsearch时报错

执行CUDA_VISIBLE_DEVICES=1 python main.py --dataset dukemtmcreid --results_dir ./results/dukemtmcreid/ --lightfeat True --lightsearch True报错:

Traceback (most recent call last):
File "main.py", line 46, in
light_model=args.lightmodel, light_feat=args.lightfeat, light_search=args.lightsearch)
File "../../lightreid/engine/engine.py", line 106, in init
self.model.enable_tanh()
File "/environment/python/versions/miniconda3-4.7.12/envs/lightreid/lib/python3.7/site-packages/torch/nn/modules/module.py", line 779, in getattr
type(self).name, name))
torch.nn.modules.module.ModuleAttributeError: 'BaseReIDModel' object has no attribute 'enable_tanh'

TypeError: forward() got an unexpected keyword argument 'use_tanh'

Hi, Dr. Wang.
I make the config file base.yaml

light_search: True

but I meet the bug: TypeError: forward() got an unexpected keyword argument 'use_tanh'

it is In code_pyramid.py,
bn_feats, logits = neck(feats, use_tanh=use_tanh)

There is no use_tanh argument.How do I fix the bug or error? Thanks for your reply

Questions about "Distance Threshold Optimization"

Hi @wangguanan , 非常感谢您的faster re-id工作,在理解论文的过程中,关于Distance Threshold Optimization算法有一些疑问:

  1. 请问DTO算法中,为什么选择用高斯累计分布函数来代替precision和recall呢?
  2. 论文的Eq.8 ,即Fβ的公式看的不太懂,请问该公式是如何得到的
    请问关于这个算法有什么参考文献或有助于理解的出处吗?您的回答会对我有很大的帮助,感谢!

关于哈希的问题

对特征的二值化编码,论文中写的是通过sgn(bn(Vk)),实际我看代码里用的tanh(),为什么这种简单的二值化编码方法相比于ABC在mAP上提升那么大。

给出的表格中的search per query是指的什么,和论文中的Q.Time是一个意思吗

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.