Esempio n. 1
0
    def __init__(self):
        super(IMIPS, self).__init__(name='IMIPS',
                                    is_detector=True,
                                    is_descriptor=False,
                                    is_both=False,
                                    patch_input=False)

        graph, sess = hyperparams.bootstrapFromCheckpoint()
        self.forward_passer = hyperparams.getForwardPasser(graph, sess)
Esempio n. 2
0
def evalImips():
    net, sess = hyperparams.bootstrapFromCheckpoint()
    fpasser = hyperparams.getForwardPasser(net, sess)
    times = []
    for pair in eval_set:
        t = time.time()
        fps = [fpasser(i) for i in pair.im]
        times.append(time.time() - t)
        print(times[-1])
    return times
Esempio n. 3
0
# imips_open is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# imips_open is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with imips_open. If not, see <http:#www.gnu.org/licenses/>.

import imips.evaluate as evaluate
import imips.flags as flags
import imips.hyperparams as hyperparams
import imips.system as system

FLAGS = flags.FLAGS

if __name__ == '__main__':
    print(hyperparams.methodEvalString())
    eval_pairs = hyperparams.getEvalSet()
    graph, sess = hyperparams.bootstrapFromCheckpoint()
    forward_passer = hyperparams.getForwardPasser(graph, sess)

    for pair in eval_pairs:
        fps = [forward_passer(im) for im in pair.im]
        fps = system.unifyForwardPasses(fps)
        evaluate.renderMatching(pair, fps)
Esempio n. 4
0
# imips_open is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with imips_open. If not, see <http:#www.gnu.org/licenses/>.

import cv2
import os

import imips.flags as flags
import imips.hyperparams as hyperparams

if __name__ == '__main__':
    seq = hyperparams.getEvalSequence()
    fpasser = hyperparams.getForwardPasser()

    save_path = os.path.join('results', 'render', hyperparams.methodString(),
                             seq.set_name, seq.seq_name)
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    i = 0
    for image in seq.images:
        fp = fpasser(cv2.imread(image, cv2.IMREAD_GRAYSCALE))
        bgr = fp.render()
        imname = os.path.basename(image)
        print('%d / %d' % (i, len(seq)))
        cv2.imwrite(os.path.join(save_path, '%05d.png' % i), bgr)
        i = i + 1
Esempio n. 5
0
import imips.hyperparams as hyperparams

FLAGS = flags.FLAGS


if __name__ == '__main__':
    assert FLAGS.tds == 'tm'
    assert FLAGS.baseline == 'sift'

    # Collect all (keyframe) descriptors
    dump_file = os.path.join('compress', 'tm_%s.hkl' % FLAGS.baseline)
    if not os.path.exists(dump_file):
        tms = [rpg_datasets_py.tum_mono.Sequence(i)
               for i in ['01', '02', '03', '48', '49', '50']]
        assert FLAGS.baseline_num_ips == 500
        fpasser = hyperparams.getForwardPasser(None, None)

        all_descs = []
        for tm in tms:
            kf_indices = getKeyFrames(tm, 0.5)
            print(tm.name())
            print('Frames reduced from %d to %d' % (len(tm), len(kf_indices)))
            for index in kf_indices:
                print('%d %d' % (index, kf_indices[-1]))
                image = cv2.imread(tm[index], cv2.IMREAD_GRAYSCALE)
                fp = fpasser(image)
                all_descs = all_descs + fp.descriptors.tolist()

        descs_array = np.array(all_descs)
        hkl.dump(descs_array, open(dump_file, 'w'))
    else:
Esempio n. 6
0
def run():
    print('\n\n%s\n\n' % hyperparams.shortString())

    tf.reset_default_graph()
    deploy_net = nets.Deploy2Net()
    train_net = nets.CorrespTrainNet()

    sess = tf.Session()

    train_set = hyperparams.getTrainSet()
    val_set = hyperparams.getEvalSet(train=True)
    tval_set = hyperparams.getTrainValidationSubset()
    fpasser = hyperparams.getForwardPasser(deploy_net, sess)

    def step_fun(sess):
        dp = train_set.getRandomDataPoint()
        if FLAGS.tds == 'hp' and (FLAGS.aug_ang > 0. or FLAGS.aug_sc > 0.):
            dp = augment.augmentHpatchPair(dp,
                                           ang_range=FLAGS.aug_ang,
                                           sc_range=FLAGS.aug_sc)

        fps = [fpasser(i) for i in dp.im]
        flat = system.unifyForwardPasses(fps)
        corr_rc, corr_valid_masks = system.getCorrespondences(dp, flat)

        for i in [0, 1]:
            if FLAGS.use_qn:
                raise NotImplementedError
                sess.run(train_net.train_step,
                         feed_dict={
                             train_net.ip_patches: ip_patches[i],
                             train_net.corr_patches: corr_patches[i],
                             train_net.is_inlier_label: inl[i],
                             train_net.is_outlier_label: outl[i],
                             train_net.qn_patches: qns[i],
                             train_net.qn_other_diff: qnd[i]
                         })
            else:
                if np.min(fps[i].ips_rc) == 0:
                    viz = plot_utils.tile(fps[i].image_scores, 16, 8, 4,
                                          fps[0].ips_rc)
                    cv2.imwrite('debug_out.png', viz)
                    raise Exception(
                        'Something went very wrong! See debug_out.png. '
                        'Consider restarting the training.')

                ip_patches, corr_patches, inl, outl = \
                    system.getTrainingBatchesImage(
                        dp.im[i], fps[i], corr_rc[i], corr_valid_masks[i])

                if FLAGS.render_train_samples:
                    evaluate.renderTrainSample(dp, fps, corr_rc, inl)

                sess.run(train_net.train_step,
                         feed_dict={
                             train_net.ip_patches: ip_patches,
                             train_net.corr_patches: corr_patches,
                             train_net.is_inlier_label: inl,
                             train_net.is_outlier_label: outl
                         })

    def val_fun(_):
        apparent, true, _, _, _ = evaluate.evaluatePairs(fpasser, val_set)
        app_tr, true_tr, _, _, _ = evaluate.evaluatePairs(fpasser, tval_set)
        return [apparent.mean(), true.mean(), app_tr.mean(), true_tr.mean()]

    trainer = Trainer(step_fun,
                      val_fun,
                      hyperparams.checkpointRoot(),
                      hyperparams.shortString(),
                      check_every=FLAGS.val_every,
                      best_index=1,
                      best_is_max=True)
    trainer.trainUpToNumIts(sess, FLAGS.its)