Giter VIP home page Giter VIP logo

layumi / person_reid_baseline_pytorch Goto Github PK

View Code? Open in Web Editor NEW
4.0K 77.0 997.0 7.9 MB

:bouncing_ball_person: Pytorch ReID: A tiny, friendly, strong pytorch implement of person re-id / vehicle re-id baseline. Tutorial 👉https://github.com/layumi/Person_reID_baseline_pytorch/tree/master/tutorial

Home Page: https://www.zdzheng.xyz

License: MIT License

Python 97.63% C++ 0.77% Cuda 1.50% Shell 0.10%
open-reid pytorch person-reidentification image-retrieval person-reid re-ranking random-erasing image-search market-1501 tutorial

person_reid_baseline_pytorch's Introduction

Pytorch ReID

Strong, Small, Friendly

Python3.6+ License: MIT

A tiny, friendly, strong baseline code for Object-reID (based on pytorch) since 2017.

Share to Facebook Twitter Weibo LinkedIn Email

Tutorial

Table of contents

Features

Now we have supported:

Training

  • Running the code on Google Colab with Free GPU. Check Here (Thanks to @ronghao233)
  • DG-Market (10x Large Synthetic Dataset from Market CVPR 2019 Oral)
  • Swin Transformer / EfficientNet / HRNet
  • ResNet/ResNet-ibn/DenseNet
  • Circle Loss, Triplet Loss, Contrastive Loss, Sphere Loss, Lifted Loss, Arcface, Cosface and Instance Loss
  • Float16 to save GPU memory based on apex
  • Part-based Convolutional Baseline(PCB)
  • Random Erasing
  • Linear Warm-up
  • torch.compile (faster training)
  • DDP (Multiple GPUs)

Testing

  • TensorRT
  • Pytorch JIT
  • Fuse Conv and BN layer into one Conv layer
  • Multiple Query Evaluation
  • Re-Ranking (CPU & GPU Version)
  • Visualize Training Curves
  • Visualize Ranking Result
  • Visualize Heatmap

Here we provide hyperparameters and architectures, that were used to generate the result. Some of them (i.e. learning rate) are far from optimal. Do not hesitate to change them and see the effect.

P.S. With similar structure, we arrived Rank@1=87.74% mAP=69.46% with Matconvnet. (batchsize=8, dropout=0.75) You may refer to Here. Different framework need to be tuned in a slightly different way.

Some News

12 Jan 2024 We are holding a workshop at ACM ICMR 2024 on Multimedia Object Re-ID. You are welcome to show your insights. See you at Phuket, Thailand!😃 The workshop link is https://www.zdzheng.xyz/MORE2024/ . Submission DDL is 15 April 2024. Good papers will be recommended to ACM TOMM Special Issue (CCF-B). (Re-submission is needed.)

12 Aug 2023 Large Person Langauge Model is currently available at HereGitHub stars accepted by ACM MM'23. You are welcomed to check it.

19 Mar 2023 We host a special session on IEEE Intelligent Transportation Systems Conference (ITSC), covering the object re-identification & point cloud topic. The paper ddl is by May 15, 2023 and the paper notification is at June 30, 2023. Please select the session code ``w7r4a'' during submission. More details can be found at Special Session Website.

9 Mar 2023 Market-1501 is in 3D. Please check our single 2D to 3D reconstruction work https://github.com/layumi/3D-Magic-Mirror GitHub stars. Magic Mirror

2022 News

7 Sep 2022 We support SwinV2.

24 Jul 2022 Market-HQ is released with super-resolution quality from 128*64 to 512*256. Please check at https://github.com/layumi/HQ-Market

14 Jul 2022 Add adversarial training by python train.py --name ftnet_adv --adv 0.1 --aiter 40.

1 Feb 2022 Speed up the inference process about 10 seconds by removing the cat function in test.py.

1 Feb 2022 Add the demo with TensorRT (The fast inference speed may depend on the GPU with the latest RT Core).

2021 News

30 Dec 2021 We add supports for new losses, including arcface loss, cosface loss and instance loss. The hyper-parameters are still tunning.

3 Dec 2021 We add supports for four losses, including triplet loss, contrastive loss, sphere loss and lifted loss. The hyper-parameters are still tunning.

1 Dec 2021 We support EfficientNet/HRNet.

15 Sep 2021 We support ResNet-ibn from ECCV2018 (https://github.com/XingangPan/IBN-Net).

17 Aug 2021 We support running code on Google Colab with free GPU. Please check it out at https://github.com/layumi/Person_reID_baseline_pytorch/tree/master/colab .

14 Aug 2021 We have supported the training with DG-Market for regularization via Self-supervised Memory Learning. You only neeed to download/unzip the dataset and add --DG to train model.

12 Aug 2021 We have supported the transformer-based model Swin by --use_swin. The basic performance is 92.73% Rank@1 and 79.71%mAP.

23 Jun 2021 Attack your re-ID model via Query! They are not robust as you expected! Check the code at Here.

5 Feb 2021 We have supported Circle loss(CVPR20 Oral). You can try it by simply adding --circle.

11 January 2021 On the Market-1501 dataset, we accelerate the re-ranking processing from 89.2s to 9.4ms with one K40m GPU, facilitating the real-time post-processing. The pytorch implementation can be found in GPU-Re-Ranking.

2020 News

11 June 2020 People live in the 3D world. We release one new person re-id code Person Re-identification in the 3D Space, which conduct representation learning in the 3D space. You are welcomed to check out it.

30 April 2020 We have applied this code to the AICity Challenge 2020, yielding the 1st Place Submission to the re-id track 🚗. Check out here.

01 March 2020 We release one new image retrieval dataset, called University-1652, for drone-view target localization and drone navigation 🚁. It has a similar setting with the person re-ID. You are welcomed to check out it.

2019 News

07 July 2019: I added some new functions, such as --resume, auto-augmentation policy, acos loss, into developing thread and rewrite the save and load functions. I haven't tested the functions throughly. Some new functions are worthy of having a try. If you are first to this repo, I suggest you stay with the master thread.

01 July 2019: My CVPR19 Paper is online. It is based on this baseline repo as teacher model to provide pseudo label for the generated images to train a better student model. You are welcomed to check out the opensource code at here.

03 Jun 2019: Testing with multiple-scale inputs is added. You can use --ms 1,0.9 when extracting the feature. It could slightly improve the final result.

20 May 2019: Linear Warm Up is added. You also can set warm-up the first K epoch by --warm_epoch K. If K <=0, there will be no warm-up.

2018 & 2017 News

What's new: FP16 has been added. It can be used by simply added --fp16. You need to install apex and update your pytorch to 1.0.

Float16 could save about 50% GPU memory usage without accuracy drop. Our baseline could be trained with only 2GB GPU memory.

python train.py --fp16

What's new: Visualizing ranking result is added.

python prepare.py
python train.py
python test.py
python demo.py --query_index 777

What's new: Multiple-query Evaluation is added. The multiple-query result is about Rank@1=91.95% mAP=78.06%.

python prepare.py
python train.py
python test.py --multi
python evaluate_gpu.py

What's new:  PCB is added. You may use '--PCB' to use this model. It can achieve around Rank@1=92.73% mAP=78.16%. I used a GPU (P40) with 24GB Memory. You may try apply smaller batchsize and choose the smaller learning rate (for stability) to run. (For example, --batchsize 32 --lr 0.01 --PCB)

python train.py --PCB --batchsize 64 --name PCB-64
python test.py --PCB --name PCB-64

What's new: You may try evaluate_gpu.py to conduct a faster evaluation with GPU.

What's new: You may apply '--use_dense' to use DenseNet-121. It can arrive around Rank@1=89.91% mAP=73.58%.

What's new: Re-ranking is added to evaluation. The re-ranked result is about Rank@1=90.20% mAP=84.76%.

What's new: Random Erasing is added to train.

What's new: I add some code to generate training curves. The figure will be saved into the model folder when training.

Trained Model

I re-trained several models, and the results may be different with the original one. Just for a quick reference, you may directly use these models. The download link is Here.

Methods Rank@1 mAP Reference
[EfficientNet-b4] 85.78% 66.80% python train.py --use_efficient --name eff; python test.py --name eff
[ResNet-50 + adv defense] 87.77% 69.83% python train.py --name adv0.1_40_w10_all --adv 0.1 --aiter 40 --warm 10 --train_all; python test.py --name adv0.1_40_w10_all
[ConvNeXt] 88.98% 71.35% python train.py --use_convnext --name convnext; python test.py --name convnext
[ResNet-50 (fp16)] 88.03% 71.40% python train.py --name fp16 --fp16 --train_all
[ResNet-50] 88.84% 71.59% python train.py --train_all
[ResNet-50-ibn] 89.13% 73.40% python train.py --train_all --name res-ibn --ibn
[DenseNet-121] 90.17% 74.02% python train.py --name ft_net_dense --use_dense --train_all
[DenseNet-121 (Circle)] 91.00% 76.54% python train.py --name ft_net_dense_circle_w5 --circle --use_dense --train_all --warm_epoch 5
[HRNet-18] 90.83% 76.65% python train.py --use_hr --name hr18; python test.py --name hr18
[PCB] 92.64% 77.47% python train.py --name PCB --PCB --train_all --lr 0.02
[PCB + DG] 92.70% 78.31% python train.py --name PCB_DG --PCB --train_all --lr 0.02 --DG; python test.py --name PCB_DG
[ResNet-50 (all tricks)] 91.83% 78.32% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 8 --lr 0.02 --name warm5_s1_b8_lr2_p0.5
[ResNet-50 (all tricks+Circle)] 92.13% 79.84% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 8 --lr 0.02 --name warm5_s1_b8_lr2_p0.5_circle --circle
[ResNet-50 (all tricks+Circle+DG)] 92.13% 80.13% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 8 --lr 0.02 --name warm5_s1_b8_lr2_p0.5_circle_DG --circle --DG; python test.py --name warm5_s1_b8_lr2_p0.5_circle_DG
[DenseNet-121 (all tricks+Circle)] 92.61% 80.24% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 8 --lr 0.02 --name dense_warm5_s1_b8_lr2_p0.5_circle --circle --use_dense; python test.py --name dense_warm5_s1_b8_lr2_p0.5_circle
[HRNet-18 (all tricks+Circle+DG)] 92.19% 81.00% python train.py --use_hr --name hr18_p0.5_circle_w5_b16_lr0.01_DG --lr 0.01 --batch 16 --DG --erasing_p 0.5 --circle --warm_epoch 5; python test.py --name hr18_p0.5_circle_w5_b16_lr0.01_DG
[Swin] (224x224) 92.75% 79.70% python train.py --use_swin --name swin; python test.py --name swin
[SwinV2 (all tricks+Circle 256x128)] 92.93% 82.99% python train.py --use_swinv2 --name swinv2_p0.5_circle_w5_b16_lr0.03 --lr 0.03 --batch 16 --erasing_p 0.5 --circle --warm_epoch 5; python test.py --name swinv2_p0.5_circle_w5_b16_lr0.03 --batch 32
[Swin (all tricks+Circle 224x224)] 94.12% 84.39% python train.py --use_swin --name swin_p0.5_circle_w5 --erasing_p 0.5 --circle --warm_epoch 5; python test.py --name swin_p0.5_circle_w5
[Swin (all tricks+Circle+b16 224x224)] 94.00% 85.21% python train.py --use_swin --name swin_p0.5_circle_w5_b16_lr0.01 --lr 0.01 --batch 16 --erasing_p 0.5 --circle --warm_epoch 5; python test.py --name swin_p0.5_circle_w5_b16_lr0.01
[Swin (all tricks+Circle+b16+DG 224x224)] 94.00% 85.36% python train.py --use_swin --name swin_p0.5_circle_w5_b16_lr0.01_DG --lr 0.01 --batch 16 --DG --erasing_p 0.5 --circle --warm_epoch 5; python test.py --name swin_p0.5_circle_w5_b16_lr0.01_DG
  • More training iterations may lead to better results.
  • Swin costs more GPU memory (11G GPU is needed) to run.
  • The hyper-parameter of DG-Market --DG is not tuned. Better hyper-parameter may lead to better results.

Different Losses

I do not optimize the hyper-parameters. You are free to tune them for better performance.

Methods Rank@1 mAP Reference
CE 92.01% 79.31% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_100 --total 100 ; python test.py --name warm5_s1_b32_lr8_p0.5_100
CE + Sphere [Paper] 92.01% 79.39% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_sphere100 --sphere --total 100; python test.py --name warm5_s1_b32_lr8_p0.5_sphere100
CE + Triplet [Paper] 92.40% 79.71% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_triplet100 --triplet --total 100; python test.py --name warm5_s1_b32_lr8_p0.5_triplet100
CE + Lifted [Paper] 91.78% 79.77% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_lifted100 --lifted --total 100; python test.py --name warm5_s1_b32_lr8_p0.5_lifted100
CE + Instance [Paper] 92.73% 81.11% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_instance100_gamma64 --instance --ins_gamma 64 --total 100 ; python test.py --name warm5_s1_b32_lr8_p0.5_instance100_gamma64
CE + Contrast [Paper] 92.28% 81.42% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_contrast100 --contrast --total 100; python test.py --name warm5_s1_b32_lr8_p0.5_contrast100
CE + Circle [Paper] 92.46% 81.70% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_circle100 --circle --total 100 ; python test.py --name warm5_s1_b32_lr8_p0.5_circle100
CE + Contrast + Sphere 92.79% 82.02% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 32 --lr 0.08 --name warm5_s1_b32_lr8_p0.5_cs100 --contrast --sphere --total 100; python test.py --name warm5_s1_b32_lr8_p0.5_cs100
CE + Contrast + Triplet (Long) 92.61% 82.01% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 24 --lr 0.062 --name warm5_s1_b24_lr6.2_p0.5_contrast_triplet_133 --contrast --triplet --total 133 ; python test.py --name warm5_s1_b24_lr6.2_p0.5_contrast_triplet_133
CE + Contrast + Circle (Long) 92.19% 82.07% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 24 --lr 0.08 --name warm5_s1_b24_lr8_p0.5_contrast_circle133 --contrast --circle --total 133 ; python test.py --name warm5_s1_b24_lr8_p0.5_contrast_circle133
CE + Contrast + Sphere (Long) 92.84% 82.37% python train.py --warm_epoch 5 --stride 1 --erasing_p 0.5 --batchsize 24 --lr 0.06 --name warm5_s1_b24_lr6_p0.5_contrast_sphere133 --contrast --sphere --total 133 ; python test.py --name warm5_s1_b24_lr6_p0.5_contrast_sphere133

Model Structure

You may learn more from model.py. We add one linear layer(bottleneck), one batchnorm layer and relu.

Prerequisites

  • Python 3.6+
  • GPU Memory >= 6G
  • Numpy
  • Pytorch 0.3+
  • timm pip install timm for Swin-Transformer with Pytorch >1.7.0
  • pretrainedmodels via pip install pretrainedmodels
  • [Optional] apex (for float16)
  • [Optional] pretrainedmodels

(Some reports found that updating numpy can arrive the right accuracy. If you only get 50~80 Top1 Accuracy, just try it.) We have successfully run the code based on numpy 1.12.1 and 1.13.1 .

Getting started

Installation

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

Because pytorch and torchvision are ongoing projects.

Here we noted that our code is tested based on Pytorch 0.3.0/0.4.0/0.5.0/1.0.0 and Torchvision 0.2.0/0.2.1 .

Dataset & Preparation

Download Market1501 Dataset [Google] [Baidu] Or use command line:

pip install gdown 
pip install --upgrade gdown #!!important!!
gdown 0B8-rUzbwVRk0c054eEozWG9COHM

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

python prepare.py

Remember to change the dataset path to your own path.

Futhermore, you also can test our code on [DukeMTMC-reID Dataset]( GoogleDriver or (BaiduYun password: bhbh)) Or use command line:

gdown 1jjE85dRCMOgRtvJ5RQV9-Afs-2_5dY3O

Our baseline code is not such high on DukeMTMC-reID Rank@1=64.23%, mAP=43.92%. Hyperparameters are need to be tuned.

  • [Optional] DG-Market is a generated pedestrian dataset of 128,307 images for training a robust model.

Train

Train a model by

python train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 32  --data_dir your_data_path

--gpu_ids which gpu to run.

--name the name of model.

--data_dir the path of the training data.

--train_all using all images to train.

--batchsize batch size.

--erasing_p random erasing probability.

Train a model with random erasing by

python train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 32  --data_dir your_data_path --erasing_p 0.5

If you want to use multiple GPUs, you are suggested to use DDP (train_DDP.py) instead of DP (train.py). It is because DP lacks the torch supports and may face some NaN. You could call train_DDP.py by running DDP.sh.

bash DDP.sh 

Test

Use trained model to extract feature by

python test.py --gpu_ids 0 --name ft_ResNet50 --test_dir your_data_path  --batchsize 32 --which_epoch 59

--gpu_ids which gpu to run.

--batchsize batch size.

--name the dir name of trained model.

--which_epoch select the i-th model.

--data_dir the path of the testing data.

Evaluation

python evaluate.py

It will output Rank@1, Rank@5, Rank@10 and mAP results. You may also try evaluate_gpu.py to conduct a faster evaluation with GPU.

For mAP calculation, you also can refer to the C++ code for Oxford Building. We use the triangle mAP calculation (consistent with the Market1501 original code).

re-ranking

python evaluate_rerank.py

It may take more than 10G Memory to run. So run it on a powerful machine if possible.

It will output Rank@1, Rank@5, Rank@10 and mAP results.

Tips

Notes the format of the camera id and the number of cameras.

For some dataset, e.g., MSMT17, there are more than 10 cameras. You need to modify the prepare.py and test.py to read the double-digit camera ID.

For some vehicle re-ID datasets. e.g. VeRi, you also need to modify the prepare.py and test.py. It has different naming rules. #107 (Sorry. It is in Chinese)

Citation

The following paper uses and reports the result of the baseline model. You may cite it in your paper.

@article{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},
  journal={IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2019}
}

The following papers may be the first two to use the bottleneck baseline. You may cite them in your paper.

@article{DBLP:journals/corr/SunZDW17,
  author    = {Yifan Sun and
               Liang Zheng and
               Weijian Deng and
               Shengjin Wang},
  title     = {SVDNet for Pedestrian Retrieval},
  booktitle   = {ICCV},
  year      = {2017},
}

@article{hermans2017defense,
  title={In Defense of the Triplet Loss for Person Re-Identification},
  author={Hermans, Alexander and Beyer, Lucas and Leibe, Bastian},
  journal={arXiv preprint arXiv:1703.07737},
  year={2017}
}

Basic Model

@article{zheng2018discriminatively,
  title={A discriminatively learned CNN embedding for person reidentification},
  author={Zheng, Zhedong and Zheng, Liang and Yang, Yi},
  journal={ACM Transactions on Multimedia Computing, Communications, and Applications (TOMM)},
  volume={14},
  number={1},
  pages={13},
  year={2018},
  publisher={ACM}
}

@article{zheng2020vehiclenet,
  title={VehicleNet: Learning Robust Visual Representation for Vehicle Re-identification},
  author={Zheng, Zhedong and Ruan, Tao and Wei, Yunchao and Yang, Yi and Mei, Tao},
  journal={IEEE Transaction on Multimedia (TMM)},
  year={2020}
}

