try:
with open("data/coco_color_fps.json") as f:
= json.load(f)["fps_color"]
color_fps except FileNotFoundError:
= [str(fi) for fi in Path("data/train2017").glob("**/*.jpg")]
fps = []
color_fps with multiprocessing.Pool() as p:
= zip(p.imap(black_and_white, fps), fps)
iter_ for b_w, fp in tqdm(iter_, total=len(fps)):
if not b_w:
color_fps.append(fp)with open("data/coco_color_fps.json", "wt") as f:
= json.dump({"fps_color": fps_color}, f) color_fps
COCO: Super-resolution
This notebook continues the data preprocessing work, but specifically focused on preparing the data for super-resolution.
coco_2017_trn
coco_2017_trn (fps=None, n=None, remove_bw=True)
= coco_2017_trn(fps_color) ds
crop_to_box
crop_to_box (img:<module'PIL.Image'from'/opt/hostedtoolcache/Python/3.10. 14/x64/lib/python3.10/site-packages/PIL/Image.py'>)
preprocess_ddpm
preprocess_ddpm (examples, pipe, extra_blur=False)
= ds["train"][:6]
rows = plt.subplots(4, 5, figsize=(10, 8))
fig, axes for ax in axes.flatten():
ax.set_xticks([])
ax.set_yticks([])= preprocess_ddpm(rows, pipe=trn_preprocess_super_rez)
trn = preprocess_ddpm(rows, pipe=tst_preprocess_super_rez)
tst for im_trn_hi, im_trn_lo, im_test, im_org, ax_col in zip(
"image_high_rez"],
trn["image_low_rez"],
trn["image_high_rez"],
tst["image"],
rows[
axes.T,
):for ax, im in zip(ax_col, (im_trn_lo, im_trn_hi, im_test)):
1, 2, 0))
ax.imshow(denorm(im).permute(3].imshow(im_org)
ax_col[0, 0].set(title="Train (Low Rez)")
axes[1, 0].set(title="Train (Hi Rez)")
axes[2, 0].set(title="Test")
axes[3, 0].set(title="Original")
axes[ fig.tight_layout()
get_coco_dataset
get_coco_dataset (fac, trn, tst, fp='data/train2017', bs=512, n=None, columns=['image_low_rez', 'image_high_rez'])
= get_coco_dataset_super_rez(n=100) dls
CPU times: user 320 ms, sys: 35.5 ms, total: 355 ms
Wall time: 173 ms
We also want to do colorization
preprocess_colorization
preprocess_colorization (examples, pipe)
= get_coco_dataset_colorization(n=100) dls
CPU times: user 319 ms, sys: 25 ms, total: 344 ms
Wall time: 156 ms
= dls.peek() xb, yb
max() denorm(xb).
tensor(0.9961)
6, ...]), imsize=(1.6)) show_images(denorm(xb[:
6, ...]), imsize=(1.6)) show_images(denorm(yb[: