U-Net model trained to enhance low-light and night-time images to match daylight appearance.
This is the v2 checkpoint, trained with a composite L1 + MS-SSIM loss instead of MSE.
MSE loss minimises expected pixel error, which causes two well-known failure modes:
1import torch
2from PIL import Image
3from torchvision import transforms
4from huggingface_hub import hf_hub_download
5from model import UNet # available in this repo
6
7ckpt_path = hf_hub_download("tyakovenko/night-to-day-enhancement-model-v2", "best_v2.pt")
8ckpt = torch.load(ckpt_path, map_location="cpu")
9model = UNet(base_filters=ckpt["args"]["base_filters"])
10model.load_state_dict(ckpt["model"])
11model.eval()
12
13def pad_to_multiple(t, m=16):
14 _, _, h, w = t.shape
15 ph = (m - h % m) % m
16 pw = (m - w % m) % m
17 return torch.nn.functional.pad(t, (0, pw, 0, ph), mode="reflect"), h, w
18
19img = Image.open("night.jpg").convert("RGB")
20x = transforms.ToTensor()(img).unsqueeze(0)
21x_padded, orig_h, orig_w = pad_to_multiple(x)
22
23with torch.no_grad():
24 out = model(x_padded)
25
26out = out[:, :, :orig_h, :orig_w].clamp(0, 1)
27transforms.ToPILImage()(out.squeeze(0)).save("enhanced.jpg")