Related Repos

  1. Pedestrian Alignment Network GitHub stars
  2. 2stream Person re-ID GitHub stars
  3. Pedestrian GAN GitHub stars
  4. Language Person Search GitHub stars
  5. DG-Net GitHub stars
  6. 3D Person re-ID GitHub stars

person_reid_baseline_pytorch's People

Contributors

awarebayes avatar eddiehe99 avatar layumi avatar tiif avatar yasinlaw 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  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

person_reid_baseline_pytorch's Issues

RuntimeError: cuda runtime error (2) : out of memory at /opt/conda/conda-bld/pytorch_1524586445097/work/aten/src/THC/generic/THCStorage.cu:58

I was using trained model to extract feature by command
python test.py --gpu_ids 1 --name ft_ResNet50 --test_dir Market-1501-v15.09.15/pytorch/ --which_epoch 59
However, there exists the following error:
RuntimeError: cuda runtime error (2) : out of memory at /opt/conda/conda-bld/pytorch_1524586445097/work/aten/src/THC/generic/THCStorage.cu:58

How can I solve the problem? Any suggestion would be appreciable.

Thanks,
Zhang

About out of memory error

-------test-----------
64
THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1512386481460/work/torch/lib/THC/generic/THCStorage.cu line=58 error=2 : out of memory

PCB

This is only PCB added , not include RPP, right?

a error in train.py

python train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 32
error occurs as below:

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\pytorch\lib\multiprocessing\spawn.py", line 144, in get_preparation_data
_check_not_importing_main()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\pytorch\lib\multiprocessing\spawn.py", line 137, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.
ForkingPickler(file, protocol).dump(obj)

BrokenPipeError: [Errno 32] Broken pipe

Acc: 0.0000/1.0000 when training for each epoch

I just download the Market1501 dataset and run the following command
python prepare.py
python train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 32 --data_dir Market-1501-v15.09.15/pytorch/

It runs without error and the loss is decreasing with each epoch, however, the acc is abnormal with 0 or 1, just as follow
train1
Is there something wrong?
Thanks
Zhang

Evaluation metric

Hi @layumi
I have read your evaluation code
Did you use the camera indexes to constraint the query and the gallery in the same cameras?
Thank you so much for your reply.

About PCB and Duke rank-1 accurate...

When I use PCB to train the model ,it always occurs error "out of memory",my GPU is 1080.How much memory do I need to train the model?or change the batchsize?

And when I train the Duke dataset, the train loss and the train accurate is quite small .But the final rank-1 is about 64%as you account.Does it mean overfitting ? what should I do if I want to increase the rank-1 in Duke dataset?

Thanks a lot!

C++

@layumi 您好,有没有C++的开源的源码呀?

undefined symbol: cudnnSetConvolutionGroupCount

python: symbol lookup error: /home/sn/anaconda3/envs/pytorch0.3/lib/python3.6/site-packages/torch/_C.cpython-36m-x86_64-linux-gnu.so: undefined symbol: cudnnSetConvolutionGroupCount

I use python 3.6.2, pytorch0.3, numpy 1.14.
I got the error when I run " python test.py --gpu_ids 0 --name /home/sn/person-reid/Person_reID_baseline_pytorch/model/ft_ResNet50 --test_dir /home/sn/person-reid/Market-1501/pytorch --which_epoch 59".
Do you know how to solve this problem?

When run PCB, get an error of 'out of memory'

When I try to train PCB model, I got an error of 'out of memory'.
python train.py --gpu_ids 0 --PCB --batchsize 64 --name PCB
When I try to train PCB model with multi GPUs, the error still occurs.
python train.py --gpu_ids 0,1 --PCB --batchsize 64 --name PCB
Thus I have 3 relevant questions.

Q1. Can the model with parameters ResNet50 + PCB + BatchSize64 is able to run on a single GPU with memory 12GB?
Q2. If Q1 is negative, can multi GPUs solve the problem of 'out of memory' by straightly setting gpu_ids '0,1'.
Q3. If Q2 is negative, how can I solve the problem.

