Update README.md
Browse files
README.md
CHANGED
|
@@ -5,22 +5,23 @@ tags:
|
|
| 5 |
- unet
|
| 6 |
- pytorch
|
| 7 |
license: apache-2.0
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
-
|
| 10 |
# Mini U-Net Colorizer
|
| 11 |
|
| 12 |
-
A 3,968,892-parameter U-Net that colorizes grayscale photos. Classification-style
|
| 13 |
-
(Zhang et al.,
|
| 14 |
-
236 quantized CIE Lab `a`/`b` bins per pixel rather than regressing a
|
| 15 |
-
single ab value directly, with color-bin loss weights derived from the real
|
| 16 |
-
training-data distribution (rare/saturated colors weighted higher) so it
|
| 17 |
doesn't just hedge toward desaturated averages. Decode with an annealed mean.
|
| 18 |
|
| 19 |
-
- **Status:** Final (20 epochs complete)
|
| 20 |
-
- **Input:** L channel normalized as `L/50 - 1`
|
| 21 |
-
- **Output:** logits over 236 ab bins, shape `(236, 256, 256)`
|
| 22 |
-
- **Trained on:** `johnowhitaker/imagenette2-320` (None), warm-started from `User-2468/mini-unet-colorizer`
|
| 23 |
-
- **Loss so far (weighted soft cross-entropy):** train 2.4069, val 2.7111
|
| 24 |
|
| 25 |
## Usage
|
| 26 |
|
|
@@ -31,16 +32,12 @@ from PIL import Image
|
|
| 31 |
# paste the SmallUNetColorizer class definition from the training script, then:
|
| 32 |
model = SmallUNetColorizer.from_pretrained("User-2468/mini-unet-colorizer")
|
| 33 |
model.eval()
|
| 34 |
-
|
| 35 |
img = Image.open("photo.jpg").convert("RGB").resize((256, 256))
|
| 36 |
lab = rgb2lab(np.asarray(img).astype("float32") / 255.0)
|
| 37 |
L = torch.from_numpy(lab[:, :, 0:1] / 50.0 - 1.0).permute(2, 0, 1)[None]
|
| 38 |
-
|
| 39 |
with torch.no_grad():
|
| 40 |
logits = model(L)
|
| 41 |
ab = model.decode(logits, temperature=0.38)[0].permute(1, 2, 0).numpy()
|
| 42 |
-
|
| 43 |
L_out = (L[0, 0].numpy() + 1) * 50.0
|
| 44 |
lab_out = np.concatenate([L_out[:, :, None], ab], axis=-1)
|
| 45 |
-
rgb_out = np.clip(lab2rgb(lab_out), 0, 1)
|
| 46 |
-
```
|
|
|
|
| 5 |
- unet
|
| 6 |
- pytorch
|
| 7 |
license: apache-2.0
|
| 8 |
+
datasets:
|
| 9 |
+
- johnowhitaker/imagenette2-320
|
| 10 |
---
|
|
|
|
| 11 |
# Mini U-Net Colorizer
|
| 12 |
|
| 13 |
+
A 3,968,892-parameter U-Net that colorizes grayscale photos. Classification-style
|
| 14 |
+
(Zhang et al., *Colorful Image Colorization*, [arXiv:1603.08511](https://arxiv.org/abs/1603.08511)): it predicts a distribution over
|
| 15 |
+
236 quantized CIE Lab `a`/`b` bins per pixel rather than regressing a
|
| 16 |
+
single ab value directly, with color-bin loss weights derived from the real
|
| 17 |
+
training-data distribution (rare/saturated colors weighted higher) so it
|
| 18 |
doesn't just hedge toward desaturated averages. Decode with an annealed mean.
|
| 19 |
|
| 20 |
+
- **Status:** Final (20 epochs complete)
|
| 21 |
+
- **Input:** L channel normalized as `L/50 - 1` → `[-1, 1]`, shape `(1, 256, 256)`
|
| 22 |
+
- **Output:** logits over 236 ab bins, shape `(236, 256, 256)`
|
| 23 |
+
- **Trained on:** `johnowhitaker/imagenette2-320` (None), warm-started from `User-2468/mini-unet-colorizer`
|
| 24 |
+
- **Loss so far (weighted soft cross-entropy):** train 2.4069, val 2.7111
|
| 25 |
|
| 26 |
## Usage
|
| 27 |
|
|
|
|
| 32 |
# paste the SmallUNetColorizer class definition from the training script, then:
|
| 33 |
model = SmallUNetColorizer.from_pretrained("User-2468/mini-unet-colorizer")
|
| 34 |
model.eval()
|
|
|
|
| 35 |
img = Image.open("photo.jpg").convert("RGB").resize((256, 256))
|
| 36 |
lab = rgb2lab(np.asarray(img).astype("float32") / 255.0)
|
| 37 |
L = torch.from_numpy(lab[:, :, 0:1] / 50.0 - 1.0).permute(2, 0, 1)[None]
|
|
|
|
| 38 |
with torch.no_grad():
|
| 39 |
logits = model(L)
|
| 40 |
ab = model.decode(logits, temperature=0.38)[0].permute(1, 2, 0).numpy()
|
|
|
|
| 41 |
L_out = (L[0, 0].numpy() + 1) * 50.0
|
| 42 |
lab_out = np.concatenate([L_out[:, :, None], ab], axis=-1)
|
| 43 |
+
rgb_out = np.clip(lab2rgb(lab_out), 0, 1)
|
|
|