<jupyter_start><jupyter_text>Example w/out unet<jupyter_code>im = imgs[0]
im = im[ :, :, [2,1,0] ] # BGR -> RGB

p = PaperCornerPredictor()
print('trained shape:', p.train_shape)
pts = p.predict_corners(tensor(im), shape='train')
pts
#export
def points_on_mask(mask, o): # o - (8,) shape arr w/ points x,y coords
    mask = mask.copy()
    for i, c in zip(range(0,8,2), [(255,0,0), (0,255,0), (0,0,255), (255,255,0)]):
        mask = cv2.circle(mask, (o[i], o[i+1]), radius=15, color=c, thickness=50)
    return mask

def show_points_on_mask(mask, o): # o - (8,) shape arr w/ points x,y coords
    return plot(points_on_mask(mask, o))
show_points_on_mask(im, pts)
pts = p.predict_corners(tensor(im), shape=(200,200))
show_points_on_mask(im, pts)<jupyter_output><empty_output><jupyter_text>Example w/ unet<jupyter_code>im = imgs[0]
im = im[ :, :, [2,1,0] ] # BGR -> RGB

p = PaperCornerPredictor(use_unet=True, use_gpu=False)
pts = p.predict_corners(tensor(im), shape='train')
pts
show_points_on_mask(im, pts)
pts = p.predict_corners(tensor(im), shape=(200,200))
show_points_on_mask(im, pts)<jupyter_output><empty_output><jupyter_text>Times<jupyter_code>from ocr.corner_detection_training import *
corner_predictor_gpu = PaperCornerPredictor(model_name='unet_paper_mask', use_gpu=True, use_unet=True)
corner_predictor_cpu = PaperCornerPredictor(model_name='unet_paper_mask', use_gpu=False, use_unet=True)
%%timeit
pts = corner_predictor_cpu.predict_corners(tensor(im), shape='train')
%%timeit
pts = corner_predictor_cpu.predict_corners(tensor(im), shape=(1080,1920))
%%timeit
pts = corner_predictor_gpu.predict_corners(tensor(im), shape='train')
%%timeit
pts = corner_predictor_gpu.predict_corners(tensor(im), shape=(1080,1920))<jupyter_output>28.4 ms ± 423 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)<jupyter_text>Perspective transform<jupyter_code>plot(im[240:280 , 720:950])
transformed_im = p.transform_image(im, pts, out_shape=[1080,720])
%matplotlib notebook
plot(transformed_im[70:120 , 200:600])<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup