User-2468 commited on
Commit
6ab713a
·
verified ·
1 Parent(s): 2e098df

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +40 -10
README.md CHANGED
@@ -1,16 +1,46 @@
1
  ---
2
- license: apache-2.0
3
- pipeline_tag: image-to-image
4
  tags:
5
- - classification
6
- - colorization
7
  - image-to-image
8
- - model_hub_mixin
9
- - pytorch_model_hub_mixin
10
  - unet
 
 
11
  ---
12
 
13
- This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
14
- - Code: [More Information Needed]
15
- - Paper: [More Information Needed]
16
- - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
 
 
2
  tags:
 
 
3
  - image-to-image
4
+ - colorization
 
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., "Colorful Image Colorization"): it predicts a distribution over
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` -> `[-1, 1]`, shape `(1, 256, 256)`
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
+
27
+ ```python
28
+ import numpy as np, torch
29
+ from skimage.color import rgb2lab, lab2rgb
30
+ 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
+ ```