Views
No views yet
a/b bins per pixel rather than regressing a
single ab value directly, with color-bin loss weights derived from the real
training-data distribution (rare/saturated colors weighted higher) so it
doesn't just hedge toward desaturated averages. Decode with an annealed mean.L/50 - 1 -> [-1, 1], shape (1, 256, 256)(236, 256, 256)johnowhitaker/imagenette2-320 (None), warm-started from User-2468/mini-unet-colorizer1import numpy as np, torch
2from skimage.color import rgb2lab, lab2rgb
3from PIL import Image
4# paste the SmallUNetColorizer class definition from the training script, then:
5model = SmallUNetColorizer.from_pretrained("User-2468/mini-unet-colorizer")
6model.eval()
7
8img = Image.open("photo.jpg").convert("RGB").resize((256, 256))
9lab = rgb2lab(np.asarray(img).astype("float32") / 255.0)
10L = torch.from_numpy(lab[:, :, 0:1] / 50.0 - 1.0).permute(2, 0, 1)[None]
11
12with torch.no_grad():
13 logits = model(L)
14 ab = model.decode(logits, temperature=0.38)[0].permute(1, 2, 0).numpy()
15
16L_out = (L[0, 0].numpy() + 1) * 50.0
17lab_out = np.concatenate([L_out[:, :, None], ab], axis=-1)
18rgb_out = np.clip(lab2rgb(lab_out), 0, 1)