Пример #1
0
    def test_stopwatch_full_cancel(self):
        """Test that an entire span - from root to children, can be cancelled."""

        sw = StopWatch()

        sw.start('root')
        sw.start('child')
        sw.start('grand')
        sw.cancel('grand')
        sw.cancel('child')
        sw.cancel('root')

        assert not sw.get_last_aggregated_report()
        assert not sw._cancelled_spans

        sw = StopWatch()
        with sw.timer('root'):
            with sw.timer('child'):
                with sw.timer('grandchild'):
                    sw.cancel('grandchild')
                    sw.cancel('child')
                    sw.cancel('root')

        assert not sw.get_last_aggregated_report()
        assert not sw._cancelled_spans
Пример #2
0
def sum_primes_up_to_N(N):
    from stopwatch import StopWatch
    StopWatch.start()
    _generator = Prime()
    _primes = _generator.get_primes(N)
    print sum(_primes)
    StopWatch.print_time()
Пример #3
0
def get_Nth_prime(N):
    from stopwatch import StopWatch
    StopWatch.start()
    _generator = Prime()
    _primes = _generator.get_first_N_primes(N)
    print _primes[N-1]
    StopWatch.print_time()
Пример #4
0
def howLongToCountNumbers(startNum, endNum):
	stopwatch = StopWatch(time.time())
	stopwatch.start()
	sum = 0
	for i in range(startNum, endNum):
		sum += i
	stopwatch.stop()
	print(stopwatch.getElapsedTime())
Пример #5
0
 def test_stopwatch_cancel(self):
     """Test that spans can be correctly cancelled and not reported."""
     sw = StopWatch()
     sw.start('root')
     sw.start('child')
     sw.cancel('child')
     sw.end('root')
     agg_values = sw.get_last_aggregated_report().aggregated_values
     assert len(agg_values) == 1
     assert 'root' in agg_values
Пример #6
0
def check_up_to_N(N):
    from stopwatch import StopWatch
    StopWatch.start()
    _checker = Prime()
    #_checker.get_primes(N)
    for i in range(N):
        if i % 10000 == 0: print i
        if _checker.is_prime(i):
            if N < 10000:
                print i, 
    print ""
    StopWatch.print_time()    
Пример #7
0
class BitRate:
    def __init__(self):
        self._stopwatch = StopWatch()
        self._totBytes = 0
        self._numFrames = 0
        self._bitrate = 0.0

    def update(self, bytecnt):
        self._numFrames += 1
        self._totBytes += bytecnt

    # Returns bitrate in MBit/sec
    def get(self):
        if self._numFrames > 10:
            totTime = self._stopwatch.stop()
            self._bitrate = (8 * self._totBytes / totTime) / 1.0e6

            self._numFrames = 0
            self._totBytes = 0
            self._stopwatch.start()

        return self._bitrate
Пример #8
0
def main():
    s = StopWatch()
    s.start()
    import compute_pi
    s.stop()
    print("Elapsed time:", round(s.time(), 2), "seconds")
