Beispiel #1
0
                                                   config['image_size'],
                                                   BATCH_SIZE,
                                                   args.num_examples,
                                                   mode='test')

    try:
        ssd = create_ssd(NUM_CLASSES, args.arch, args.pretrained_type,
                         args.checkpoint_dir, args.checkpoint_path)
    except Exception as e:
        print(e)
        print('The program is exiting...')
        sys.exit()

    os.makedirs('outputs/images', exist_ok=True)
    os.makedirs('outputs/detects', exist_ok=True)
    visualizer = ImageVisualizer(info['idx_to_name'],
                                 save_dir='outputs/images')

    for i, (filename, imgs, gt_confs, gt_locs) in enumerate(
            tqdm(batch_generator,
                 total=info['length'],
                 desc='Testing...',
                 unit='images')):
        boxes, classes, scores = predict(imgs, default_boxes)
        filename = filename.numpy()[0].decode()
        original_image = Image.open(
            os.path.join(info['image_dir'], '{}.jpg'.format(filename)))
        boxes *= original_image.size * 2
        visualizer.save_image(original_image, boxes, classes,
                              '{}.jpg'.format(filename))

        log_file = os.path.join('outputs/detects', '{}.txt')
        new_size=config['image_size'],
        batch_size=BATCH_SIZE,
        num_batches=args.num_examples,
        mode='test')

    try:
        ssd = create_ssd(NUM_CLASSES, args.arch, args.pretrained_type,
                         args.checkpoint_dir, args.checkpoint_path)
    except Exception as e:
        print(e)
        print('The program is exiting...')
        sys.exit()

    os.makedirs('./find_area_results/PNGImages', exist_ok=True)
    os.makedirs('./find_area_results/detects', exist_ok=True)
    visualizer = ImageVisualizer(info['idx_to_name'],
                                 save_dir='./find_area_results/PNGImages')

    for i, (filename, imgs) in enumerate(
            tqdm(batch_generator,
                 total=info['length'],
                 desc='Testing...',
                 unit='images')):
        boxes, classes, scores = predict(imgs, default_boxes)

        filename = filename.numpy()[0].decode()
        original_image = Image.open(
            os.path.join(info['image_dir'], '{}.jpg'.format(filename)))
        boxes *= original_image.size * 2
        visualizer.save_image(original_image, boxes, classes,
                              '{}.jpg'.format(filename))
Beispiel #3
0
    return dataloader, info


if __name__ == '__main__':
    default_boxes = torch.rand(8732, 4)
    dataloader, info = create_dataloader('./data/VOCdevkit', 1, default_boxes)
    data = next(iter(dataloader))

    idx_to_name = info['idx_to_name']

    # Confirm data shapes
    print([x.shape for x in data])

    img, boxes, labels = data
    # Eliminate the batch dimension
    img = img.squeeze(0)
    boxes = boxes.squeeze(0)
    labels = labels.squeeze(0)

    # Reverse image processing step
    img = img.permute(1, 2, 0).contiguous().numpy()
    img += [123, 117, 104]
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

    # Scale boxes back to image size
    boxes = boxes.numpy() * 300
    labels = labels.numpy()

    visualizer = ImageVisualizer(idx_to_name)
    visualizer.save_image(img, boxes, labels, 'test.jpg')
Beispiel #4
0
    default_boxes = generate_default_boxes(config)

    batch_generator, info = create_batch_generator(
        args.data_dir, args.data_year, default_boxes, config['image_size'],
        BATCH_SIZE, args.num_examples)

    try:
        ssd = create_ssd(NUM_CLASSES, args.arch, args.pretrained_type,
                         args.checkpoint_dir, args.checkpoint_path)
    except Exception as e:
        print(e)
        print('The program is exiting...')
        sys.exit()

    visualizer = ImageVisualizer(info['idx_to_name'], save_dir='images')

    for i, (imgs, gt_confs, gt_locs) in enumerate(
            tqdm(batch_generator,
                 total=info['length'],
                 desc='Testing...',
                 unit='images')):
        img = imgs[0].numpy() + 1.0
        img *= 127
        img = img.astype(np.uint8)
        boxes, classes, scores = predict(imgs, default_boxes)

        boxes *= img.shape[0]

        visualizer.save_image(img, boxes, classes, '{}.jpg'.format(i))
Beispiel #5
0
    return img, all_boxes, all_scores, all_names


if __name__ == '__main__':
    with open('config.yaml', 'r') as f:
        cfg = yaml.load(f)

    if args.arch == 'ssd300':
        config = cfg['SSD300']
    else:
        config = cfg['SSD512']

    default_boxes = generate_default_boxes(config)

    dataloader, info = create_dataloader(args.data_dir, args.batch_size,
                                         config['image_size'], default_boxes,
                                         False, args.num_examples)

    ssd = create_ssd(NUM_CLASSES, args.arch, 'ssd', args.pretrained_path)
    ssd.to(device)
    ssd.eval()

    visualizer = ImageVisualizer(info['idx_to_name'],
                                 save_dir=args.save_image_dir)

    for i, data in enumerate(dataloader):
        img, boxes, scores, names = test(ssd, data, default_boxes)
        img = reconstruct_image(img)
        img_name = 'image_{}.jpg'.format(i)
        visualizer.save_image(img, boxes, names, img_name)