def run(): hyperparams.announceEval() eval_pairs = hyperparams.getEvalDataGen() graph, sess = hyperparams.modelFromCheckpoint() forward_passer = hyperparams.getForwardPasser(graph, sess) fp_cache = system.ForwardPassCache(forward_passer) for pair_i in range(len(eval_pairs)): print('%d/%d' % (pair_i, len(eval_pairs))) pair = eval_pairs[pair_i] print(pair.name()) fps = [fp_cache[im] for im in pair.im] assert len(fps[0]) == FLAGS.num_test_pts assert len(fps[1]) == FLAGS.num_test_pts matched_indices = system.match(fps) inliers = system.getInliers(pair, fps, matched_indices) matched_fps = [fps[i][matched_indices[i]] for i in [0, 1]] evaluate.renderMatching(pair, fps, matched_fps, inliers)
def plot(label=None, k=10): hyperparams.announceEval() eval_pairs = hyperparams.getEvalDataGen() # Very special case lfnet: if FLAGS.baseline == 'lfnet': x = [50, 100, 150] y = [] for num_pts in x: forward_pass_dict = baselines.parseLFNetOuts(eval_pairs, num_pts) success = np.zeros(len(eval_pairs), dtype=bool) for pair_i in range(len(eval_pairs)): pair = eval_pairs[pair_i] folder, a, b = pair.name().split(' ') forward_passes = [ forward_pass_dict['%s%s' % (folder, i)] for i in [a, b] ] matched_indices = system.match(forward_passes) inliers = system.getInliers(pair, forward_passes, matched_indices) if np.count_nonzero(inliers) >= k: success[pair_i] = True y.append(np.mean(success.astype(float))) plt.plot(x, y, 'x', label='%s: N/A' % (hyperparams.methodString())) else: pair_outs = cache_forward_pass.loadOrCalculateOuts() if FLAGS.num_scales > 1 and FLAGS.baseline == '': fps = [[multiscale.forwardPassFromHicklable(im) for im in pair] for pair in pair_outs] else: fps = [[system.forwardPassFromHicklable(im) for im in pair] for pair in pair_outs] pairs_fps = zip(eval_pairs, fps) stats = [ evaluate.leastNumForKInliers(pair_fps[0], pair_fps[1], k) for pair_fps in pairs_fps ] x, y = evaluate.lessThanCurve(stats) auc = evaluate.auc(x, y, 200) plt.step(x, y, label='%s: %.2f' % (hyperparams.label(), auc)) return auc
def step(sess): dp = train_pairs.getRandomDataPoint() if FLAGS.augment and FLAGS.tds == 'hp': dp = augment.augmentHpatchPair(dp) # Feedforward fps = [forward_passer(im) for im in dp.im] if type(fps[0]) == multiscale.ForwardPass: flat = [i.toFlatForwardPass() for i in fps] else: flat = fps matched_indices = system.match(flat) inliers = system.getInliers(dp, flat, matched_indices) print('%d inliers' % np.count_nonzero(inliers)) batch, inlier_labels = makeBatchAndInlierLabelsDouble( dp, fps, matched_indices, inliers) sess.run(g.train_step, feed_dict={ g.train_input: batch, g.inlier_mask: inlier_labels })
def plot(color=plt.get_cmap('tab10').colors[0]): n = FLAGS.num_test_pts hyperparams.announceEval() eval_pairs = hyperparams.getEvalDataGen() # Very special case lfnet: if FLAGS.baseline == 'lfnet': forward_pass_dict = baselines.parseLFNetOuts(eval_pairs, n) fps = [] for pair_i in range(len(eval_pairs)): pair = eval_pairs[pair_i] folder, a, b = pair.name().split(' ') forward_passes = [ forward_pass_dict['%s%s' % (folder, i)] for i in [a, b] ] matched_indices = system.match(forward_passes) fps.append([forward_passes[i][matched_indices[i]] for i in [0, 1]]) else: pair_outs = cache_forward_pass.loadOrCalculateOuts() if FLAGS.num_scales > 1 and FLAGS.baseline == '': raise NotImplementedError else: fps = [] full_fps = [] for pair in pair_outs: reduced = [ system.forwardPassFromHicklable(i).reducedTo(n) for i in pair ] full_fps.append(reduced) matched_indices = system.match(reduced) fps.append([reduced[i][matched_indices[i]] for i in [0, 1]]) pairs_fps = zip(eval_pairs, fps) masks_errs = [ evaluate.p3pMaskAndError(pair_fps[0], pair_fps[1]) for pair_fps in pairs_fps ] if FLAGS.baseline == '': for mask_e, pair_fps, full in zip(masks_errs, pairs_fps, full_fps): mask, rerr, terr = mask_e pair, fps = pair_fps evaluate.renderMatching(pair, full, fps, mask) ninl = np.array([np.count_nonzero(i[0]) for i in masks_errs]) rerrs = np.array([i[1] for i in masks_errs]) rerrs[ninl < 10] = np.inf terrs = np.array([i[2] for i in masks_errs]) terrs[ninl < 10] = np.inf if FLAGS.baseline != 'sift': rlabel, tlabel = hyperparams.label(), None else: rlabel, tlabel = '%s, rot.' % hyperparams.label(), \ '%s, transl.' % hyperparams.label() x, y = evaluate.lessThanCurve(rerrs) plt.semilogx(x, y, '--', color=color, label=rlabel) x, y = evaluate.lessThanCurve(terrs) plt.semilogx(x, y, ':', color=color, label=tlabel)
# # You should have received a copy of the GNU General Public License # along with sips2_open. If not, see <http:#www.gnu.org/licenses/>. import numpy as np import sips2.flags as flags import sips2.hyperparams as hyperparams import sips2.system as system FLAGS = flags.FLAGS if __name__ == '__main__': hyperparams.announceEval() eval_pairs = hyperparams.getEvalDataGen() graph, sess = hyperparams.modelFromCheckpoint() forward_passer = hyperparams.getForwardPasser(graph, sess) score_wasinlier = [] for pair in eval_pairs: fps = [forward_passer(im) for im in pair.im] matched_indices = system.match(fps) inlier_mask = system.getInliers(pair, fps, matched_indices) for im_i in [0, 1]: im = pair.im[im_i] inlier_indices = matched_indices[im_i][inlier_mask] scores = fps[im_i].ip_scores for pt_i in range(len(scores)): score_wasinlier.append([scores[pt_i], pt_i in inlier_indices]) np.savetxt(hyperparams.wasInlierFilePath(), np.array(score_wasinlier))