Skip to content

Commit 6509a44

Browse files
committed
init
0 parents  commit 6509a44

File tree

93 files changed

+6453
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+6453
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 heshuting555
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SOLIDER on Person Re-identification
2+
3+
This repo provides details about how to use [SOLIDER](https://github.com/tinyvision/SOLIDER) pretrained representation on **person re-identification task**.
4+
We modify the code from [TransReID](https://github.com/damo-cv/TransReID), and you can refer to the original repo for more details.
5+
6+
## Installation and Datasets
7+
8+
We use python version 3.7, PyTorch version 1.7.1, CUDA 10.1 and torchvision 0.8.2. More details of installation and dataset preparation can be found in [TransReID-SSL](https://github.com/damo-cv/TransReID-SSL).
9+
10+
## Prepare Pre-trained Models
11+
You can download models from [SOLIDER](https://github.com/tinyvision/SOLIDER), or use [SOLIDER](https://github.com/tinyvision/SOLIDER) to train your own models.
12+
Before training, you should convert the models first.
13+
14+
```bash
15+
python convert_model.py path/to/SOLIDER/log/lup/swin_tiny/checkpoint.pth path/to/SOLIDER/log/lup/swin_tiny/checkpoint_tea.pth
16+
```
17+
18+
## Training
19+
20+
We utilize 1 GPU for training. Please modify the `MODEL.PRETRAIN_PATH`, `DATASETS.ROOT_DIR` and `OUTPUT_DIR` in the config file.
21+
22+
```bash
23+
sh run.sh
24+
```
25+
26+
## Performance
27+
28+
| Method | Model | MSMT17<br>(mAP/R1) | Market1501<br>(mAP/R1) |
29+
| ------ | :---: | :---: | :---: |
30+
| SOLIDER | Swin Tiny | 67.4/85.9 | 91.6/96.1 |
31+
| SOLIDER | Swin Small | 76.9/90.8 | 93.3/96.6 |
32+
| SOLIDER | Swin Base | 77.1/90.7 | 93.9/96.9 |
33+
34+
- We use the pretrained models from [SOLIDER](https://github.com/tinyvision/SOLIDER).
35+
- The semantic weight is set to 0.2 in these experiments.
36+
37+
## Citation
38+
39+
If you find this code useful for your research, please cite our paper
40+
41+
```
42+
@inproceedings{chen2023beyond,
43+
title={Beyond Appearance: a Semantic Controllable Self-Supervised Learning Framework for Human-Centric Visual Tasks},
44+
author={Weihua Chen and Xianzhe Xu and Jian Jia and Hao Luo and Yaohua Wang and Fan Wang and Rong Jin and Xiuyu Sun},
45+
booktitle={The IEEE/CVF Conference on Computer Vision and Pattern Recognition},
46+
year={2023},
47+
}
48+
```

config/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# encoding: utf-8
2+
"""
3+
@author: sherlock
4+
5+
"""
6+
7+
from .defaults import _C as cfg
8+
from .defaults import _C as cfg_test
329 Bytes
Binary file not shown.
2.53 KB
Binary file not shown.

config/defaults.py

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
from yacs.config import CfgNode as CN
2+
3+
# -----------------------------------------------------------------------------
4+
# Convention about Training / Test specific parameters
5+
# -----------------------------------------------------------------------------
6+
# Whenever an argument can be either used for training or for testing, the
7+
# corresponding name will be post-fixed by a _TRAIN for a training parameter,
8+
9+
# -----------------------------------------------------------------------------
10+
# Config definition
11+
# -----------------------------------------------------------------------------
12+
13+
_C = CN()
14+
# -----------------------------------------------------------------------------
15+
# MODEL
16+
# -----------------------------------------------------------------------------
17+
_C.MODEL = CN()
18+
# Using cuda or cpu for training
19+
_C.MODEL.DEVICE = "cuda"
20+
# ID number of GPU
21+
_C.MODEL.DEVICE_ID = '0'
22+
# Name of backbone
23+
_C.MODEL.NAME = 'resnet50'
24+
# Last stride of backbone
25+
_C.MODEL.LAST_STRIDE = 1
26+
# Path to pretrained model of backbone
27+
_C.MODEL.PRETRAIN_PATH = ''
28+
_C.MODEL.PRETRAIN_HW_RATIO = 1
29+
30+
# Use ImageNet pretrained model to initialize backbone or use self trained model to initialize the whole model
31+
# Options: 'imagenet' , 'self' , 'finetune'
32+
_C.MODEL.PRETRAIN_CHOICE = 'imagenet'
33+
34+
# If train with BNNeck, options: 'bnneck' or 'no'
35+
_C.MODEL.NECK = 'bnneck'
36+
# If train loss include center loss, options: 'yes' or 'no'. Loss with center loss has different optimizer configuration
37+
_C.MODEL.IF_WITH_CENTER = 'no'
38+
39+
_C.MODEL.ID_LOSS_TYPE = 'softmax'
40+
_C.MODEL.ID_LOSS_WEIGHT = 1.0
41+
_C.MODEL.TRIPLET_LOSS_WEIGHT = 1.0
42+
43+
_C.MODEL.METRIC_LOSS_TYPE = 'triplet'
44+
# If train with multi-gpu ddp mode, options: 'True', 'False'
45+
_C.MODEL.DIST_TRAIN = False
46+
# If train with soft triplet loss, options: 'True', 'False'
47+
_C.MODEL.NO_MARGIN = False
48+
# If train with label smooth, options: 'on', 'off'
49+
_C.MODEL.IF_LABELSMOOTH = 'on'
50+
# If train with arcface loss, options: 'True', 'False'
51+
_C.MODEL.COS_LAYER = False
52+
53+
_C.MODEL.DROPOUT_RATE = 0.0
54+
# Reduce feature dim
55+
_C.MODEL.REDUCE_FEAT_DIM = False
56+
_C.MODEL.FEAT_DIM = 512
57+
# Transformer setting
58+
_C.MODEL.DROP_PATH = 0.1
59+
_C.MODEL.DROP_OUT = 0.0
60+
_C.MODEL.ATT_DROP_RATE = 0.0
61+
_C.MODEL.TRANSFORMER_TYPE = 'None'
62+
_C.MODEL.STRIDE_SIZE = [16, 16]
63+
_C.MODEL.GEM_POOLING = False
64+
_C.MODEL.STEM_CONV = False
65+
66+
# JPM Parameter
67+
_C.MODEL.JPM = False
68+
_C.MODEL.SHIFT_NUM = 5
69+
_C.MODEL.SHUFFLE_GROUP = 2
70+
_C.MODEL.DEVIDE_LENGTH = 4
71+
_C.MODEL.RE_ARRANGE = True
72+
73+
# SIE Parameter
74+
_C.MODEL.SIE_COE = 3.0
75+
_C.MODEL.SIE_CAMERA = False
76+
_C.MODEL.SIE_VIEW = False
77+
78+
# Semantic Weight
79+
_C.MODEL.SEMANTIC_WEIGHT = 1.0
80+
81+
# -----------------------------------------------------------------------------
82+
# INPUT
83+
# -----------------------------------------------------------------------------
84+
_C.INPUT = CN()
85+
# Size of the image during training
86+
_C.INPUT.SIZE_TRAIN = [384, 128]
87+
# Size of the image during test
88+
_C.INPUT.SIZE_TEST = [384, 128]
89+
# Random probability for image horizontal flip
90+
_C.INPUT.PROB = 0.5
91+
# Random probability for random erasing
92+
_C.INPUT.RE_PROB = 0.5
93+
# Values to be used for image normalization
94+
_C.INPUT.PIXEL_MEAN = [0.485, 0.456, 0.406]
95+
# Values to be used for image normalization
96+
_C.INPUT.PIXEL_STD = [0.229, 0.224, 0.225]
97+
# Value of padding size
98+
_C.INPUT.PADDING = 10
99+
100+
# -----------------------------------------------------------------------------
101+
# Dataset
102+
# -----------------------------------------------------------------------------
103+
_C.DATASETS = CN()
104+
# List of the dataset names for training, as present in paths_catalog.py
105+
_C.DATASETS.NAMES = ('market1501')
106+
# Root directory where datasets should be used (and downloaded if not found)
107+
_C.DATASETS.ROOT_DIR = ('../data')
108+
_C.DATASETS.ROOT_TRAIN_DIR = ('../data')
109+
_C.DATASETS.ROOT_VAL_DIR = ('../data')
110+
111+
112+
# -----------------------------------------------------------------------------
113+
# DataLoader
114+
# -----------------------------------------------------------------------------
115+
_C.DATALOADER = CN()
116+
# Number of data loading threads
117+
_C.DATALOADER.NUM_WORKERS = 8
118+
# Sampler for data loading
119+
_C.DATALOADER.SAMPLER = 'softmax'
120+
# Number of instance for one batch
121+
_C.DATALOADER.NUM_INSTANCE = 16
122+
# remove tail data
123+
_C.DATALOADER.REMOVE_TAIL = 0
124+
125+
# ---------------------------------------------------------------------------- #
126+
# Solver
127+
# ---------------------------------------------------------------------------- #
128+
_C.SOLVER = CN()
129+
# Name of optimizer
130+
_C.SOLVER.OPTIMIZER_NAME = "Adam"
131+
# Number of max epoches
132+
_C.SOLVER.MAX_EPOCHS = 100
133+
# Base learning rate
134+
_C.SOLVER.BASE_LR = 3e-4
135+
# Whether using larger learning rate for fc layer
136+
_C.SOLVER.LARGE_FC_LR = False
137+
# Factor of learning bias
138+
_C.SOLVER.BIAS_LR_FACTOR = 1
139+
# Factor of learning bias
140+
_C.SOLVER.SEED = 1234
141+
# Momentum
142+
_C.SOLVER.MOMENTUM = 0.9
143+
# Margin of triplet loss
144+
_C.SOLVER.MARGIN = 0.3
145+
# Learning rate of SGD to learn the centers of center loss
146+
_C.SOLVER.CENTER_LR = 0.5
147+
# Balanced weight of center loss
148+
_C.SOLVER.CENTER_LOSS_WEIGHT = 0.0005
149+
150+
# Settings of weight decay
151+
_C.SOLVER.WEIGHT_DECAY = 0.0005
152+
_C.SOLVER.WEIGHT_DECAY_BIAS = 0.0005
153+
154+
# decay rate of learning rate
155+
_C.SOLVER.GAMMA = 0.1
156+
# decay step of learning rate
157+
_C.SOLVER.STEPS = (40, 70)
158+
# warm up factor
159+
_C.SOLVER.WARMUP_FACTOR = 0.01
160+
# warm up epochs
161+
_C.SOLVER.WARMUP_EPOCHS = 5
162+
# method of warm up, option: 'constant','linear'
163+
_C.SOLVER.WARMUP_METHOD = "cosine"
164+
165+
_C.SOLVER.COSINE_MARGIN = 0.5
166+
_C.SOLVER.COSINE_SCALE = 30
167+
168+
# epoch number of saving checkpoints
169+
_C.SOLVER.CHECKPOINT_PERIOD = 10
170+
# iteration of display training log
171+
_C.SOLVER.LOG_PERIOD = 100
172+
# epoch number of validation
173+
_C.SOLVER.EVAL_PERIOD = 10
174+
# Number of images per batch
175+
# This is global, so if we have 8 GPUs and IMS_PER_BATCH = 128, each GPU will
176+
# contain 16 images per batch
177+
_C.SOLVER.IMS_PER_BATCH = 64
178+
_C.SOLVER.TRP_L2 = False
179+
180+
# ---------------------------------------------------------------------------- #
181+
# TEST
182+
# ---------------------------------------------------------------------------- #
183+
184+
_C.TEST = CN()
185+
# Number of images per batch during test
186+
_C.TEST.IMS_PER_BATCH = 128
187+
# If test with re-ranking, options: 'True','False'
188+
_C.TEST.RE_RANKING = False
189+
# Path to trained model
190+
_C.TEST.WEIGHT = ""
191+
# Which feature of BNNeck to be used for test, before or after BNNneck, options: 'before' or 'after'
192+
_C.TEST.NECK_FEAT = 'after'
193+
# Whether feature is nomalized before test, if yes, it is equivalent to cosine distance
194+
_C.TEST.FEAT_NORM = 'yes'
195+
196+
# Name for saving the distmat after testing.
197+
_C.TEST.DIST_MAT = "dist_mat.npy"
198+
# Whether calculate the eval score option: 'True', 'False'
199+
_C.TEST.EVAL = False
200+
# ---------------------------------------------------------------------------- #
201+
# Misc options
202+
# ---------------------------------------------------------------------------- #
203+
# Path to checkpoint and saved log of trained model
204+
_C.OUTPUT_DIR = ""

configs/market/swin_base.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
MODEL:
2+
PRETRAIN_HW_RATIO: 2
3+
METRIC_LOSS_TYPE: 'triplet'
4+
IF_LABELSMOOTH: 'off'
5+
IF_WITH_CENTER: 'no'
6+
NAME: 'transformer'
7+
NO_MARGIN: True
8+
DEVICE_ID: ('0')
9+
TRANSFORMER_TYPE: 'swin_base_patch4_window7_224'
10+
STRIDE_SIZE: [16, 16]
11+
12+
INPUT:
13+
SIZE_TRAIN: [384, 128]
14+
SIZE_TEST: [384, 128]
15+
PROB: 0.5 # random horizontal flip
16+
RE_PROB: 0.5 # random erasing
17+
PADDING: 10
18+
PIXEL_MEAN: [0.5, 0.5, 0.5]
19+
PIXEL_STD: [0.5, 0.5, 0.5]
20+
21+
DATASETS:
22+
NAMES: ('market1501')
23+
ROOT_DIR: ('path/to/market1501/datasets')
24+
25+
DATALOADER:
26+
SAMPLER: 'softmax_triplet'
27+
NUM_INSTANCE: 4
28+
NUM_WORKERS: 8
29+
30+
SOLVER:
31+
OPTIMIZER_NAME: 'SGD'
32+
MAX_EPOCHS: 120
33+
BASE_LR: 0.0008
34+
WARMUP_EPOCHS: 20
35+
IMS_PER_BATCH: 64
36+
WARMUP_METHOD: 'cosine'
37+
LARGE_FC_LR: False
38+
CHECKPOINT_PERIOD: 120
39+
LOG_PERIOD: 20
40+
EVAL_PERIOD: 10
41+
WEIGHT_DECAY: 1e-4
42+
WEIGHT_DECAY_BIAS: 1e-4
43+
BIAS_LR_FACTOR: 2
44+
45+
TEST:
46+
EVAL: True
47+
IMS_PER_BATCH: 256
48+
RE_RANKING: False
49+
WEIGHT: ''
50+
NECK_FEAT: 'before'
51+
FEAT_NORM: 'yes'
52+
53+
OUTPUT_DIR: './log/market1501/swin_base'

configs/market/swin_small.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
MODEL:
2+
PRETRAIN_HW_RATIO: 2
3+
METRIC_LOSS_TYPE: 'triplet'
4+
IF_LABELSMOOTH: 'off'
5+
IF_WITH_CENTER: 'no'
6+
NAME: 'transformer'
7+
NO_MARGIN: True
8+
DEVICE_ID: ('0')
9+
TRANSFORMER_TYPE: 'swin_small_patch4_window7_224'
10+
STRIDE_SIZE: [16, 16]
11+
12+
INPUT:
13+
SIZE_TRAIN: [384, 128]
14+
SIZE_TEST: [384, 128]
15+
PROB: 0.5 # random horizontal flip
16+
RE_PROB: 0.5 # random erasing
17+
PADDING: 10
18+
PIXEL_MEAN: [0.5, 0.5, 0.5]
19+
PIXEL_STD: [0.5, 0.5, 0.5]
20+
21+
DATASETS:
22+
NAMES: ('market1501')
23+
ROOT_DIR: ('path/to/market1501/datasets')
24+
25+
DATALOADER:
26+
SAMPLER: 'softmax_triplet'
27+
NUM_INSTANCE: 4
28+
NUM_WORKERS: 8
29+
30+
SOLVER:
31+
OPTIMIZER_NAME: 'SGD'
32+
MAX_EPOCHS: 120
33+
BASE_LR: 0.0008
34+
WARMUP_EPOCHS: 20
35+
IMS_PER_BATCH: 64
36+
WARMUP_METHOD: 'cosine'
37+
LARGE_FC_LR: False
38+
CHECKPOINT_PERIOD: 120
39+
LOG_PERIOD: 20
40+
EVAL_PERIOD: 10
41+
WEIGHT_DECAY: 1e-4
42+
WEIGHT_DECAY_BIAS: 1e-4
43+
BIAS_LR_FACTOR: 2
44+
45+
TEST:
46+
EVAL: True
47+
IMS_PER_BATCH: 256
48+
RE_RANKING: False
49+
WEIGHT: ''
50+
NECK_FEAT: 'before'
51+
FEAT_NORM: 'yes'
52+
53+
OUTPUT_DIR: './log/market1501/swin_small'

0 commit comments

Comments
 (0)