Thank you!

Inceptionv3

hi @layumi , I try to test inceptionv3, I change the forward and model.
It appears the following problems
Traceback (most recent call last): File "inceptionv3_train.py", line 346, in <module> num_epochs=500) File ''inceptionv3_train.py", line 215, in train_model outputs = model(inputs) File "/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__ result = self.forward(*input, **kwargs) File "inceptionv3_train.py", line 195, in forward x = self.classifier(x) File "/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__ result = self.forward(*input, **kwargs) File "inceptionv3_train.py", line 55, in forward x = self.add_block(x) File "/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__ result = self.forward(*input, **kwargs) File "/lib/python3.5/site-packages/torch/nn/modules/container.py", line 67, in forward input = module(input) File "/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__ result = self.forward(*input, **kwargs) File "/lib/python3.5/site-packages/torch/nn/modules/linear.py", line 55, in forward return F.linear(input, self.weight, self.bias) File "/lib/python3.5/site-packages/torch/nn/functional.py", line 837, in linear output = input.matmul(weight.t()) File "/lib/python3.5/site-packages/torch/autograd/variable.py", line 386, in matmul return torch.matmul(self, other) File "/lib/python3.5/site-packages/torch/functional.py", line 192, in matmul output = torch.mm(tensor1, tensor2) RuntimeError: size mismatch at /pytorch/torch/lib/THC/generic/THCTensorMathBlas.cu:247

test time

I found this line 'f = outputs.data.cpu()' very slow

Goog Rank1 but bad MAP

I run the project with my trained model whose parameters include --train_all --batchsize 32 no color jitter.
when I evaluate the model,I got rank1 for 87% but map for 2.96%.
My train loss image is listed.
train

About evaluation metric

Hello sir,
First thanks a lot for the great implementation, it is really a strong baseline!
Then, after studying your code, I have a doubt about the evaluation metric. You wrote in evaluate.py that:

for i in range(ngood):
        d_recall = 1.0/ngood
        precision = (i+1)*1.0/(rows_good[i]+1)
        if rows_good[i]!=0:
            old_precision = i*1.0/rows_good[i]
        else:
            old_precision=1.0
        ap = ap + d_recall*(old_precision + precision)/2

Note in the last line, there is (old_precision+precison)/2. In my understanding of AP calculation, there shouldn't be such "old_precision" term.
For example, if there are 4 GT results retrieved at position 1,2,4,7, then AP should be (1/1+2/2+3/4+4/7)/4, right? In your implementation, the result seems not to be equal to that value(should be a little bit lower in fact). So what's the intuition behind such AP calculation mechanism and is it a custom practice in re-id evaluation?
I will be really appreciated for you answer.
Best Wishes!

Error when using PCB

Hi, @layumi.Thanks for the great code. I meet some problems when using the PCB.
python train.py --PCB --batchsize 10--name PCB-10. only change the batchsize to 10, When using PCB to train, It report as below:

Traceback (most recent call last):
  File "train.py", line 273, in <module>
    model = PCB(len(class_names))
  File "/home/yhangbin/code/github/Person_reID_baseline_pytorch/model.py", line 140, in __init__
    setattr(self, name, ClassBlock(2048, class_num, True, False, 256))
TypeError: __init__() takes from 3 to 4 positional arguments but 6 were given

I changed ClassBlock(2048, class_num, True, False, 256) to ClassBlock(2048, class_num, 256) this error was solved. But when training at epoch 1 , I got such errors as below in the val phase

train Loss: 3.7999 Acc: 0.0192
Traceback (most recent call last):
  File "train.py", line 332, in <module>
    model = train_model(model, criterion, optimizer_ft, exp_lr_scheduler,num_epochs=10)
  File "train.py", line 176, in train_model
    outputs = model(inputs)
  File "/home/yhangbin/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yhangbin/code/github/Person_reID_baseline_pytorch/model.py", line 162, in forward
    predict[i] = c(part[i])
  File "/home/yhangbin/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yhangbin/code/github/Person_reID_baseline_pytorch/model.py", line 47, in forward
    x = self.add_block(x)
  File "/home/yhangbin/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yhangbin/anaconda3/lib/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward
    input = module(input)
  File "/home/yhangbin/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yhangbin/anaconda3/lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 37, in forward
    self.training, self.momentum, self.eps)
  File "/home/yhangbin/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py", line 1013, in batch_norm
    return f(input, weight, bias)
RuntimeError: CHECK_ARG(tensor->nDimension >= 2 && tensor->nDimension <= 5) failed at torch/csrc/cudnn/BatchNorm.cpp:13

I don't know how to solve this problem,thanks for your help.

SVDNet

