Giter VIP home page Giter VIP logo

open-scpnet's Introduction

The implementation of the SCPNet modified from person-reid-triplet-loss-baseline. If you use this repo, please cite the following paper:

@inproceedings{SCPNet,
  title = {SCPNet: Spatial-Channel Parallelism Network for Joint Holistic and Partial Person Re-Identification},
  author = {Fan, Xing and Luo, Hao and Zhang, Xuan and He, Lingxiao and Zhang, Chi and Jiang, Wei},
  booktitle = {ACCV},
  year = {2018}
}

Installation

The original code is based on a internal deep learning framewok using 4 datasets together. We re-implement it using PyTorch in this repo based on person-reid-triplet-loss-baseline (More useful information may be found).

You can use Python2 and install PyTorch using the following commands (at least one Nvida GPU is required):

pip install torch==0.3.1
pip install torchvision

After training on single dataset alone for 200 epoch, the following results should be achieved:

Market-1501 DukeMTMC-reID
Original Version (paper) rank-1: 91.2, mAP: 75.2 rank-1: 80.3, mAP: 62.6
This re-implement (repo) rank-1: 90.4, mAP: 74.9 rank-1: 81.2, mAP: 64.5

Dataset Preparation

Inspired by Tong Xiao's open-reid project, you need to prepare datasets first.

Market1501

You can download what I have transformed for the project from Google Drive or BaiduYun. Otherwise, you can download the original dataset and transform it using my script, described below.

Download the Market1501 dataset from here. Run the following script to transform the dataset, replacing the paths with yours.

python script/dataset/transform_market1501.py \
--zip_file ~/Dataset/market1501/Market-1501-v15.09.15.zip \
--save_dir ~/Dataset/market1501

CUHK03

We follow the new training/testing protocol proposed in paper

@article{zhong2017re,
  title={Re-ranking Person Re-identification with k-reciprocal Encoding},
  author={Zhong, Zhun and Zheng, Liang and Cao, Donglin and Li, Shaozi},
  booktitle={CVPR},
  year={2017}
}

Details of the new protocol can be found here.

You can download what I have transformed for the project from Google Drive or BaiduYun. Otherwise, you can download the original dataset and transform it using my script, described below.

Download the CUHK03 dataset from here. Then download the training/testing partition file from Google Drive or BaiduYun. This partition file specifies which images are in training, query or gallery set. Finally run the following script to transform the dataset, replacing the paths with yours.

python script/dataset/transform_cuhk03.py \
--zip_file ~/Dataset/cuhk03/cuhk03_release.zip \
--train_test_partition_file ~/Dataset/cuhk03/re_ranking_train_test_split.pkl \
--save_dir ~/Dataset/cuhk03

DukeMTMC-reID

You can download what I have transformed for the project from Google Drive or BaiduYun. Otherwise, you can download the original dataset and transform it using my script, described below.

Download the DukeMTMC-reID dataset from here. Run the following script to transform the dataset, replacing the paths with yours.

python script/dataset/transform_duke.py \
--zip_file ~/Dataset/duke/DukeMTMC-reID.zip \
--save_dir ~/Dataset/duke

Combining Trainval Set of Market1501, CUHK03, DukeMTMC-reID

Larger training set tends to benefit deep learning models, so I combine trainval set of three datasets Market1501, CUHK03 and DukeMTMC-reID. After training on the combined trainval set, the model can be tested on three test sets as usual.

Transform three separate datasets as introduced above if you have not done it.

For the trainval set, you can download what I have transformed from Google Drive or BaiduYun. Otherwise, you can run the following script to combine the trainval sets, replacing the paths with yours.

python script/dataset/combine_trainval_sets.py \
--market1501_im_dir ~/Dataset/market1501/images \
--market1501_partition_file ~/Dataset/market1501/partitions.pkl \
--cuhk03_im_dir ~/Dataset/cuhk03/detected/images \
--cuhk03_partition_file ~/Dataset/cuhk03/detected/partitions.pkl \
--duke_im_dir ~/Dataset/duke/images \
--duke_partition_file ~/Dataset/duke/partitions.pkl \
--save_dir ~/Dataset/market1501_cuhk03_duke

Configure Dataset Path

The project requires you to configure the dataset paths. In tri_loss/dataset/__init__.py, modify the following snippet according to your saving paths used in preparing datasets.

# In file tri_loss/dataset/__init__.py

########################################
# Specify Directory and Partition File #
########################################

if name == 'market1501':
  im_dir = ospeu('~/Dataset/market1501/images')
  partition_file = ospeu('~/Dataset/market1501/partitions.pkl')

elif name == 'cuhk03':
  im_type = ['detected', 'labeled'][0]
  im_dir = ospeu(ospj('~/Dataset/cuhk03', im_type, 'images'))
  partition_file = ospeu(ospj('~/Dataset/cuhk03', im_type, 'partitions.pkl'))

elif name == 'duke':
  im_dir = ospeu('~/Dataset/duke/images')
  partition_file = ospeu('~/Dataset/duke/partitions.pkl')

elif name == 'combined':
  assert part in ['trainval'], \
    "Only trainval part of the combined dataset is available now."
  im_dir = ospeu('~/Dataset/market1501_cuhk03_duke/trainval_images')
  partition_file = ospeu('~/Dataset/market1501_cuhk03_duke/partitions.pkl')

Evaluation Protocol

Datasets used in this project all follow the standard evaluation protocol of Market1501, using CMC and mAP metric. According to open-reid, the setting of CMC is as follows

# In file tri_loss/dataset/__init__.py

