README.md 12.8 KB
Newer Older
André Araujo's avatar
André Araujo committed
1
# Deep Local and Global Image Features
Andre Araujo's avatar
Andre Araujo committed
2

3
[![TensorFlow 2.1](https://img.shields.io/badge/tensorflow-2.1-brightgreen)](https://github.com/tensorflow/tensorflow/releases/tag/v2.1.0)
4
[![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/)
5

6
7
8
9
10
11
12
This project presents code for deep local and global image feature methods,
which are particularly useful for the computer vision tasks of instance-level
recognition and retrieval. These were introduced in the
[DELF](https://arxiv.org/abs/1612.06321),
[Detect-to-Retrieve](https://arxiv.org/abs/1812.01584),
[DELG](https://arxiv.org/abs/2001.05027) and
[Google Landmarks Dataset v2](https://arxiv.org/abs/2004.01804) papers.
13

14
15
16
We provide Tensorflow code for building and training models, and python code for
image retrieval and local feature matching. Pre-trained models for the landmark
recognition domain are also provided.
Andre Araujo's avatar
Andre Araujo committed
17

18
If you make use of this codebase, please consider citing the following papers:
Andre Araujo's avatar
Andre Araujo committed
19

André Araujo's avatar
André Araujo committed
20
DELF:
21
22
[![Paper](http://img.shields.io/badge/paper-arXiv.1612.06321-B3181B.svg)](https://arxiv.org/abs/1612.06321)

Andre Araujo's avatar
Andre Araujo committed
23
24
```
"Large-Scale Image Retrieval with Attentive Deep Local Features",
25
H. Noh, A. Araujo, J. Sim, T. Weyand and B. Han,
Andre Araujo's avatar
Andre Araujo committed
26
27
28
Proc. ICCV'17
```

André Araujo's avatar
André Araujo committed
29
Detect-to-Retrieve:
30
31
[![Paper](http://img.shields.io/badge/paper-arXiv.1812.01584-B3181B.svg)](https://arxiv.org/abs/1812.01584)

32
33
34
35
36
37
```
"Detect-to-Retrieve: Efficient Regional Aggregation for Image Search",
M. Teichmann*, A. Araujo*, M. Zhu and J. Sim,
Proc. CVPR'19
```

André Araujo's avatar
André Araujo committed
38
39
40
41
42
43
44
45
46
DELG:
[![Paper](http://img.shields.io/badge/paper-arXiv.2001.05027-B3181B.svg)](https://arxiv.org/abs/2001.05027)

```
"Unifying Deep Local and Global Features for Image Search",
B. Cao*, A. Araujo* and J. Sim,
arxiv:2001.05027
```

47
48
49
50
51
52
53
54
55
GLDv2:
[![Paper](http://img.shields.io/badge/paper-arXiv.2004.01804-B3181B.svg)](https://arxiv.org/abs/2004.01804)

```
"Google Landmarks Dataset v2 - A Large-Scale Benchmark for Instance-Level Recognition and Retrieval",
T. Weyand*, A. Araujo*, B. Cao and J. Sim,
Proc. CVPR'20
```

Andre Araujo's avatar
Andre Araujo committed
56
57
## News

58
59
60
-   [Apr'20] Check out our CVPR'20 paper: ["Google Landmarks Dataset v2 - A
    Large-Scale Benchmark for Instance-Level Recognition and
    Retrieval"](https://arxiv.org/abs/2004.01804)
André Araujo's avatar
André Araujo committed
61
62
-   [Jan'20] Check out our new paper:
    ["Unifying Deep Local and Global Features for Image Search"](https://arxiv.org/abs/2001.05027)
63
64
65
66
-   [Jun'19] DELF achieved 2nd place in
    [CVPR Visual Localization challenge (Local Features track)](https://sites.google.com/corp/view/ltvl2019).
    See our slides
    [here](https://docs.google.com/presentation/d/e/2PACX-1vTswzoXelqFqI_pCEIVl2uazeyGr7aKNklWHQCX-CbQ7MB17gaycqIaDTguuUCRm6_lXHwCdrkP7n1x/pub?start=false&loop=false&delayms=3000).
67
68
69
70
71
72
-   [Apr'19] Check out our CVPR'19 paper:
    ["Detect-to-Retrieve: Efficient Regional Aggregation for Image Search"](https://arxiv.org/abs/1812.01584)
-   [Jun'18] DELF achieved state-of-the-art results in a CVPR'18 image retrieval
    paper: [Radenovic et al., "Revisiting Oxford and Paris: Large-Scale Image
    Retrieval Benchmarking"](https://arxiv.org/abs/1803.11285).
-   [Apr'18] DELF was featured in
Andre Araujo's avatar
Andre Araujo committed
73
    [ModelDepot](https://modeldepot.io/mikeshi/delf/overview)
74
-   [Mar'18] DELF is now available in
Andre Araujo's avatar
Andre Araujo committed
75
76
    [TF-Hub](https://www.tensorflow.org/hub/modules/google/delf/1)

77
## Datasets
Andre Araujo's avatar
Andre Araujo committed
78

79
80
81
82
83
84
85
86
87
88
We have two Google-Landmarks dataset versions:

-   Initial version (v1) can be found
    [here](https://www.kaggle.com/google/google-landmarks-dataset). In includes
    the Google Landmark Boxes which were described in the Detect-to-Retrieve
    paper.
-   Second version (v2) has been released as part of two Kaggle challenges:
    [Landmark Recognition](https://www.kaggle.com/c/landmark-recognition-2019)
    and [Landmark Retrieval](https://www.kaggle.com/c/landmark-retrieval-2019).
    It can be downloaded from CVDF
89
90
91
    [here](https://github.com/cvdfoundation/google-landmark). See also
    [the CVPR'20 paper](https://arxiv.org/abs/2004.01804) on this new dataset
    version.
92
93
94

If you make use of these datasets in your research, please consider citing the
papers mentioned above.
Andre Araujo's avatar
Andre Araujo committed
95

Andre Araujo's avatar
Andre Araujo committed
96
97
## Installation

98
99
100
101
102
To be able to use this code, please follow
[these instructions](INSTALL_INSTRUCTIONS.md) to properly install the DELF
library.

## Quick start
Andre Araujo's avatar
Andre Araujo committed
103

104
105
106
107
108
109
110
### Pre-trained models

We release several pre-trained models. See instructions in the following
sections for examples on how to use the models.

**DELF pre-trained on the Google-Landmarks dataset v1**
([link](http://storage.googleapis.com/delf/delf_gld_20190411.tar.gz)). Presented
111
112
113
114
115
116
117
118
119
120
in the [Detect-to-Retrieve paper](https://arxiv.org/abs/1812.01584). Boosts
performance by ~4% mAP compared to ICCV'17 DELF model.

**DELG pre-trained on the Google-Landmarks dataset v1**
([link](http://storage.googleapis.com/delf/delg_gld_20200520.tar.gz)). Presented
in the [DELG paper](https://arxiv.org/abs/2001.05027).

**RN101-ArcFace pre-trained on the Google-Landmarks dataset v2 (train-clean)**
([link](https://storage.googleapis.com/delf/rn101_af_gldv2clean_20200521.tar.gz)).
Presented in the [GLDv2 paper](https://arxiv.org/abs/2004.01804).
121
122
123

**DELF pre-trained on Landmarks-Clean/Landmarks-Full dataset**
([link](http://storage.googleapis.com/delf/delf_v1_20171026.tar.gz)). Presented
124
125
in the [DELF paper](https://arxiv.org/abs/1612.06321), model was trained on the
dataset released by the [DIR paper](https://arxiv.org/abs/1604.01325).
126
127
128

**Faster-RCNN detector pre-trained on Google Landmark Boxes**
([link](http://storage.googleapis.com/delf/d2r_frcnn_20190411.tar.gz)).
129
Presented in the [Detect-to-Retrieve paper](https://arxiv.org/abs/1812.01584).
130
131
132

**MobileNet-SSD detector pre-trained on Google Landmark Boxes**
([link](http://storage.googleapis.com/delf/d2r_mnetssd_20190411.tar.gz)).
133
Presented in the [Detect-to-Retrieve paper](https://arxiv.org/abs/1812.01584).
134

135
136
137
138
139
Besides these, we also release pre-trained codebooks for local feature
aggregation. See the
[Detect-to-Retrieve instructions](delf/python/detect_to_retrieve/DETECT_TO_RETRIEVE_INSTRUCTIONS.md)
for details.

140
### DELF extraction and matching
Andre Araujo's avatar
Andre Araujo committed
141
142
143
144

Please follow [these instructions](EXTRACTION_MATCHING.md). At the end, you
should obtain a nice figure showing local feature matches, as:

145
146
![MatchedImagesExample](delf/python/examples/matched_images_example.jpg)

147
148
149
150
### DELF training

Please follow [these instructions](delf/python/training/README.md).

André Araujo's avatar
André Araujo committed
151
152
153
154
155
156
### DELG

Please follow [these instructions](delf/python/delg/DELG_INSTRUCTIONS.md). At
the end, you should obtain image retrieval results on the Revisited Oxford/Paris
datasets.

157
158
159
160
161
162
163
### GLDv2 baseline

Please follow
[these instructions](delf/python/google_landmarks_dataset/README.md). At the
end, you should obtain image retrieval results on the Revisited Oxford/Paris
datasets.

164
165
166
167
168
169
### Landmark detection

Please follow [these instructions](DETECTION.md). At the end, you should obtain
a nice figure showing a detection, as:

![DetectionExample1](delf/python/examples/detection_example_1.jpg)
Andre Araujo's avatar
Andre Araujo committed
170

171
172
### Detect-to-Retrieve

173
174
175
176
Please follow
[these instructions](delf/python/detect_to_retrieve/DETECT_TO_RETRIEVE_INSTRUCTIONS.md).
At the end, you should obtain image retrieval results on the Revisited
Oxford/Paris datasets.
177

Andre Araujo's avatar
Andre Araujo committed
178
179
## Code overview

180
181
DELF/D2R/DELG/GLD code is located under the `delf` directory. There are two
directories therein, `protos` and `python`.
Andre Araujo's avatar
Andre Araujo committed
182
183
184

### `delf/protos`

185
This directory contains protobufs:
Andre Araujo's avatar
Andre Araujo committed
186

187
188
-   `aggregation_config.proto`: protobuf for configuring local feature
    aggregation.
189
-   `box.proto`: protobuf for serializing detected boxes.
Andre Araujo's avatar
Andre Araujo committed
190
-   `datum.proto`: general-purpose protobuf for serializing float tensors.
191
-   `delf_config.proto`: protobuf for configuring DELF/DELG extraction.
192
-   `feature.proto`: protobuf for serializing DELF features.
Andre Araujo's avatar
Andre Araujo committed
193
194
195
196
197

### `delf/python`

This directory contains files for several different purposes:

198
199
-   `box_io.py`, `datum_io.py`, `feature_io.py` are helper files for reading and
    writing tensors and features.
200
-   `delf_v1.py` contains code to create DELF models.
201
202
203
204
-   `feature_aggregation_extractor.py` contains a module to perform local
    feature aggregation.
-   `feature_aggregation_similarity.py` contains a module to perform similarity
    computation for aggregated local features.
Andre Araujo's avatar
Andre Araujo committed
205
206
207
208
209
210
-   `feature_extractor.py` contains the code to extract features using DELF.
    This is particularly useful for extracting features over multiple scales,
    with keypoint selection based on attention scores, and PCA/whitening
    post-processing.

The subdirectory `delf/python/examples` contains sample scripts to run DELF
211
feature extraction/matching, and object detection:
Andre Araujo's avatar
Andre Araujo committed
212

213
214
-   `delf_config_example.pbtxt` shows an example instantiation of the DelfConfig
    proto, used for DELF feature extraction.
215
-   `detector.py` is a module to construct an object detector function.
216
-   `extract_boxes.py` enables object detection from a list of images.
Andre Araujo's avatar
Andre Araujo committed
217
-   `extract_features.py` enables DELF extraction from a list of images.
218
-   `extractor.py` is a module to construct a DELF/DELG local feature extraction
219
    function.
Andre Araujo's avatar
Andre Araujo committed
220
221
-   `match_images.py` supports image matching using DELF features extracted
    using `extract_features.py`.
222

André Araujo's avatar
André Araujo committed
223
224
225
226
227
228
229
230
231
The subdirectory `delf/python/delg` contains sample scripts/configs related to
the DELG paper:

-   `delg_gld_config.pbtxt` gives the DelfConfig used in DELG paper.
-   `extract_features.py` for local+global feature extraction on Revisited
    datasets.
-   `perform_retrieval.py` for performing retrieval/evaluating methods on
    Revisited datasets.

232
233
234
The subdirectory `delf/python/detect_to_retrieve` contains sample
scripts/configs related to the Detect-to-Retrieve paper:

235
236
237
238
-   `aggregation_extraction.py` is a library to extract/save feature
    aggregation.
-   `boxes_and_features_extraction.py` is a library to extract/save boxes and
    DELF features.
239
240
241
-   `cluster_delf_features.py` for local feature clustering.
-   `dataset.py` for parsing/evaluating results on Revisited Oxford/Paris
    datasets.
242
243
-   `delf_gld_config.pbtxt` gives the DelfConfig used in Detect-to-Retrieve
    paper.
244
245
246
247
248
-   `extract_aggregation.py` for aggregated local feature extraction.
-   `extract_index_boxes_and_features.py` for index image local feature
    extraction / bounding box detection on Revisited datasets.
-   `extract_query_features.py` for query image local feature extraction on
    Revisited datasets.
249
250
-   `image_reranking.py` is a module to re-rank images with geometric
    verification.
251
252
253
254
255
-   `perform_retrieval.py` for performing retrieval/evaluating methods using
    aggregated local features on Revisited datasets.
-   `index_aggregation_config.pbtxt`, `query_aggregation_config.pbtxt` give
    AggregationConfig's for Detect-to-Retrieve experiments.

256
The subdirectory `delf/python/google_landmarks_dataset` contains sample
257
258
scripts/modules for computing GLD metrics / reproducing results from the GLDv2
paper:
259
260
261
262
263
264
265

-   `compute_recognition_metrics.py` performs recognition metric computation
    given input predictions and solution files.
-   `compute_retrieval_metrics.py` performs retrieval metric computation given
    input predictions and solution files.
-   `dataset_file_io.py` is a module for dataset-related file IO.
-   `metrics.py` is a module for GLD metric computation.
266
267
268
-   `rn101_af_gldv2clean_config.pbtxt` gives the DelfConfig used in the
    ResNet101-ArcFace (trained on GLDv2-train-clean) baseline used in the GLDv2
    paper.
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

The subdirectory `delf/python/training` contains sample scripts/modules for
performing DELF training:

-   `datasets/googlelandmarks.py` is the dataset module used for training.
-   `model/delf_model.py` is the model module used for training.
-   `model/export_model.py` is a script for exporting trained models in the
    format used by the inference code.
-   `model/export_model_utils.py` is a module with utilities for model
    exporting.
-   `model/resnet50.py` is a module with a backbone RN50 implementation.
-   `build_image_dataset.py` converts downloaded dataset into TFRecords format
    for training.
-   `train.py` is the main training script.

284
285
Besides these, other files in the different subdirectories contain tests for the
various modules.
Andre Araujo's avatar
Andre Araujo committed
286
287
288
289
290
291
292

## Maintainers

André Araujo (@andrefaraujo)

## Release history

293
294
295
296
297
298
299
300
### May, 2020

-   Codebase is now Python3-first
-   DELG model/code released
-   GLDv2 baseline model released

**Thanks to contributors**: Barbara Fusinska and André Araujo.

301
302
303
304
305
306
307
### April, 2020 (version 2.0)

-   Initial DELF training code released.
-   Codebase is now fully compatible with TF 2.1.

**Thanks to contributors**: Arun Mukundan, Yuewei Na and André Araujo.

308
309
### April, 2019

310
Detect-to-Retrieve code released.
311
312
313
314
315
316
317
318

Includes pre-trained models to detect landmark boxes, and DELF model pre-trained
on Google Landmarks v1 dataset.

**Thanks to contributors**: André Araujo, Marvin Teichmann, Menglong Zhu,
Jack Sim.

### October, 2017
Andre Araujo's avatar
Andre Araujo committed
319
320

Initial release containing DELF-v1 code, including feature extraction and
321
matching examples. Pre-trained DELF model from ICCV'17 paper is released.
Andre Araujo's avatar
Andre Araujo committed
322
323
324

**Thanks to contributors**: André Araujo, Hyeonwoo Noh, Youlong Cheng,
Jack Sim.