Пример #9
0
class App:
    def __init__(self, window, window_title, video_source=0, master=None):
        self.window = window
        self.window.title(window_title)
        self.video_source = video_source
        self.ok = False
        self.master = master

        #timer
        self.timer = StopWatch(self.window)

        # open video source (by default this will try to open the computer webcam)
        self.vid = VideoCapture(self.video_source)

        # Create a canvas that can fit the above video source size
        self.canvas = tk.Canvas(window,
                                width=self.vid.width,
                                height=self.vid.height)
        self.canvas.pack()

        # --------------------------------------------------------------------------------
        # fm = tk.Frame(master)

        #video control buttons

        self.img1 = tk.PhotoImage(file="stop.png")
        self.btn_stop = tk.Button(self.window,
                                  image=self.img1,
                                  padx=3,
                                  pady=2,
                                  activebackground='#979797',
                                  command=self.close_camera)
        self.btn_stop["border"] = "0"
        self.btn_stop.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.YES)
        self.img = tk.PhotoImage(file="start.png")
        self.btn_start = tk.Button(self.window,
                                   image=self.img,
                                   padx=3,
                                   pady=2,
                                   activebackground='#979797',
                                   command=self.open_camera)
        self.btn_start["border"] = "0"
        self.btn_start.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.YES)

        # Button that lets the user take a snapshot
        self.img2 = tk.PhotoImage(file="snap.png")
        self.btn_snapshot = tk.Button(self.window,
                                      image=self.img2,
                                      padx=3,
                                      pady=2,
                                      activebackground='#979797',
                                      command=self.snapshot)
        self.btn_snapshot["border"] = "0"
        self.btn_snapshot.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.YES)

        # Button t

        # quit button
        self.img3 = tk.PhotoImage(file="exit.png")
        self.btn_quit = tk.Button(self.window,
                                  text='QUIT',
                                  image=self.img3,
                                  padx=3,
                                  pady=2,
                                  activebackground='#979797',
                                  command=self.quit)
        self.btn_quit["border"] = "0"
        self.btn_quit.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.YES)

        # After it is called once, the update method will be automatically called every delay milliseconds
        self.delay = 10
        self.update()
        self.window.resizable(0, 0)
        self.window.mainloop()

    def snapshot(self):
        # Get a frame from the video source
        ret, frame = self.vid.get_frame()

        if ret:
            cv2.imwrite("IMG-" + time.strftime("%d-%m-%Y-%H-%M-%S") + ".jpg",
                        cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))

    def open_camera(self):
        self.ok = True
        self.timer.start()
        print("camera opened => Recording")

    def close_camera(self):
        self.ok = False
        self.timer.stop()
        print("camera closed => Not Recording")

    def update(self):

        # Get a frame from the video source
        ret, frame = self.vid.get_frame()

        if ret:
            self.photo = PIL.ImageTk.PhotoImage(
                image=PIL.Image.fromarray(frame))
            self.canvas.create_image(0, 0, image=self.photo, anchor=tk.NW)

            self.window.after(self.delay, self.update)

    def quit(self):
        self.window.destroy()
