Beispiel #1
0
def visual_test(epoch):
    print("===> Running visual test...")
    for i, tup in enumerate(visual_test_set):
        result = interpolate(model, load_img(tup[0]), load_img(tup[2]))
        result = pil_to_tensor(result)
        tag = 'data/visual_test_{}'.format(i)
        board_writer.add_image(tag, result, epoch)
Beispiel #2
0
def stitch_frames(src_path, dest_path, output_fps=None, drop_frames=False):

    tick_t = timer()

    frames = [join(src_path, x) for x in listdir(src_path)]
    frames = [x for x in frames if is_image(x)]
    frames.sort()

    print('===> Loading frames...')
    if drop_frames:
        frames = [load_img(x) for i, x in enumerate(frames) if i % 2 == 0]
    else:
        frames = [load_img(x) for i, x in enumerate(frames)]

    print('===> Writing results...')
    write_video(dest_path, frames, output_fps)

    tock_t = timer()
    print("Done. Took ~{}s".format(round(tock_t - tick_t)))
Beispiel #3
0
def test_linear_interp(validation_set=None):

    if validation_set is None:
        validation_set = get_validation_set()

    total_ssim = 0
    total_psnr = 0
    iters = len(validation_set.tuples)

    crop = CenterCrop(config.CROP_SIZE)

    for tup in validation_set.tuples:
        x1, gt, x2, = [pil_to_tensor(crop(load_img(p))) for p in tup]
        pred = torch.mean(torch.stack((x1, x2), dim=0), dim=0)
        total_ssim += ssim(pred, gt).item()
        total_psnr += psnr(pred, gt).item()

    avg_ssim = total_ssim / iters
    avg_psnr = total_psnr / iters

    print(f'avg_ssim: {avg_ssim}, avg_psnr: {avg_psnr}')
Beispiel #4
0
def test_on_validation_set(model, validation_set=None):

    if validation_set is None:
        validation_set = get_validation_set()

    total_ssim = 0
    total_psnr = 0
    iters = len(validation_set.tuples)

    crop = CenterCrop(config.CROP_SIZE)

    for i, tup in enumerate(validation_set.tuples):
        x1, gt, x2, = [crop(load_img(p)) for p in tup]
        pred = interpolate(model, x1, x2)
        gt = pil_to_tensor(gt)
        pred = pil_to_tensor(pred)
        total_ssim += ssim(pred, gt).item()
        total_psnr += psnr(pred, gt).item()
        print(f'#{i+1} done')

    avg_ssim = total_ssim / iters
    avg_psnr = total_psnr / iters

    print(f'avg_ssim: {avg_ssim}, avg_psnr: {avg_psnr}')
Beispiel #5
0
def find_icme_optical_flow_magnitude():
    tuples = tuples_from_custom("./video/icme/")

    pil_to_numpy = lambda x: np.array(x)[:, :, ::-1]

    for tup_index in range(len(tuples)):
        tup = tuples[tup_index]
        imgs = [load_img(x) for x in tup]
        imgs = [pil_to_numpy(x) for x in imgs]

        for pair_idx in range(2, len(imgs)):
            img1 = imgs[pair_idx - 2]
            img2 = imgs[pair_idx]
            flow = cv.optflow.calcOpticalFlowSF(img1,
                                                img2,
                                                layers=3,
                                                averaging_block_size=2,
                                                max_flow=4)
            n = np.sum(1 - np.isnan(flow), axis=(0, 1))
            flow[np.isnan(flow)] = 0
            flow_magnitude = np.linalg.norm(flow.sum(axis=(0, 1)) / n)
            print(
                f"Flow magnitude {tup[pair_idx-2]} to {tup[pair_idx]} is {flow_magnitude}"
            )
Beispiel #6
0
 def __getitem__(self, index):
     frames = self.tuples[index]
     x1, target, x2 = (pil_to_tensor(self.crop(data_manager.load_img(x))) for x in frames)
     input = torch.cat((x1, x2), dim=0)
     return input, target
Beispiel #7
0
        processed_magnitude += v[1]
        if processed_magnitude > check_vectors_magnitude_ratio * sum_magnitudes:
            break

        diff = angle_difference(v[0], avg_direction_angle)
        if diff > check_vectors_max_angle_difference:
            num_check_fails += 1

    fail_ratio = num_check_fails / float(checked_vecs)

    return (fail_ratio < check_vectors_max_error_ratio, avg_direction)


print(len(tuples_from_custom("video/raw/frames")))

img1 = load_img("video/raw/frames/FjU_x1106pg/255000.jpg")
img2 = load_img("video/raw/frames/FjU_x1106pg/255004.jpg")

pil_to_numpy = lambda x: np.array(x)[:, :, ::-1]

img1 = pil_to_numpy(img1)
img2 = pil_to_numpy(img2)

#flow = cv.optflow.calcOpticalFlowSF(img1, img2, layers=3, averaging_block_size=2, max_flow=4)

img_h = img1.shape[0]
img_w = img1.shape[1]
patch_h = 150
patch_w = 150
flow_threshold = 6