You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+134-8Lines changed: 134 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,35 @@
2
2
3
3
Code for reproducing the results of our "In Defense of the Triplet Loss for Person Re-Identification" paper.
4
4
5
-
Both main authors are currently in an internship.
6
-
We will publish the full training code after our internships, which is end of September 2017.
7
-
(By "Watching" this project on github, you will receive e-mails about updates to this repo.)
8
-
Meanwhile, we provide the pre-trained weights for the TriNet model, as well as some rudimentary example code for using it to compute embeddings, see below.
5
+
We provide the following things:
6
+
- The exact pre-trained weights for the TriNet model as used in the paper, including some rudimentary example code for using it to compute embeddings.
7
+
See section [Pretrained models](#pretrained-models).
8
+
- A clean re-implementation of the training code that can be used for training your own models/data.
9
+
See section [Training your own models](#training-your-own-models).
10
+
- A script for evaluation which computes the CMC and mAP of embeddings in an HDF5 ("new .mat") file.
11
+
See section [Evaluating embeddings](#evaluating-embeddings).
9
12
10
-
# Pretrained Models
13
+
If you use any of the provided code, please cite:
14
+
```
15
+
@article{HermansBeyer2017Arxiv,
16
+
title = {{In Defense of the Triplet Loss for Person Re-Identification}},
17
+
author = {Hermans*, Alexander and Beyer*, Lucas and Leibe, Bastian},
18
+
journal = {arXiv preprint arXiv:1703.07737},
19
+
year = {2017}
20
+
}
21
+
```
22
+
23
+
24
+
# Pretrained models
11
25
12
-
This is a first, simple release. A better more generic script will follow in a few months, but this should be enough to get started trying out our models!
26
+
We provide the exact TriNet model used in the paper, which was implemented in
@@ -47,3 +63,113 @@ You can now do meaningful work by comparing these embeddings using the Euclidean
47
63
A couple notes:
48
64
- The script depends on [Theano](http://deeplearning.net/software/theano/install.html), [Lasagne](http://lasagne.readthedocs.io/en/latest/user/installation.html) and [OpenCV Python](http://opencv.org/) (`pip install opencv-python`) being correctly installed.
49
65
- The input files should be crops of a full person standing upright, and they will be resized to `288x144` before being passed to the network.
66
+
67
+
68
+
# Training your own models
69
+
70
+
If you want more flexibility, we now provide code for training your own models.
71
+
This is not the code that was used in the paper (which became a unusable mess),
72
+
but rather a clean re-implementation of it in [TensorFlow](https://www.tensorflow.org/),
73
+
achieving about the same performance.
74
+
75
+
-**This repository requires at least version 1.4 of TensorFlow.**
76
+
-**The TensorFlow code is Python 3 only and won't work in Python 2!**
77
+
78
+
## Defining a dataset
79
+
80
+
A dataset consists of two things:
81
+
82
+
1. An `image_root` folder which contains all images, possibly in sub-folders.
83
+
2. A dataset `.csv` file describing the dataset.
84
+
85
+
To create a dataset, you simply create a new `.csv` file for it of the following form:
86
+
87
+
```
88
+
identity,relative_path/to/image.jpg
89
+
```
90
+
91
+
Where the `identity` is also often called `PID` (`P`erson `ID`entity) and corresponds to the "class name",
92
+
it can be any arbitrary string, but should be the same for images belonging to the same identity.
93
+
94
+
The `relative_path/to/image.jpg` is relative to aforementioned `image_root`.
95
+
96
+
## Training
97
+
98
+
Given the dataset file, and the `image_root`, you can already train a model.
99
+
The minimal way of training a model is to just call `train.py` in the following way:
100
+
101
+
```
102
+
python train.py \
103
+
--train_set data/market1501_train.csv \
104
+
--image_root /absolute/image/root \
105
+
--experiment_root ~/experiments/my_experiment
106
+
```
107
+
108
+
This will start training with all default parameters.
109
+
We recommend writing a script file similar to `market1501_train.sh` where you define all kinds of parameters,
110
+
it is **highly recommended** you tune hyperparameters such as `net_input_{height,width}`, `learning_rate`,
111
+
`decay_start_iteration`, and many more.
112
+
See the top of `train.py` for a list of all parameters.
113
+
114
+
As a convenience, we store all the parameters that were used for a run in `experiment_root/args.json`.
115
+
116
+
### Pre-trained initialization
117
+
118
+
If you want to initialize the model using pre-trained weights, such as done for TriNet,
119
+
you need to specify the location of the checkpoint file through `--initial_checkpoint`.
120
+
121
+
For most common models, you can download the [checkpoints provided by Google here](https://github.com/tensorflow/models/tree/master/research/slim#pre-trained-models).
122
+
For example, that's where we get our ResNet50 pre-trained weights from,
123
+
and what you should pass as second parameter to `market1501_train.sh`.
124
+
125
+
## Interrupting and resuming training
126
+
127
+
Since training can take quite a while, interrupting and resuming training is important.
128
+
You can interrupt training at any time by hitting `Ctrl+C` or sending `SIGINT (2)` or `SIGTERM (15)`
129
+
to the training process; it will finish the current batch, store the model and optimizer state,
130
+
and then terminate cleanly.
131
+
Because of the `args.json` file, you can later resume that run simply by running:
0 commit comments