Skip to content

Commit

Permalink
store keypoint score for imw2020
Browse files Browse the repository at this point in the history
  • Loading branch information
lzx551402 committed Feb 15, 2020
1 parent b27953a commit d4e7ccc
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ then call:
cd /local/aslfeat && python image_matching.py --config configs/matching_eval.yaml
```

### 2. Benchmark on FMBench
### 2. Benchmark on FMBench

Download the data (validation/test) from [here](https://vision.uvic.ca/imw-challenge/index.md), then configure ``configs/imw2020_eval.yaml``, finally call:

```bash
cd /local/aslfeat && python evaluations.py --config configs/imw2020_eval.yaml
```
20 changes: 20 additions & 0 deletions configs/imw2020_eval.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
data_name: 'imw2020'
data_split: 'val' # val or test
data_root: '/local/data/phototourism'
dump_root: '/local/imw2020_val_aslfeat_2k'
truncate: [0, null]
model_path: 'pretrained/aslfeat/model.ckpt-380000'
overwrite: true
net:
max_dim: 2048
config:
kpt_n: 2048
kpt_refinement: true
deform_desc: 1
score_thld: 0.5
edge_thld: -1
multi_level: true
nms_size: 3
eof_mask: 5
need_norm: true
use_peakiness: true
7 changes: 6 additions & 1 deletion datasets/imw2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,21 @@ def _format_data(self, data):
seq_folder = os.path.join(self.config['dump_root'], seq_name)
h5_kpt = os.path.join(seq_folder, 'keypoints.h5')
h5_desc = os.path.join(seq_folder, 'descriptors.h5')
h5_score = os.path.join(seq_folder, 'scores.h5')

if not os.path.exists(h5_desc) and not os.path.exists(h5_kpt):
if not os.path.exists(h5_desc) and not os.path.exists(h5_kpt) and not os.path.exists(h5_score):
gen_kpt_f = h5py.File(h5_kpt, 'w')
gen_desc_f = h5py.File(h5_desc, 'w')
gen_score_f = h5py.File(h5_score, 'w')
else:
gen_kpt_f = h5py.File(h5_kpt, 'a')
gen_desc_f = h5py.File(h5_desc, 'a')
gen_score_f = h5py.File(h5_score, 'a')

if basename not in gen_kpt_f and basename not in gen_desc_f:
feat = data['dump_data'][0]
kpt = data['dump_data'][1]
score = data['dump_data'][2]
_ = gen_kpt_f.create_dataset(basename, data=kpt, dtype='f')
_ = gen_desc_f.create_dataset(basename, data=feat, dtype='f')
_ = gen_score_f.create_dataset(basename, data=score, dtype='f')
4 changes: 2 additions & 2 deletions evaluations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def extract_feat(config):
try:
data = next(test_set)
if config['overwrite'] or not os.path.exists(data['dump_path']):
desc, kpt = model.run_test_data(data['image'])
desc, kpt, score = model.run_test_data(data['image'])
dump_data = {}
dump_data['dump_data'] = (desc, kpt)
dump_data['dump_data'] = (desc, kpt, score)
dump_data['image_path'] = data['image_path']
dump_data['dump_path'] = data['dump_path']
dataset.format_data(dump_data)
Expand Down
1 change: 1 addition & 0 deletions models/cnn_wrapper/aslfeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def setup(self):
det_kpt_coord = tf.stack(
[det_kpt_inds[:, :, 1], det_kpt_inds[:, :, 0]], axis=-1, name='kpt')
self.layers['kpt'] = det_kpt_coord
self.layers['score'] = tf.identity(det_kpt_score, name='score')

def our_score(self, inputs, ksize=3, all_softplus=True, need_norm=True, dilation=1, name='conv'):
if need_norm:
Expand Down
42 changes: 42 additions & 0 deletions models/feat_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys

import cv2
import numpy as np
import tensorflow as tf

from .base_model import BaseModel
from .cnn_wrapper.aslfeat import ASLFeatNet

sys.path.append('..')


class FeatModel(BaseModel):
output_tensors = ["desc:0", "kpt:0", "score:0"]
default_config = {'max_dim': 1280}

def _init_model(self):
return

def _run(self, data):
assert len(data.shape) == 3
max_dim = max(data.shape[0], data.shape[1])
downsample_ratio = 1
if max_dim > self.config['max_dim']:
downsample_ratio = self.config['max_dim'] / float(max_dim)
data = cv2.resize(data, (0, 0), fx=downsample_ratio, fy=downsample_ratio)
data = data[..., np.newaxis]
feed_dict = {"input:0": np.expand_dims(data, 0)}
returns = self.sess.run(self.output_tensors, feed_dict=feed_dict)
desc = np.squeeze(returns[0], axis=0)
kpt = np.squeeze(returns[1], axis=0)
kpt /= downsample_ratio
score = np.squeeze(returns[2], axis=0)
return desc, kpt, score

def _construct_network(self):
ph_imgs = tf.placeholder(dtype=tf.float32, shape=(None, None, None, 1), name='input')
mean, variance = tf.nn.moments(
tf.cast(ph_imgs, tf.float32), axes=[1, 2], keep_dims=True)
norm_input = tf.nn.batch_normalization(ph_imgs, mean, variance, None, None, 1e-5)
config_dict = {'det_config': self.config['config']}
tower = ASLFeatNet({'data': norm_input}, is_training=False, resue=False, **config_dict)

0 comments on commit d4e7ccc

Please sign in to comment.