Hi,thanks for your sharing.I have tried to write SVDNet based on this baseline.However, the loss is not convergent.Do you have the SVDNet source code written on Pytorch?

when i use train.py ,it can't run normal!!!

wty@z:~/soft_wty/Person_reID_baseline_pytorch-master$ python3 train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 32 --data_dir /home/wty/soft_wty/dataset/market1501 --erasing_p 0.5
Downloading: "https://download.pytorch.org/models/densenet121-a639ec97.pth" to /home/wty/.torch/models/densenet121-a639ec97.pth
Traceback (most recent call last):
File "/home/wty/soft_wty/local_install/lib/python3.6/urllib/request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/home/wty/soft_wty/local_install/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/home/wty/soft_wty/local_install/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/home/wty/soft_wty/local_install/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/home/wty/soft_wty/local_install/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/home/wty/soft_wty/local_install/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/home/wty/soft_wty/local_install/lib/python3.6/http/client.py", line 1400, in connect
server_hostname=server_hostname)
File "/home/wty/soft_wty/local_install/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/home/wty/soft_wty/local_install/lib/python3.6/ssl.py", line 814, in init
self.do_handshake()
File "/home/wty/soft_wty/local_install/lib/python3.6/ssl.py", line 1068, in do_handshake
self._sslobj.do_handshake()
File "/home/wty/soft_wty/local_install/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "train.py", line 20, in
from model import ft_net, ft_net_dense, PCB
File "/home/software_mount/wty/Person_reID_baseline_pytorch-master/model.py", line 200, in
net = ft_net_dense(751)
File "/home/software_mount/wty/Person_reID_baseline_pytorch-master/model.py", line 83, in init
model_ft = models.densenet121(pretrained=True)
File "/home/wty/soft_wty/local_install/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg/torchvision/models/densenet.py", line 35, in densenet121
File "/home/wty/soft_wty/local_install/lib/python3.6/site-packages/torch/utils/model_zoo.py", line 65, in load_url
_download_url_to_file(url, cached_file, hash_prefix, progress=progress)
File "/home/wty/soft_wty/local_install/lib/python3.6/site-packages/torch/utils/model_zoo.py", line 70, in _download_url_to_file
u = urlopen(url)
File "/home/wty/soft_wty/local_install/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/home/wty/soft_wty/local_install/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/home/wty/soft_wty/local_install/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/home/wty/soft_wty/local_install/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/home/wty/soft_wty/local_install/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/home/wty/soft_wty/local_install/lib/python3.6/urllib/request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)>

pip3 list show:
cycler (0.10.0)
kiwisolver (1.0.1)
matplotlib (2.2.2)
numpy (1.15.0)
Pillow (5.2.0)
pip (9.0.3)
pyparsing (2.2.0)
python-dateutil (2.7.3)
pytz (2018.5)
PyYAML (3.13)
setuptools (39.0.1)
six (1.11.0)
torch (0.4.0)
torchvision (0.2.1)
tqdm (3.7.0)

python3 -V show:
Python 3.6.5

model.py run error

python train.py --gpu_ids 0 --name ft_ResNet50 --train_all --batchsize 32 --data_dir your_data_path

the error is:

net output size:
Traceback (most recent call last):
File "/reid_baseline/model.py", line 100, in <module>
print(output.shape)

i want try resnet50

multi gpu error

CUDA_VISIBLE_DEVICES=6,7 python train.py --PCB --batchsize 60 --name PCB-64 --train_all

I use multi gpu, so add some code:
if torch.cuda.device_count() > 1 and use_gpu:
  model_wraped = nn.DataParallel(model).cuda()
  model = model_wraped

but error in forward:
RuntimeError: cuda runtime error (77) : an illegal memory access was encountered at /opt/conda/conda-bld/pytorch_1513368888240/work/torch/lib/THC/THCTensorCopy.cu:204

RandomErasing

问题1:文章中说的是用随机值填充,代码给的均值是统计得到的吗?
问题2:对应这种global represention用这种方法可能有效,但是针对part-based方法,反倒丢失了细节,不知是否可行?

reranking evaluate issue

After training the resnet50 model and run test.py to generate the feature mat file,
I run the python file evaluate.py and got the result as below:
top1:0.802850 top5:0.911817 top10:0.945962 mAP:0.627301
while when I run evaluate_rerank.py, I got the bad result:
top1:0.000297 top5:0.000594 top10:0.001485 mAP:0.000627

Do you konw what is the matter with the bad result?
Looking forward to your reply.

about PCB model

Why your images reshape to 384192 instead of 384128 which was proposed in paper.

Error when running test.py

Hi, @layumi. Thanks for the great code. I tried your code on Market-1501 and it worked very well. Now I have trained the model for DukeMTMC-reID but when running test.py I got such errors as below

