-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Docs] add reid training README.md (#210)
* [Docs] add reid training readme * fix some bug * fix a bug * change basedataset
- Loading branch information
1 parent
df67e78
commit 11d2a1c
Showing
3 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Training a ReID Model | ||
|
||
You may want to train a ReID model for multiple object tracking or other applications. We support ReID model training in MMTracking, which is built upon [MMClassification](https://github.com/open-mmlab/mmclassification). | ||
|
||
## 1.Standard Dataset | ||
|
||
This section will show how to train a ReID model on standard datasets i.e. MOT17. | ||
|
||
### Dataset Preparation | ||
|
||
We need to download datasets following [here](https://github.com/open-mmlab/mmtracking/blob/master/docs/dataset.md). We use [ReIDDataset](https://github.com/open-mmlab/mmtracking/blob/master/mmtrack/datasets/reid_dataset.py) inherited from [BaseDataset](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/datasets/base_dataset.py) to maintain standard datasets. In this case, you need to convert the official dataset to this style. We provide scripts and the usages as follow: | ||
|
||
```python | ||
python ./tools/convert_datasets/mot2reid.py -i ./data/MOT17/ -o ./data/MOT17/reid --val-split 0.2 --vis-threshold 0.3 | ||
``` | ||
|
||
Arguments: | ||
|
||
- `--val-split`: Proportion of the validation dataset to the whole ReID dataset. | ||
- `--vis-threshold`: Threshold of visibility for each person. | ||
|
||
The directory of the converted datasets is as follows: | ||
|
||
``` | ||
MOT17 | ||
├── train | ||
├── test | ||
├── reid | ||
│ ├── imgs | ||
│ │ ├── MOT17-02-FRCNN_000002 | ||
│ │ │ ├── 000000.jpg | ||
│ │ │ ├── 000001.jpg | ||
│ │ │ ├── ... | ||
│ │ ├── MOT17-02-FRCNN_000003 | ||
│ │ │ ├── 000000.jpg | ||
│ │ │ ├── 000001.jpg | ||
│ │ │ ├── ... | ||
│ ├── meta | ||
│ │ ├── train_80.txt | ||
│ │ ├── val_20.txt | ||
``` | ||
|
||
Note: `80` in `train_80.txt` means the proportion of the training dataset to the whole ReID dataset is eighty percent. While the proportion of the validation dataset is twenty percent. | ||
|
||
For training, we provide a annotation list `train_80.txt`. Each line of the list contrains a filename and its corresponding ground-truth labels. The format is as follows: | ||
|
||
``` | ||
MOT17-05-FRCNN_000110/000018.jpg 0 | ||
MOT17-13-FRCNN_000146/000014.jpg 1 | ||
MOT17-05-FRCNN_000088/000004.jpg 2 | ||
MOT17-02-FRCNN_000009/000081.jpg 3 | ||
``` | ||
|
||
For validation, The annotation list `val_20.txt` remains the same as format above. | ||
|
||
Note: Images in `MOT17/reid/imgs` are cropped from raw images in `MOT17/train` by the corresponding `gt.txt`. The value of ground-truth labels should fall in range `[0, num_classes - 1]`. | ||
|
||
### Training | ||
|
||
#### Training on a single GPU | ||
|
||
```shell | ||
python tools/train.py configs/reid/resnet50_b32*8_MOT17.py [optional arguments] | ||
``` | ||
|
||
During training, log files and checkpoints will be saved to the working directory, which is specified by `work_dir` in the config file or via CLI argument `--work-dir`. | ||
|
||
#### Training on multiple GPUs | ||
|
||
We provide `tools/dist_train.sh` to launch training on multiple GPUs. | ||
The basic usage is as follows. | ||
|
||
```shell | ||
bash ./tools/dist_train.sh \ | ||
configs/reid/resnet50_b32*8_MOT17.py \ | ||
${GPU_NUM} \ | ||
[optional arguments] | ||
``` | ||
|
||
Optional arguments remain the same as stated above. | ||
|
||
For more training details, please refer to [here](https://github.com/open-mmlab/mmtracking/blob/master/docs/quick_run.md). | ||
|
||
## 2.Customize Dataset | ||
|
||
This section will show how to train a ReID model on customize datasets. | ||
|
||
### Dataset Preparation | ||
|
||
You need to convert your customize datasets to existing dataset format. | ||
|
||
#### An example of customized dataset | ||
|
||
Assume we are going to implement a `Filelist` dataset, which takes filelists for both training and testing. The directory of the dataset is as follows: | ||
|
||
``` | ||
Filelist | ||
├── imgs | ||
│ ├── person1 | ||
│ │ ├── 000000.jpg | ||
│ │ ├── 000001.jpg | ||
│ │ ├── ... | ||
│ ├── person2 | ||
│ │ ├── 000000.jpg | ||
│ │ ├── 000001.jpg | ||
│ │ ├── ... | ||
├── meta | ||
│ ├── train.txt | ||
│ ├── val.txt | ||
``` | ||
|
||
The format of annotation list is as follows: | ||
|
||
``` | ||
person1/000000.jpg 0 | ||
person1/000001.jpg 0 | ||
person2/000000.jpg 1 | ||
person2/000001.jpg 1 | ||
``` | ||
|
||
You can directly use [ReIDDataset](https://github.com/open-mmlab/mmtracking/blob/master/mmtrack/datasets/reid_dataset.py). In this case, you only need to modify the config as follows: | ||
|
||
```python | ||
# modify the path of annotation files and the image path prefix | ||
data = dict( | ||
train=dict( | ||
data_prefix='data/Filelist/imgs', | ||
ann_file='data/Filelist/meta/train.txt'), | ||
val=dict( | ||
data_prefix='data/Filelist/imgs', | ||
ann_file='data/Filelist/meta/val.txt'), | ||
test=dict( | ||
data_prefix='data/Filelist/imgs', | ||
ann_file='data/Filelist/meta/val.txt'), | ||
) | ||
# modify the number of classes, assume your training set has 100 classes | ||
model = dict(reid=dict(head=dict(num_classes=100))) | ||
``` | ||
|
||
You also can write a new Dataset class inherited from `BaseDataset`, and overwrite `load_annotations(self)`. For more details, you can follow [here](https://github.com/open-mmlab/mmclassification/blob/master/docs/tutorials/new_dataset.md). | ||
|
||
### Training | ||
|
||
The training stage is the same as `Standard Dataset`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters