Torchreid는 Pytorch로 작성되었으며 ICCV'19 프로젝트 인 Omni-Scale 기능 학습을위한 ICCV'19 프로젝트를 위해 개발 된 딥 러닝 사람 재 식별을위한 도서관입니다.
기능 :
코드 : https://github.com/kaiyangzhou/deep-person-reid.
문서 : https://kaiyangzhou.github.io/deep-person-reid/.
방법 지침 : https://kaiyangzhou.github.io/deep-person-reid/user_guide.
모델 동물원 : https://kaiyangzhou.github.io/deep-person-reid/model_zoo.
기술 보고서 : https://arxiv.org/abs/1910.10093.
Torchreid 위에 구축 된 일부 연구 프로젝트를 여기에서 찾을 수 있습니다.
osnet_ain_x0_75 , osnet_ain_x0_5 및 osnet_ain_x0_25 의 imageNet-retrained 모델을 발표했습니다. 사전 여분의 설정은 pycls를 따릅니다.tools/parse_test_res.py 참조하십시오.v1.4.0 : 우리는 Person Search Dataset, Cuhk-Sysu를 추가했습니다. 데이터 세트를 다운로드하는 방법에 대한 설명서를 참조하십시오 (자른 사람 이미지가 포함되어 있음).v1.3.6 다중 뷰 다중 소스 지리적 지역화를위한 새로운 데이터 세트 인 University-1652를 추가했습니다 (Zhedong Zheng에 대한 신용).v1.3.5 : 이제 Cython 코드는 Windows에서 작동합니다 (Lablabla에 대한 크레딧).v1.3.3 : visrank 에서 버그를 수정했습니다 ( dsetid 포장을 풀지 않음).v1.3.2 : grid 및 prid 에 _junk_pids 추가했습니다. 이것은 combineall=True 설정할 때 훈련을 위해 잘못 표지 된 갤러리 이미지를 사용하지 않습니다.v1.3.0 : (1) 기존 3- 튜플 데이터 소스에 dsetid 추가하여 (impath, pid, camid, dsetid) 초래했습니다. 이 변수는 데이터 세트 ID를 나타내며 교육을 위해 여러 데이터 세트를 결합 할 때 유용합니다 (데이터 세트 표시기). 예를 들어, market1501 과 cuhk03 결합 할 때 전자는 dsetid=0 으로 할당되며 후자는 dsetid=1 할당됩니다. (2) RandomDatasetSampler 추가되었습니다. RandomDomainSampler 와 유사한 RandomDatasetSampler 각 지정된 데이터 세트 (금액은 num_datasets 에 의해 결정됨)의 특정 수의 이미지 ( batch_size // num_datasets )를 샘플합니다.v1.2.6 : RandomDomainSampler 추가되었습니다 (IT는 batch_size // num_cams 이미지가있는 num_cams 카메라를 샘플링하여 미니 배치를 형성합니다).v1.2.5 : (1) __getitem__ 의 Dataloader의 출력이 list 에서 dict 으로 변경되었습니다. 이전에는 요소와 같은 이미지 텐서가 imgs=data[0] 로 가져 왔습니다. 이제 imgs=data['img'] 에 의해 얻어야합니다. 자세한 변경은이 커밋을 참조하십시오. (2) 이미지 데이터 로더의 옵션으로 k_tfm 추가하여 데이터 증강을 이미지에 독립적으로 k_tfm 시간에 적용 할 수 있습니다. k_tfm > 1 인 경우 imgs=data['img'] k_tfm 이미지 텐서로 목록을 반환합니다.projects/attribute_recognition/ 참조하십시오.v1.2.1 : 기능 추출 ( torchreid/utils/feature_extractor.py )에 대한 간단한 API를 추가했습니다. 지침 문서를 참조하십시오.projects/DML 에서 발표되었습니다.v1.2.0 으로 업그레이드 됨. 엔진 클래스는 확장 성을 향상시키기 위해보다 모델에 비해 더 많은 모델을 만들어 냈습니다. 자세한 내용은 엔진 및 ImagesOftMaxEngine을 참조하십시오. dassl.pytorch에 대한 신용.ImageDataManager load_train_targets=True 설정하여 대상 데이터 세트에서 교육 데이터를로드 할 수 있으며 train_loader_t = datamanager.train_loader_t 로 Train-Loader에 액세스 할 수 있습니다. 이 기능은 도메인 적응 연구에 유용합니다. 콘다가 설치되어 있는지 확인하십시오.
# cd to your preferred directory and clone this repo
git clone https://github.com/KaiyangZhou/deep-person-reid.git
# create environment
cd deep-person-reid/
conda create --name torchreid python=3.7
conda activate torchreid
# install dependencies
# make sure `which python` and `which pip` point to the correct path
pip install -r requirements.txt
# install torch and torchvision (select the proper cuda version to suit your machine)
conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
# install torchreid (don't need to re-build it if you modify the source code)
python setup.py develop설치하는 또 다른 방법은 Docker 컨테이너 내부에서 모든 것을 실행하는 것입니다.
make build-imagemake run torchreid 를 가져옵니다 import torchreid datamanager = torchreid . data . ImageDataManager (
root = "reid-data" ,
sources = "market1501" ,
targets = "market1501" ,
height = 256 ,
width = 128 ,
batch_size_train = 32 ,
batch_size_test = 100 ,
transforms = [ "random_flip" , "random_crop" ]
)3 빌드 모델, Optimizer 및 LR_SCHEDULER
model = torchreid . models . build_model (
name = "resnet50" ,
num_classes = datamanager . num_train_pids ,
loss = "softmax" ,
pretrained = True
)
model = model . cuda ()
optimizer = torchreid . optim . build_optimizer (
model ,
optim = "adam" ,
lr = 0.0003
)
scheduler = torchreid . optim . build_lr_scheduler (
optimizer ,
lr_scheduler = "single_step" ,
stepsize = 20
) engine = torchreid . engine . ImageSoftmaxEngine (
datamanager ,
model ,
optimizer = optimizer ,
scheduler = scheduler ,
label_smooth = True
) engine . run (
save_dir = "log/resnet50" ,
max_epoch = 60 ,
eval_freq = 10 ,
print_freq = 10 ,
test_only = False
)"심해-리드/스크립트/"에서는 모델을 훈련하고 테스트하기위한 통합 인터페이스를 제공합니다. 자세한 내용은 "Scripts/Main.py"및 "Scripts/Default_Config.py"를 참조하십시오. "configs/"폴더에는 시작점으로 사용할 수있는 일부 사전 정의 된 구성이 포함되어 있습니다.
아래에서 우리는 OSNET를 훈련시키고 테스트하는 예를 제공합니다 (Zhou et al. ICCV'19). PATH_TO_DATA Reid 데이터 세트를 포함하는 디렉토리라고 가정합니다. 환경 변수 CUDA_VISIBLE_DEVICES 생략되며 GPU 풀이 있고 특정 세트를 사용하려는 경우 지정해야합니다.
Market1501에서 Osnet을 훈련시키기 위해
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad_cosine.yaml
--transforms random_flip random_erase
--root $PATH_TO_DATA구성 파일은 Market1501을 기본 데이터 세트로 설정합니다. dukemtmc-reid를 사용하고 싶다면하십시오
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad_cosine.yaml
-s dukemtmcreid
-t dukemtmcreid
--transforms random_flip random_erase
--root $PATH_TO_DATA
data.save_dir log/osnet_x1_0_dukemtmcreid_softmax_cosinelr 코드는 ImageNet 사전 관리 중량을 자동으로 (다운로드 및)로드합니다. 교육이 완료되면 모델은 "log/osnet_x1_0_market1501_softmax_cosinelr/model.pth.tar-250"으로 저장됩니다. 동일한 폴더에서 Tensorboard 파일을 찾을 수 있습니다. Tensorboard를 사용하여 학습 곡선을 시각화하려면 tensorboard --logdir=log/osnet_x1_0_market1501_softmax_cosinelr 는 http://localhost:6006/ 웹 브라우저를 방문 할 수 있습니다.
평가는 훈련이 끝날 때 자동으로 수행됩니다. 훈련 된 모델을 사용하여 다시 테스트를 실행하려면
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad_cosine.yaml
--root $PATH_TO_DATA
model.load_weights log/osnet_x1_0_market1501_softmax_cosinelr/model.pth.tar-250
test.evaluate TrueDukemtmc-Reid에서 OSNET를 훈련시키고 Market1501에서 성능을 테스트하고 싶다고 가정합니다.
python scripts/main.py
--config-file configs/im_osnet_x1_0_softmax_256x128_amsgrad.yaml
-s dukemtmcreid
-t market1501
--transforms random_flip color_jitter
--root $PATH_TO_DATA 여기서는 크로스 도메인 성능 만 테스트합니다. 그러나 소스 데이터 세트에서 성능을 테스트하려면 Dukemtmc -Reid를 테스트하려면 -t dukemtmcreid market1501 설정하여 두 데이터 세트의 모델을 별도로 평가할 수 있습니다.
동일한 도메인 설정과는 달리, 여기서 우리는 random_erase color_jitter 로 대체합니다. 이것은 보이지 않는 대상 데이터 세트의 일반화 성능을 향상시킬 수 있습니다.
사전 예방 모델은 모델 동물원에서 사용할 수 있습니다.
이 코드 나 연구에서 모델을 사용하는 경우 다음 논문에 대한 크레딧을 제공하십시오.
@article{torchreid,
title={Torchreid: A Library for Deep Learning Person Re-Identification in Pytorch},
author={Zhou, Kaiyang and Xiang, Tao},
journal={arXiv preprint arXiv:1910.10093},
year={2019}
}
@inproceedings{zhou2019osnet,
title={Omni-Scale Feature Learning for Person Re-Identification},
author={Zhou, Kaiyang and Yang, Yongxin and Cavallaro, Andrea and Xiang, Tao},
booktitle={ICCV},
year={2019}
}
@article{zhou2021osnet,
title={Learning Generalisable Omni-Scale Representations for Person Re-Identification},
author={Zhou, Kaiyang and Yang, Yongxin and Cavallaro, Andrea and Xiang, Tao},
journal={TPAMI},
year={2021}
}