Example #1
0
def display_image_depth(image, depth):
    depth.add_(-depth.min())
    depth = depth.div_(1000 / 256).clamp(max=255).byte()

    depth = cv.gray_to_rgb(depth)

    cv.display(torch.cat([image, depth], 1))
Example #2
0
classes = model_args.dataset.classes

model.to(device)
encoder.to(device)

frame = cv.imread_color(args.input)

nms_params = detection_table.nms_defaults._extend(nms=args.threshold)
pprint_struct(nms_params)

detections = evaluate_image(model,
                            frame,
                            encoder,
                            nms_params=nms_params,
                            device=device,
                            crop_boxes=True)

for prediction in detections._sequence():

    if prediction.confidence > 0.7:
        label_class = classes[prediction.label].name
        display.draw_box(frame,
                         prediction.bbox,
                         confidence=prediction.confidence,
                         name=label_class.name,
                         color=display.to_rgb(label_class.colour))

frame = cv.resize(frame, (frame.size(1) // 2, frame.size(0) // 2))
cv.display(frame)
Example #3
0
def show_indexed_batch(t, cols=int(6)):
    colorizer = index_map.colorizer_t(255)
    tiled = tile_batch(t, cols)

    color = colorizer(tiled)
    return cv.display(color)
Example #4
0
def show_batch(t, cols=int(6), scale=1):
    tiled = tile_batch(t, cols)
    tiled = cv.resize (tiled, (tiled.size(0) * scale, tiled.size(1) * scale), interpolation = cv.INTER_NEAREST)

    return cv.display(tiled)
Example #5
0
            transform=random_crop(dim))

    loader=DataLoader(dataset, num_workers=args.num_workers,
        batch_size=args.batch_size, sampler=RepeatSampler(args.epoch_size, dataset))

    return loader, dataset




if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='Segmentation - view data set')
    parser.add_argument('--input', default='/storage/workspace/dtd/images/scaly',
                        help='input image path')


    args = parser.parse_args()

    args.num_workers = 1
    args.epoch_size = 1024
    args.batch_size = 16

    loader, dataset = training(args, (144, 144))

    for _, data in enumerate(loader):
        image = tensor.tile_batch(data, cols=4)

        if (cv.display(image) == 27):
            break
Example #6
0
def visualise(model, encoder, iter, args):

    threshold = 50
    zoom = 100

    modes = ['target', 'matches', 'prediction', 'normal']
    mode_index = 0
    debug_index = 0

    help_str = """
    keys:
    -+:  reduce and increase threshold
    []:  zoom in and out

    (): adjust nms threshold
    <>: adjust max detections

    m:  show matches
    p:  show predictions
    a:  show matched anchor boxes
    t:  show target boxes
    """

    keys = struct(escape=27, space=32, minus=45, plus=61)

    nms = struct(nms=0.5, threshold=0.05, detections=400)

    print(help_str)

    model.to(device)
    encoder.to(device)

    print("classes:")
    print(dataset.classes)

    for batch in iter:

        key = 0
        while (not key in [keys.escape, keys.space]):

            debug_key = encoder.debug_keys[debug_index -
                                           1] if debug_index > 0 else None
            evals = [
                evaluate_vis(model,
                             encoder,
                             i,
                             nms,
                             dataset.classes,
                             args,
                             debug_key=debug_key) for i in batch
            ]

            def show2(x):
                return "{:.2f}".format(x)

            def show_vector(v):
                return "({})".format(",".join(map(show2, v.tolist())))

            for e in evals:
                print("{}: {:d}x{:d} {}".format(
                    e.file, e.image_size[0], e.image_size[1],
                    str(e.stats._map(show_vector))))

            display = overlay_batch(evals,
                                    mode=modes[mode_index],
                                    scale=100 / zoom,
                                    classes=dataset.classes,
                                    threshold=threshold / 100,
                                    cols=4)
            if zoom != 100:
                display = resize_scale(display, zoom / 100)

            key = cv.display(display)

            if key == keys.minus and threshold > 0:
                threshold -= 5
                print("reducing threshold: ", threshold)
            elif key == keys.plus and threshold < 100:
                threshold += 5
                print("increasing threshold: ", threshold)

            elif chr(key) == '(' and nms.nms > 0:
                nms.nms = max(0, nms.nms - 0.05)
                print("decreasing nms threshold: ", nms.nms)

            elif chr(key) == ')' and nms.nms < 1:
                nms.nms = min(1, 0.05 + nms.nms)
                print("increasing nms threshold: ", nms.nms)
            elif chr(key) == '<' and nms.detections > 50:
                nms.detections -= 50
                print("decreasing max detections: ", nms.detections)
            elif chr(key) == '>':
                nms.detections += 50
                print("increasing max detections: ", nms.detections)

            elif key == 91 and zoom > 10:
                zoom -= 5
                print("zoom out: ", zoom)
            elif key == 93 and zoom < 200:
                zoom += 5
                print("zoom in: ", zoom)
            elif chr(key) == 'm':
                mode_index = (mode_index + 1) % len(modes)
                print("showing " + modes[mode_index])

            elif chr(key) == 'd':
                debug_index = (debug_index + 1) % (len(encoder.debug_keys) + 1)
                if debug_index > 0:
                    print("showing debug: " +
                          encoder.debug_keys[debug_index - 1])
                else:
                    print("hiding debug")

        if (key == 27):
            break