cmc_kwargs = dict(separate_camera_set=False,
                  single_gallery_shot=False,
                  first_match_break=True)

To play with different CMC options, you can modify it accordingly.

# In open-reid's reid/evaluators.py

# Compute all kinds of CMC scores
cmc_configs = {
  'allshots': dict(separate_camera_set=False,
                   single_gallery_shot=False,
                   first_match_break=False),
  'cuhk03': dict(separate_camera_set=True,
                 single_gallery_shot=True,
                 first_match_break=False),
  'market1501': dict(separate_camera_set=False,
                     single_gallery_shot=False,
                     first_match_break=True)}

Examples

Test

My training log and saved model weights for three datasets can be downloaded from Google Drive or BaiduYun.

Specify

  • a dataset name (one of market1501, cuhk03, duke)
  • stride, 1 or 2
  • an experiment directory for saving testing log
  • the path of the downloaded model_weight.pth

in the following command and run it.

python2 script/experiment/train.py \
-d '(0,)' \
--only_test true \
--dataset DATASET_NAME \
--last_conv_stride STRIDE \
--normalize_feature false \
--exp_dir EXPERIMENT_DIRECTORY \
--model_weight_file THE_DOWNLOADED_MODEL_WEIGHT_FILE

Train

You can also train it by yourself. The following command performs training, validation and finally testing automatically.

Specify

  • a dataset name (one of ['market1501', 'cuhk03', 'duke'])
  • stride, 1 or 2
  • training on trainval set or train set (for tuning parameters)
  • an experiment directory for saving training log

in the following command and run it.

python2 script/experiment/train.py \
-d '(0,)' \
--only_test false \
--dataset DATASET_NAME \
--last_conv_stride STRIDE \
--normalize_feature false \
--trainset_part TRAINVAL_OR_TRAIN \
--exp_dir EXPERIMENT_DIRECTORY \
--steps_per_log 10 \
--epochs_per_val 5

Log

During training, you can run the TensorBoard and access port 6006 to watch the loss curves etc. E.g.

# Modify the path for `--logdir` accordingly.
tensorboard --logdir YOUR_EXPERIMENT_DIRECTORY/tensorboard

For more usage of TensorBoard, see the website and the help:

tensorboard --help

Visualize Ranking List

Specify

  • a dataset name (one of ['market1501', 'cuhk03', 'duke'])
  • stride, 1 or 2
  • either model_weight_file (the downloaded model_weight.pth) OR ckpt_file (saved ckpt.pth during training)
  • an experiment directory for saving images and log

in the following command and run it.

python script/experiment/visualize_rank_list.py \
-d '(0,)' \
--num_queries 16 \
--rank_list_size 10 \
--dataset DATASET_NAME \
--last_conv_stride STRIDE \
--normalize_feature false \
--exp_dir EXPERIMENT_DIRECTORY \
--model_weight_file '' \
--ckpt_file ''

Each query image and its ranking list would be saved to an image in directory EXPERIMENT_DIRECTORY/rank_lists. As shown in following examples, green boundary is added to true positive, and red to false positve.

References & Credits

open-scpnet's People

Contributors

xfanplus 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

Watchers

 avatar  avatar  avatar

open-scpnet's Issues

TypeError: Can't mix strings and bytes in path components

python script/dataset/combine_trainval_sets.py --market1501_im_dir ./Dataset/market1501/images --market1501_partition_file ./Dataset/market1501/partitions.pkl --cuhk03_im_dir ./Dataset/cuhk03/detected/images --cuhk03_partition_file ./Dataset/cuhk03/detected/partitions.pkl --duke_im_dir ./Dataset/duke/images --duke_partition_file ./Dataset/duke/partitions.pkl --save_dir ./Dataset/market1501_cuhk03_duke
Traceback (most recent call last):
File "script/dataset/combine_trainval_sets.py", line 140, in
combine_trainval_sets(im_dirs, partition_files, save_dir)
File "script/dataset/combine_trainval_sets.py", line 59, in combine_trainval_sets
im_paths = [ospj(im_dir, n) for n in partitions['trainval_im_names']]
File "script/dataset/combine_trainval_sets.py", line 59, in
im_paths = [ospj(im_dir, n) for n in partitions['trainval_im_names']]
File "/home/jy/.conda/envs/reid/lib/python3.6/posixpath.py", line 94, in join
genericpath._check_arg_types('join', a, *p)
File "/home/jy/.conda/envs/reid/lib/python3.6/genericpath.py", line 151, in _check_arg_types
raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components

Partial REID 和 Partial-iLIDS 自制数据集?

我感觉Partial REID是制作的数据集,感觉好像看到了罗大佬- -,那个Partial-iLIDS感觉是机场视频取帧制作的数据集。所有应该不算是公开哪种能下载到的。

model mismatch

i train the model with your code on combined dataset,when i try to test on single dataset,it occurs size mismatch bug

partial ReID datasets

The paper claims that you test on two partial ReID datasets, but the repository seems to have no related code?

about CUHK_SYSU data

Thank you very much for sharing your code. Can you share your transform_cuhksysu.py by the way?Thanks!

keys not found

while only test my model, i got "keys not found" error, and then mAP & rank1 are very low as a result.
even when i do not try to do cross domain test, this still happens.
may you show me how to solve this trouble?

Keys not found in source state_dict: ...
Keys not found in destination state_dict: ...

Train:batch_size?

您好!想询问一下,训练过程中的batch_size是trainset.py中的定义为ids_per_batch?还是ids_per_batch和ims_per_id的乘积?谢谢!

python version

Is this article using python2, but this version has been discontinued. And one of the Queue modules cannot be installed, can anyone please advise?

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.