2019-03-25 00:08:55 +08:00
Torchreid
===========
2019-03-24 07:09:39 +08:00
Torchreid is a library built on `PyTorch <https://pytorch.org/> `_ for deep-learning person re-identification.
2019-03-21 20:53:21 +08:00
It features:
- multi-GPU training
2019-03-24 07:09:39 +08:00
- support both image- and video-reid
2019-03-21 20:53:21 +08:00
- end-to-end training and evaluation
- incredibly easy preparation of reid datasets
- multi-dataset training
- cross-dataset evaluation
- standard protocol used by most research papers
- highly extensible (easy to add models, datasets, training methods, etc.)
- implementations of state-of-the-art deep reid models
- access to pretrained reid models
- advanced training techniques
2019-08-23 06:18:56 +08:00
- visualization tools (tensorboard, ranks, etc.)
2019-03-21 20:53:21 +08:00
2019-03-25 01:30:39 +08:00
Documentation: https://kaiyangzhou.github.io/deep-person-reid/.
2019-05-25 00:22:41 +08:00
Code: https://github.com/KaiyangZhou/deep-person-reid.
2019-07-11 20:38:07 +08:00
Model zoo: https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO.
2019-03-25 01:30:39 +08:00
2019-03-21 20:53:21 +08:00
Installation
---------------
2019-03-24 22:36:17 +08:00
2019-08-23 06:18:56 +08:00
We recommend using `conda <https://www.anaconda.com/distribution/> `_ to manage the packages.
2019-04-20 03:47:12 +08:00
2019-08-23 06:18:56 +08:00
1. Clone `` deep-person-reid `` to your preferred directory.
2019-03-24 23:52:39 +08:00
2019-03-24 22:36:17 +08:00
.. code-block :: bash
$ git clone https://github.com/KaiyangZhou/deep-person-reid.git
2019-03-24 23:52:39 +08:00
2019-08-23 06:18:56 +08:00
2. Create a conda environment (the default name is `` torchreid `` ).
2019-03-24 23:52:39 +08:00
.. code-block :: bash
2019-03-24 22:36:17 +08:00
$ cd deep-person-reid/
2019-08-23 06:18:56 +08:00
$ conda env create -f environment.yml
$ conda activate torchreid
2019-04-20 03:47:12 +08:00
2019-08-23 06:18:56 +08:00
Do check whether `` which python `` and `` which pip `` point to the right path.
2019-04-20 03:47:12 +08:00
2019-08-23 06:18:56 +08:00
3. Install tensorboard.
2019-04-20 03:47:12 +08:00
.. code-block :: bash
2019-08-23 06:18:56 +08:00
$ pip install tb-nightly
2019-04-20 03:47:12 +08:00
2019-08-23 06:31:34 +08:00
4. Install PyTorch and torchvision (select the proper cuda version to suit your machine).
2019-04-20 03:47:12 +08:00
.. code-block :: bash
$ conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
2019-08-23 06:31:34 +08:00
5. Install `` torchreid `` .
2019-04-20 03:47:12 +08:00
.. code-block :: bash
2019-08-23 06:18:56 +08:00
$ python setup.py develop
2019-03-21 20:53:21 +08:00
Get started: 30 seconds to Torchreid
-------------------------------------
2019-03-24 07:09:39 +08:00
1. Import `` torchreid ``
.. code-block :: python
import torchreid
2. Load data manager
.. code-block :: python
datamanager = torchreid.data.ImageDataManager(
root='reid-data',
sources='market1501',
height=256,
width=128,
batch_size=32,
2019-07-11 20:38:07 +08:00
transforms=['random_flip', 'random_crop']
2019-03-24 07:09:39 +08:00
)
3 Build model, optimizer and lr_scheduler
.. code-block :: python
model = torchreid.models.build_model(
name='resnet50',
num_classes=datamanager.num_train_pids,
loss='softmax',
pretrained=True
)
2019-03-25 05:02:18 +08:00
model = model.cuda()
2019-03-24 07:09:39 +08:00
optimizer = torchreid.optim.build_optimizer(
model,
optim='adam',
lr=0.0003
)
scheduler = torchreid.optim.build_lr_scheduler(
optimizer,
lr_scheduler='single_step',
stepsize=20
)
4. Build engine
.. code-block :: python
engine = torchreid.engine.ImageSoftmaxEngine(
datamanager,
model,
optimizer=optimizer,
scheduler=scheduler,
label_smooth=True
)
5. Run training and test
.. code-block :: python
engine.run(
save_dir='log/resnet50',
max_epoch=60,
eval_freq=10,
print_freq=10,
test_only=False
)
2019-03-21 20:53:21 +08:00
2019-03-24 23:52:39 +08:00
A unified interface
-----------------------
2019-08-24 05:48:03 +08:00
In "deep-person-reid/scripts/", we provide a unified interface to train and test a model.
For instance, to train an image reid model on Market1501 using softmax, you can do
2019-03-24 23:52:39 +08:00
2019-03-24 23:54:55 +08:00
.. code-block :: bash
2019-03-24 23:52:39 +08:00
2019-08-24 05:48:03 +08:00
# suppose you are in deep-person-reid/
python scripts/main.py \
--root PATH_TO_DATA \
2019-03-24 23:52:39 +08:00
--app image \
--loss softmax \
--label-smooth \
-s market1501 \
-a resnet50 \
--optim adam \
--lr 0.0003 \
--max-epoch 60 \
--stepsize 20 40 \
--batch-size 32 \
2019-07-11 20:38:07 +08:00
--transforms random_flip random_crop \
--save-dir log/resnet50-market1501-softmax \
2019-03-24 23:52:39 +08:00
--gpu-devices 0
2019-08-24 05:48:03 +08:00
To evaluate a trained model, do
.. code-block :: bash
python scripts/main.py \
--root PATH_TO_DATA \
--app image \
--loss softmax \
-s market1501 \
-a resnet50 \
--batch-size 32 \
--evaluate \
--load-weights log/resnet50-market1501-softmax/model.pth.tar-60 \
--save-dir log/eval-resnet50 \
--gpu-devices 0
2019-03-24 23:52:39 +08:00
Please refer to `` default_parser.py `` and `` main.py `` for more details.
2019-03-21 20:53:21 +08:00
Datasets
--------
Image-reid datasets
^^^^^^^^^^^^^^^^^^^^^
- `Market1501 <https://www.cv-foundation.org/openaccess/content_iccv_2015/papers/Zheng_Scalable_Person_Re-Identification_ICCV_2015_paper.pdf> `_
- `CUHK03 <https://www.cv-foundation.org/openaccess/content_cvpr_2014/papers/Li_DeepReID_Deep_Filter_2014_CVPR_paper.pdf> `_
- `DukeMTMC-reID <https://arxiv.org/abs/1701.07717> `_
- `MSMT17 <https://arxiv.org/abs/1711.08565> `_
- `VIPeR <http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.331.7285&rep=rep1&type=pdf> `_
- `GRID <http://www.eecs.qmul.ac.uk/~txiang/publications/LoyXiangGong_cvpr_2009.pdf> `_
- `CUHK01 <http://www.ee.cuhk.edu.hk/~xgwang/papers/liZWaccv12.pdf> `_
- `SenseReID <http://openaccess.thecvf.com/content_cvpr_2017/papers/Zhao_Spindle_Net_Person_CVPR_2017_paper.pdf> `_
- `QMUL-iLIDS <http://www.eecs.qmul.ac.uk/~sgg/papers/ZhengGongXiang_BMVC09.pdf> `_
- `PRID <https://pdfs.semanticscholar.org/4c1b/f0592be3e535faf256c95e27982db9b3d3d3.pdf> `_
Video-reid datasets
^^^^^^^^^^^^^^^^^^^^^^^
- `MARS <http://www.liangzheng.org/1320.pdf> `_
- `iLIDS-VID <https://www.eecs.qmul.ac.uk/~sgg/papers/WangEtAl_ECCV14.pdf> `_
- `PRID2011 <https://pdfs.semanticscholar.org/4c1b/f0592be3e535faf256c95e27982db9b3d3d3.pdf> `_
- `DukeMTMC-VideoReID <http://openaccess.thecvf.com/content_cvpr_2018/papers/Wu_Exploit_the_Unknown_CVPR_2018_paper.pdf> `_
Models
-------
ImageNet classification models
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- `ResNet <https://arxiv.org/abs/1512.03385> `_
- `ResNeXt <https://arxiv.org/abs/1611.05431> `_
- `SENet <https://arxiv.org/abs/1709.01507> `_
- `DenseNet <https://arxiv.org/abs/1608.06993> `_
- `Inception-ResNet-V2 <https://arxiv.org/abs/1602.07261> `_
- `Inception-V4 <https://arxiv.org/abs/1602.07261> `_
- `Xception <https://arxiv.org/abs/1610.02357> `_
Lightweight models
^^^^^^^^^^^^^^^^^^^
- `NASNet <https://arxiv.org/abs/1707.07012> `_
- `MobileNetV2 <https://arxiv.org/abs/1801.04381> `_
- `ShuffleNet <https://arxiv.org/abs/1707.01083> `_
2019-06-06 05:18:28 +08:00
- `ShuffleNetV2 <https://arxiv.org/abs/1807.11164> `_
2019-03-21 20:53:21 +08:00
- `SqueezeNet <https://arxiv.org/abs/1602.07360> `_
ReID-specific models
^^^^^^^^^^^^^^^^^^^^^^
- `MuDeep <https://arxiv.org/abs/1709.05165> `_
- `ResNet-mid <https://arxiv.org/abs/1711.08106> `_
- `HACNN <https://arxiv.org/abs/1802.08122> `_
- `PCB <https://arxiv.org/abs/1711.09349> `_
- `MLFN <https://arxiv.org/abs/1803.09132> `_
2019-07-03 20:42:31 +08:00
- `OSNet <https://arxiv.org/abs/1905.00953> `_
2019-03-21 20:53:21 +08:00
Losses
------
- `Softmax (cross entropy loss with label smoothing) <https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Szegedy_Rethinking_the_Inception_CVPR_2016_paper.pdf> `_
- `Triplet (hard example mining triplet loss) <https://arxiv.org/abs/1703.07737> `_
Citation
---------
2019-05-06 17:48:03 +08:00
If you find this code useful to your research, please cite the following publication.
.. code-block :: bash
@article{zhou2019osnet,
2019-06-06 05:18:28 +08:00
title={Omni-Scale Feature Learning for Person Re-Identification},
author={Zhou, Kaiyang and Yang, Yongxin and Cavallaro, Andrea and Xiang, Tao},
journal={arXiv preprint arXiv:1905.00953},
year={2019}
2019-05-06 17:48:03 +08:00
}