Пример #10
0
    def ensemble_models_id(self,
                           single_id,
                           set_type='train',
                           model='stage1_unet',
                           show=True,
                           verbose=True):
        self._load_ensembles(model)
        d = self._get_cell_data(single_id, set_type)
        logger.debug('image size=%dx%d' % (d.img_h, d.img_w))

        total_model_size = len(self.ensembles['rcnn']) + len(
            self.ensembles['unet'])
        logger.debug('total_model_size=%d rcnn=%d unet=%d' %
                     (total_model_size, len(
                         self.ensembles['rcnn']), len(self.ensembles['unet'])))

        rcnn_instances = []
        rcnn_scores = []

        # TODO : RCNN Ensemble
        rcnn_ensemble = False
        for idx, data in enumerate(self.ensembles['rcnn']):
            if set_type == 'train':
                instances, scores = data['valid_instances'].get(
                    single_id, (None, None))
                rcnn_ensemble = True
            else:
                # TODO
                ls = data['test_instances'].get(single_id, None)
                if ls is None:
                    instances = scores = None
                else:
                    instances = [x[0] for x in ls]
                    scores = [x[1] for x in ls]
                    rcnn_ensemble = True
                    logger.debug('rcnn # instances = %d' % len(instances))

            if instances is None:
                logger.warning('Not found id=%s in RCNN %d Model' %
                               (single_id, idx + 1))
                continue

            rcnn_instances.extend(
                [instance[:d.img_h, :d.img_w] for instance in instances])
            rcnn_scores.extend([
                s * HyperParams.get().rcnn_score_rescale for s in scores
            ])  # rescale scores

        total_instances = []
        total_scores = []

        # TODO : UNet Ensemble
        for idx, data in enumerate(self.ensembles['unet']):
            if set_type == 'train':
                instances, scores = data['valid_instances'].get(
                    single_id, (None, None))
            else:
                instances, scores = data['test_instances'].get(
                    single_id, (None, None))

            if instances is None:
                logger.warning('Not found id=%s in UNet %d Model' %
                               (single_id, idx + 1))
                continue

            total_instances.extend(instances)
            total_scores.extend(scores)

            # if single_id in ['646f5e00a2db3add97fb80a83ef3c07edd1b17b1b0d47c2bd650cdcab9f322c0']:
            # take too long
            #     logger.warning('no ensemble id=%s' % single_id)
            #     break

        watch = StopWatch()
        watch.start()
        logger.debug('voting+ size=%d' % len(total_instances))

        # TODO : Voting?
        voting_th = HyperParams.get().ensemble_voting_th

        rects = [get_rect_of_mask(a) for a in total_instances]
        voted = []
        for i, x in enumerate(total_instances):
            voted.append(
                filter_by_voting(
                    (x, total_instances, voting_th, 0.3, rects[i], rects)))

        total_instances = list(compress(total_instances, voted))
        total_scores = list(compress(total_scores, voted))

        watch.stop()
        logger.debug('voting elapsed=%.5f' % watch.get_elapsed())
        watch.reset()

        # nms
        watch.start()
        logger.debug('nms+ size=%d' % len(total_instances))
        instances, scores = Network.nms(
            total_instances,
            total_scores,
            None,
            thresh=HyperParams.get().ensemble_nms_iou)
        watch.stop()
        logger.debug('nms elapsed=%.5f' % watch.get_elapsed())
        watch.reset()

        # high threshold if not exists in RCNN
        if rcnn_ensemble:
            voted = []
            for i, x in enumerate(instances):
                voted.append(
                    filter_by_voting((x, rcnn_instances, 1, 0.3, None, None)))

            new_instances = []
            new_scores = []
            for instance, score, v in zip(instances, scores, voted):
                if v:
                    new_instances.append(instance)
                    new_scores.append(score)
                elif score > HyperParams.get().ensemble_th_no_rcnn:
                    new_instances.append(instance)
                    new_scores.append(score)
            instances, scores = new_instances, new_scores

        # nms with rcnn
        instances = instances + rcnn_instances
        scores = scores + rcnn_scores
        watch.start()
        logger.debug('nms_rcnn+ size=%d' % len(instances))
        instances, scores = Network.nms(
            instances, scores, None, thresh=HyperParams.get().ensemble_nms_iou)
        watch.stop()
        logger.debug('nms_rcnn- size=%d elapsed=%.5f' %
                     (len(instances), watch.get_elapsed()))
        watch.reset()

        # remove overlaps
        logger.debug('remove overlaps+')
        sorted_idx = [
            i[0] for i in sorted(enumerate(instances),
                                 key=lambda x: get_size_of_mask(x[1]),
                                 reverse=False)
        ]
        instances = [instances[x] for x in sorted_idx]
        scores = [scores[x] for x in sorted_idx]

        instances2 = [
            ndimage.morphology.binary_fill_holes(i) for i in instances
        ]
        instances2, scores2 = Network.remove_overlaps(instances2, scores)

        # remove deleted instances
        logger.debug('remove deleted+ size=%d' % len(instances2))
        voted = []
        for x in instances2:
            voted.append(filter_by_voting((x, instances, 1, 0.75, None, None)))
        instances = list(compress(instances2, voted))
        scores = list(compress(scores2, voted))

        # TODO : Filter by score?
        logger.debug('filter by score+ size=%d' % len(instances))
        score_filter_th = HyperParams.get().ensemble_score_th
        if score_filter_th > 0.0:
            logger.debug('filter_by_score=%.3f' % score_filter_th)
            instances = [
                i for i, s in zip(instances, scores) if s > score_filter_th
            ]
            scores = [
                s for i, s in zip(instances, scores) if s > score_filter_th
            ]

        logger.debug('finishing+ size=%d' % len(instances))
        image = d.image(is_gray=False)
        score_desc = []
        labels = []
        if len(d.masks) > 0:  # has label masks
            labels = list(d.multi_masks(transpose=False))
            tp, fp, fn = get_multiple_metric(thr_list, instances, labels)

            logger.debug('instances=%d, labels=%d' %
                         (len(instances), len(labels)))
            for i, thr in enumerate(thr_list):
                desc = 'score=%.3f, tp=%d, fp=%d, fn=%d --- iou %.2f' % (
                    (tp / (tp + fp + fn))[i], tp[i], fp[i], fn[i], thr)
                logger.debug(desc)
                score_desc.append(desc)
            score = np.mean(tp / (tp + fp + fn))
            logger.debug('score=%.3f, tp=%.1f, fp=%.1f, fn=%.1f --- mean' %
                         (score, np.mean(tp), np.mean(fp), np.mean(fn)))
        else:
            score = 0.0

        if show:
            img_vis = Network.visualize(image, labels, instances, None)
            cv2.imshow('valid', img_vis)
            cv2.waitKey(0)
        else:
            return {
                'instance_scores': scores,
                'score': score,
                'image': image,
                'instances': instances,
                'labels': labels,
                'score_desc': score_desc
            }