RuntimeError: inconsistent tensor size, expected tensor [751 x 512] and src [702 x 512] to have the same number of elements, but got 384512 and 359424 elements respectively
RuntimeError: While copying the parameter named classifier.0.weight, whose dimensions in the model are torch.Size([751, 512]) and whose dimensions in the checkpoint are torch.Size([702, 512]).

损失函数问题

请问这个代码计算损失函数时,是同时考虑了分类损失和验证损失吗?

An UserWarning

UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
train_loss += loss.data[0]

so transforming the 'train_loss += loss.data[0] ' into 'train_loss+=loss.item() ' in the 'train.py:200' can fix the warning on the new pytorch version.

error when loading pretrained ResNet-50 model

Hi,
I download the pretrainded model offered by the author from Googledrive

But it went error as follow
RuntimeError: Error(s) in loading state_dict for ft_net:
Missing key(s) in state_dict: "model.fc.weight", "model.fc.bias", "classifier.add_block.0.weight", "classifier.add_block.0.bias", "classifier.add_block.1.weight", "classifier.add_block.1.bias", "classifier.add_block.1.running_mean", "classifier.add_block.1.running_var", "classifier.classifier.0.weight", "classifier.classifier.0.bias".
Unexpected key(s) in state_dict: "model.fc.0.weight", "model.fc.0.bias", "model.fc.1.weight", "model.fc.1.bias", "model.fc.1.running_mean", "model.fc.1.running_var", "classifier.0.weight", "classifier.0.bias".

How can I solve this problem? Any suggestion would be appreciable.
Thanks,
Zhang

How to train vs test

Thanks so much for providing such an excellent codebase.

I'm sorry if this is too simple a question. The model is trained as a classification problem (input were images and output was ID numbers). If the model was previously outputting ID numbers during training, how would it output retrieved images during testing?

ValueError: expected 2D or 3D input (got 1D input)

when I run train.py using resnet50,after running for sometime, I meet a problen of ValueError: expected 2D or 3D input (got 1D input),in class ClassBlock(nn.Module): def forward(self, x): x = self.add_block(x).

About DukeMTMC-reID Dataset performance

Hello,
I want to test the code on DukeMTMC-reID dataset and need to improve the performance. In the README.md, it said:

Futhermore, you also can test our code on DukeMTMC-reID Dataset. Our baseline code is not such high on DukeMTMC-reID Rank@1=64.23%, mAP=43.92%. Hyperparameters are need to be tuned.

Which hyperparameters should I adjust? Any informations is helpful.
Thank you and waiting for your reply.

Size of Input Images for Using Pre-Trained Model

Dear @layumi,
Thank you for your nice work. I have a question. What is the correct size of input image, If one want to use your released pre-trained model (i.e., for forward pass & feature extraction of input image)? I mean (256,128) or (288,144)?

learning rate for rpp

I found that your code doesn't include the RPP part.I did it myself , but it didn't perform that good, can you tell me how to set the learning rate,epoch nums and so on in Step3 and Step4.

i have a error in train.py

when i run the train.py ,it work this result,
2018-03-28 15-29-04
you problem can download the densenet121-a639ec97.pth automatically ,but the Great Wall may stop download.so,i download this file in hand ,and put it into /home/mrzhu/.torch/models,like this.
2018-03-28 15-28-36
en.would i do for this problem,may you give a good idea .thank you very much.

ValueError: empty range for randrange() (0,-79, -79)

I try to use other convnets, however, I meet to size problems:
When I use densenet121, I change the crop size to 224 * 224 but it occurs that
"alueError: empty range for randrange() (0,-79, -79)"
If I don't change the size to 224*224 and keep it as "256,128" it will occur
“RuntimeError: Given input size: (1024x8x4). Calculated output size: (1024x2x-2). Output size is too small at /opt/conda/conda-bld/pytorch_1512386481460/work/torch/lib/THCUNN/generic/SpatialAveragePooling.cu:63”
How can I change the size for training other nets?

Pre-processing before training

Hi @layumi, I found you normalize the image pixel with fixed mean value and standard deviation for each channel respectively. I wonder how to determine these three pairs of values. Are they only suitable for Market-1501?

Thanks a lot! ;)

Do the junk images also participate in re-ranking?

It seems all the junk images are also used during the re-ranking process. But the problem is that for each query image, some of the junk images actually come from the same camera and may affect the retrieval performance if these junk images are used for re-ranking.

I want to know:

  1. Do the junk images really participate in the re-ranking process?
  2. If 1 is true, is it a widely accepted procedure in other published papers?

Multi query evaluation

Hi!
Thanks for the baseline.
The evaluation baseline works for the Single Query settings. Can you provide insights on how to modify the baseline and get the same results for multi query settings.

Thank you

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.