Пример #11
0
    def single_id(self,
                  model,
                  checkpoint,
                  single_id,
                  set_type='train',
                  show=True,
                  verbose=True):
        if model:
            self.set_network(model)
            self.network.build()

        self.init_session()
        if checkpoint:
            saver = tf.train.Saver()
            saver.restore(self.sess, checkpoint)
            if verbose:
                logger.info('restored from checkpoint, %s' % checkpoint)

        d = self._get_cell_data(single_id, set_type)
        h, w = d.img.shape[:2]
        shortedge = min(h, w)
        logger.debug('%s image size=(%d x %d)' % (single_id, w, h))

        watch = StopWatch()
        logger.debug('preprocess+')
        d = self.network.preprocess(d)

        image = d.image(is_gray=False)

        total_instances = []
        total_scores = []
        total_from_set = []
        cutoff_instance_max = HyperParams.get().post_cutoff_max_th
        cutoff_instance_avg = HyperParams.get().post_cutoff_avg_th

        watch.start()
        logger.debug('inference at default scale+ %dx%d' % (w, h))
        inference_result = self.network.inference(
            self.sess,
            image,
            cutoff_instance_max=cutoff_instance_max,
            cutoff_instance_avg=cutoff_instance_avg)
        instances_pre, scores_pre = inference_result[
            'instances'], inference_result['scores']
        instances_pre = Network.resize_instances(instances_pre,
                                                 target_size=(h, w))
        total_instances = total_instances + instances_pre
        total_scores = total_scores + scores_pre
        total_from_set = [1] * len(instances_pre)
        watch.stop()
        logger.debug('inference- elapsed=%.5f' % watch.get_elapsed())
        watch.reset()

        logger.debug('inference with flips+')
        # re-inference using flip
        for flip_orientation in range(2):
            flipped = cv2.flip(image.copy(), flip_orientation)
            inference_result = self.network.inference(
                self.sess,
                flipped,
                cutoff_instance_max=cutoff_instance_max,
                cutoff_instance_avg=cutoff_instance_avg)
            instances_flip, scores_flip = inference_result[
                'instances'], inference_result['scores']
            instances_flip = [
                cv2.flip(instance.astype(np.uint8), flip_orientation)
                for instance in instances_flip
            ]
            instances_flip = Network.resize_instances(instances_flip,
                                                      target_size=(h, w))

            total_instances = total_instances + instances_flip
            total_scores = total_scores + scores_flip
            total_from_set = total_from_set + [2 + flip_orientation
                                               ] * len(instances_flip)

        watch.stop()
        logger.debug('inference- elapsed=%.5f' % watch.get_elapsed())
        watch.reset()
        logger.debug('inference with scaling+flips+')

        # re-inference after rescale image
        def inference_with_scale(image, resize_target):
            image = cv2.resize(image.copy(),
                               None,
                               None,
                               resize_target,
                               resize_target,
                               interpolation=cv2.INTER_AREA)
            inference_result = self.network.inference(
                self.sess,
                image,
                cutoff_instance_max=cutoff_instance_max,
                cutoff_instance_avg=cutoff_instance_avg)
            instances_rescale, scores_rescale = inference_result[
                'instances'], inference_result['scores']

            instances_rescale = Network.resize_instances(instances_rescale,
                                                         target_size=(h, w))
            return instances_rescale, scores_rescale

        max_mask = get_max_size_of_masks(instances_pre)
        logger.debug('max_mask=%d' % max_mask)
        resize_target = HyperParams.get().test_aug_scale_t / max_mask
        resize_target = min(HyperParams.get().test_aug_scale_max,
                            resize_target)
        resize_target = max(HyperParams.get().test_aug_scale_min,
                            resize_target)
        import math
        # resize_target = 2.0 / (1.0 + math.exp(-1.5*(resize_target - 1.0)))
        # resize_target = max(0.5, resize_target)
        resize_target = max(228.0 / shortedge, resize_target)
        # if resize_target > 1.0 and min(w, h) > 1000:
        #     logger.debug('too large image, no resize')
        #     resize_target = 0.8
        logger.debug('resize_target=%.4f' % resize_target)

        instances_rescale, scores_rescale = inference_with_scale(
            image, resize_target)
        total_instances = total_instances + instances_rescale
        total_scores = total_scores + scores_rescale
        total_from_set = total_from_set + [4] * len(instances_rescale)

        # re-inference using flip + rescale
        for flip_orientation in range(2):
            flipped = cv2.flip(image.copy(), flip_orientation)
            instances_flip, scores_flip = inference_with_scale(
                flipped, resize_target)
            instances_flip = [
                cv2.flip(instance.astype(np.uint8), flip_orientation)
                for instance in instances_flip
            ]
            instances_flip = Network.resize_instances(instances_flip,
                                                      target_size=(h, w))

            total_instances = total_instances + instances_flip
            total_scores = total_scores + scores_flip
            total_from_set = total_from_set + [5 + flip_orientation
                                               ] * len(instances_flip)

        watch.stop()
        logger.debug('inference- elapsed=%.5f' % watch.get_elapsed())
        watch.reset()

        watch.start()
        logger.debug('voting+ size=%d' % len(total_instances))

        # TODO : Voting?
        voting_th = HyperParams.get().post_voting_th
        rects = [get_rect_of_mask(a) for a in total_instances]
        voted = []
        for i, x in enumerate(total_instances):
            voted.append(
                filter_by_voting(
                    (x, total_instances, voting_th, 0.3, rects[i], rects)))

        total_instances = list(compress(total_instances, voted))
        total_scores = list(compress(total_scores, voted))
        total_from_set = list(compress(total_from_set, voted))

        watch.stop()
        logger.debug('voting elapsed=%.5f' % watch.get_elapsed())
        watch.reset()

        # nms
        watch.start()
        logger.debug('nms+ size=%d' % len(total_instances))
        instances, scores = Network.nms(
            total_instances,
            total_scores,
            total_from_set,
            thresh=HyperParams.get().test_aug_nms_iou)
        watch.stop()
        logger.debug('nms elapsed=%.5f' % watch.get_elapsed())
        watch.reset()

        # remove overlaps
        logger.debug('remove overlaps+')
        sorted_idx = [
            i[0] for i in sorted(enumerate(instances),
                                 key=lambda x: get_size_of_mask(x[1]),
                                 reverse=True)
        ]
        instances = [instances[x] for x in sorted_idx]
        scores = [scores[x] for x in sorted_idx]

        instances = [
            ndimage.morphology.binary_fill_holes(i) for i in instances
        ]
        instances, scores = Network.remove_overlaps(instances, scores)

        # TODO : Filter by score?
        # logger.debug('filter by score+')
        # score_filter_th = HyperParams.get().post_filter_th
        # if score_filter_th > 0.0:
        #     logger.debug('filter_by_score=%.3f' % score_filter_th)
        #     instances = [i for i, s in zip(instances, scores) if s > score_filter_th]
        #     scores = [s for i, s in zip(instances, scores) if s > score_filter_th]

        logger.debug('finishing+')
        image = cv2.resize(image, (w, h), interpolation=cv2.INTER_AREA)
        score_desc = []
        labels = []
        if len(d.masks) > 0:  # has label masks
            labels = list(d.multi_masks(transpose=False))
            labels = Network.resize_instances(labels, target_size=(h, w))
            tp, fp, fn = get_multiple_metric(thr_list, instances, labels)

            if verbose:
                logger.info('instances=%d, reinf(%.3f) labels=%d' %
                            (len(instances), resize_target, len(labels)))
            for i, thr in enumerate(thr_list):
                desc = 'score=%.3f, tp=%d, fp=%d, fn=%d --- iou %.2f' % (
                    (tp / (tp + fp + fn))[i], tp[i], fp[i], fn[i], thr)
                if verbose:
                    logger.info(desc)
                score_desc.append(desc)
            score = np.mean(tp / (tp + fp + fn))
            if verbose:
                logger.info('score=%.3f, tp=%.1f, fp=%.1f, fn=%.1f --- mean' %
                            (score, np.mean(tp), np.mean(fp), np.mean(fn)))
        else:
            score = 0.0

        if show:
            img_vis = Network.visualize(image, labels, instances, None)
            cv2.imshow('valid', img_vis)
            cv2.waitKey(0)
        if not model:
            return {
                'instance_scores': scores,
                'score': score,
                'image': image,
                'instances': instances,
                'labels': labels,
                'score_desc': score_desc
            }
Пример #12
0
from stopwatch import StopWatch

# creation of stopwatch class object
clock = StopWatch()

# use of clock method start
clock.start()
sum = 0
# Random loop to test how long it takes computer to complete
for i in range(1,1000001):
    sum+=i
# use of clock method stop
clock.stop()
# use of clock method getElapsedTime to display how long between the two events
print("The amount of time for the calculation to run is",clock.getElapsedTime(), "milliseconds")
Пример #13
0
#import psyco; psyco.full()
from math import sqrt, ceil

def sieveOfEratosthenes(n):
    """sieveOfEratosthenes(n): return the list of the primes < n."""
    # Code from: <*****@*****.**>, Nov 30 2006
    # http://groups.google.com/group/comp.lang.python/msg/f1f10ced88c68c2d
    if n <= 2:
        return []
    sieve = range(3, n, 2) # is there a way we can do this
    top = len(sieve)
    for si in sieve:
        if si:
            bottom = (si*si - 3) // 2 # index of the square of si
            if bottom >= top:
                break
            num_zeros = -((bottom - top) // si)
            sieve[bottom::si] = [0] * num_zeros
    return [2] + [el for el in sieve if el]

if __name__=='__main__':
    
    n=10000000
    
    from stopwatch import StopWatch
        
    StopWatch.start()
    sieveOfEratosthenes(n)
    print "Sieve of Eratosthenes: ",
    StopWatch.print_time()
    
Пример #14
0
def run():
    sw = StopWatch()

    a = np.random.rand(n, 2) * s_range + s_min
    b = np.random.rand(m, 2) * s_range + s_min

    xa = a[:, 0]
    ya = a[:, 1]

    xb = b[:, 0]
    yb = b[:, 1]

    xlim = np.asarray(
        [np.min([xa.min(), xb.min()]),
         np.max([xa.max(), xb.max()])])
    ylim = np.asarray(
        [np.min([ya.min(), yb.min()]),
         np.max([ya.max(), yb.max()])])

    exp = (xlim[1] - xlim[0]) * x_exp
    xlim += [-exp, exp]
    exp = (ylim[1] - ylim[0]) * y_exp
    ylim += [-exp, exp]

    plt.xlim(xlim)
    plt.ylim(ylim)

    plt.plot(xa,
             ya,
             a_style,
             alpha=set_opacity,
             zorder=a_order,
             markersize=a_size)
    plt.plot(xb,
             yb,
             b_style,
             alpha=set_opacity,
             zorder=b_order,
             markersize=b_size)

    total_nv = 0
    total_kd = 0
    total_bkd = 0
    total_obkd = 0

    print "Initializing naive module..."
    sw.start()
    nf = NaiveFinder(a)
    bt_nv = sw.elapsed()
    total_nv += bt_nv
    sw.reset()

    print "Initializing K-D Tree module..."
    sw.start()
    kdf = KDFinder(a)
    bt_kd = sw.elapsed()
    total_kd += bt_kd
    sw.lap()

    print "Initializing Bucketed K-D Tree module..."
    sw.start()
    bkdf = BKDFinder(a)
    bt_bkd = sw.elapsed()
    total_bkd += bt_bkd
    sw.lap()

    print "Initializing Optimized Bucketed K-D Tree module..."
    sw.start()
    obkdf = BKDFinder(a)
    bt_obkd = sw.elapsed()
    total_obkd += bt_obkd
    sw.lap()

    for i in range(m):
        print i
        p1 = b[i, :]

        sw.start()
        found = nf.find_closest_m(p1, K)
        total_nv += sw.elapsed()

        def check_mismatch(h_f, finder):
            # If there's a mismatch with ground-truth values, save K-D search steps for debugging
            if not (np.asarray(found)[:, 1] == np.asarray(h_f)[:, 1]).all():
                print "Mismatch", np.asarray(found)[:, 1], np.asarray(h_f)[:,
                                                                           1]
                for element in found:
                    p2 = element[0]
                    plt.plot([p1[0], p2[0]], [p1[1], p2[1]],
                             color=ground_truth_col,
                             zorder=2,
                             linewidth=2)
                finder.setup_plot(xlim, ylim, True)
                finder.find_closest_m(p1, 5)
                sw.start()
                finder.find_closest_m(p1, 5)
                for element in h_f:
                    p2 = element[0]
                    plt.plot([p1[0], p2[0]], [p1[1], p2[1]],
                             color=test_col,
                             zorder=3,
                             linewidth=1.5)
                print "Done"
                plt.show()

        sw.start()
        kdfound = kdf.find_closest_m(p1, K)
        total_kd += sw.elapsed()

        check_mismatch(kdfound, kdf)

        sw.start()
        bkdfound = bkdf.find_closest_m(p1, K)
        total_bkd += sw.elapsed()

        check_mismatch(bkdfound, bkdf)

        sw.start()
        obkdfound = obkdf.find_closest_m(p1, K)
        total_obkd += sw.elapsed()

        check_mismatch(obkdfound, obkdf)

    found = nf.find_closest_m(p1, 5)
    for element in found:
        p2 = element[0]
        h1 = plt.plot([p1[0], p2[0]], [p1[1], p2[1]],
                      color=ground_truth_col,
                      zorder=2,
                      linewidth=2)

    kdf.setup_plot(xlim, ylim, save_steps)
    kdfound = kdf.find_closest_m(p1, 5)
    for element in kdfound:
        p2 = element[0]
        h2 = plt.plot([p1[0], p2[0]], [p1[1], p2[1]],
                      color=test_col,
                      zorder=3,
                      linewidth=1.5)

    if zoom_in:
        points = np.asarray(kdfound)[:, 0]
        xs = np.asarray([p[0] for p in points])
        ys = np.asarray([p[1] for p in points])

        xlim = np.asarray([xs.min(), xs.max()])
        ylim = np.asarray([ys.min(), ys.max()])

        exp = (xlim[1] - xlim[0]) * x_exp
        xlim += [-exp, exp]
        exp = (ylim[1] - ylim[0]) * y_exp
        ylim += [-exp, exp]

        for ax in plt.gcf().axes:
            ax.set_xlim(xlim)
            ax.set_ylim(ylim)

    if full_screen:
        mng = plt.get_current_fig_manager()
        print mng.full_screen_toggle()

    print ''
    print 'Doing', m, 'queries in', n, 'records for', K, 'closest'
    print ''
    print 'Method\t\t\tTotal Time\t\t\tBuild Time\t\t\tMean per-query'
    print 'Naive\t\t\t', total_nv, '\t\t', bt_nv, '\t\t', (total_nv -
                                                           bt_nv) / m
    print 'KD Tree\t\t\t', total_kd, '\t\t', bt_kd, '\t\t', (total_kd -
                                                             bt_kd) / m
    print 'BKD Tree\t\t', total_bkd, '\t\t', bt_bkd, '\t\t', (total_bkd -
                                                              bt_bkd) / m
    print 'OBKD Tree\t\t', total_obkd, '\t\t', bt_obkd, '\t\t', (total_obkd -
                                                                 bt_obkd) / m

    plt.show()