singam96 commited on
Commit
cf09647
·
verified ·
1 Parent(s): 1bf64a6

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +221 -0
README.md ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: facebook/dinov2-small
4
+ pipeline_tag: image-to-image
5
+ library_name: pytorch
6
+ tags:
7
+ - inverse-rendering
8
+ - intrinsic-decomposition
9
+ - albedo
10
+ - normal-map
11
+ - depth-estimation
12
+ - dinov2
13
+ ---
14
+
15
+ # ShadeNet-5
16
+
17
+ **Single-image inverse rendering** — one RGB photo in, albedo + relative depth + surface normal out.
18
+
19
+ ![ShadeNet-5 outputs on held-out images](assets/hero.png)
20
+
21
+ A feed-forward network on a frozen **DINOv2 ViT-S/14** backbone. In 1 forward pass it predicts a residual correction to a fixed, photo-derived prior, giving the three maps. No iteration, no time embedding, no diffusion schedule.
22
+
23
+ The images and the headline numbers on this card use an optional post-processing step: the prediction is **averaged over the mirrored photo and over small rotations of ±4 degrees** (six forward passes) and the normals are rescaled to unit length. The plain single pass is reported next to it, and both are measured below.
24
+
25
+ ## Network (traced)
26
+
27
+ ![Traced architecture: encoder / bottleneck / decoder, patch dictionaries, per-map output heads](assets/arch.png)
28
+
29
+ The diagram shows the trainable UNet, its patch dictionaries and the output heads. The frozen DINOv2 branch that feeds the decoder skips is not drawn.
30
+
31
+ | | |
32
+ |---|---|
33
+ | parameters | **34,652,431** (12,595,855 trainable) |
34
+ | patch dictionaries | 8,582,400 — bottleneck x4, d0 x4, d1 x4, d2 x4 |
35
+ | folded fixed patterns | in, u1, u2, u3, u4, u5, u6, d3, d4, out |
36
+ | model | ParallelUNet, one forward pass, residual on a fixed photo prior (`mix`) |
37
+ | input | 3ch photo + 7ch state (448x448 shown) |
38
+
39
+ ## TL;DR
40
+
41
+ | | |
42
+ |---|---|
43
+ | Task | Single-image inverse rendering (intrinsic decomposition) |
44
+ | Output | 7ch — albedo (3) + relative depth (1) + normal (3) |
45
+ | Params | 34.7M total (12.6M trainable; 22.1M is the frozen DINOv2 trunk) |
46
+ | Backbone | DINOv2 ViT-S/14, frozen (Meta AI) |
47
+ | Inference | six forward passes (mirror + rotations of ±4 degrees, averaged) + unit-length normals; the plain single pass is also available |
48
+ | Input size | 448x448 (multiples of 448 only: 448 or 896) |
49
+ | Framework | PyTorch (no ONNX export for this checkpoint) |
50
+ | License | Apache-2.0 |
51
+
52
+ ## What it does
53
+
54
+ Given a single RGB image it predicts three intrinsic maps: **albedo** (base colour), **relative depth** (grayscale, per-image), and a **surface normal** map. Output channels are `[0:3]=albedo`, `[3:4]=depth`, `[4:7]=normal`, all in `[-1, 1]`.
55
+
56
+ > Breaking change vs ShadeNet-3.2: this model has **no shading channel** (7ch, not 8ch).
57
+
58
+ ## Results
59
+
60
+ Per-map L1 (raw output vs label; albedo and normal masked where the label is invalid) on the 23-image held-out validation split at 448px, for the best checkpoint (epoch 19, pruned):
61
+
62
+ | map | single pass | mirror average + unit normals | mirror + rotations ±4° + unit normals |
63
+ |---|---|---|---|
64
+ | albedo | 0.1804 | 0.1794 | 0.1734 |
65
+ | depth | 0.1754 | 0.1704 | 0.1653 |
66
+ | normal | 0.1730 | 0.1537 | 0.1497 |
67
+ | **mean** | 0.1763 | 0.1679 | **0.1628** |
68
+
69
+ Averaging the prediction with the one on the mirrored photo lowers the mean L1 by 0.0080 (±0.0018, better on 19 of the 23 images), almost all of it in the normals (0.1730 to 0.1549; mean angular error 20.6 to 18.3 degrees). Rescaling the normals to unit length is free and lowers the normal L1 a little more (0.1730 to 0.1713 on a single pass, 0.1549 to 0.1537 after mirror averaging). Adding rotations of ±4° on top of the mirror average lowers the mean L1 by a further 0.0051 (±0.0009, better on 21 of the 23 images): albedo 0.1794 to 0.1734, depth 0.1704 to 0.1653, normal 0.1537 to 0.1497, normal angle 18.3° to 17.7°. Rotation on its own (three passes) already improves all three maps and beats the plain pass on 22 of 23 images, the albedo most (0.1804 to 0.1740), which likely reflects the tile-grid texture averaging out when the grid is tilted against the picture (not verified). The recipe costs six forward passes: about 262 ms per image against 52 ms for the plain pass on an RTX A4000, resampling included.
70
+
71
+ The validation split is small (23 images) and every label is a Marigold-V2 pseudo-label (depth is decoded from Marigold's colour visualisation), so treat these as indicative, not benchmark-grade. The depth loss is scale-and-shift invariant, so raw depth L1 is not what it optimises.
72
+
73
+ ### Against the previous run
74
+
75
+ Same 23 validation images, same labels, same L1 metric, both as a plain single pass. The previous run used the MobileNetV2 trunk, a masked-L1 loss, 384px inputs and trained 6 epochs (best epoch shown):
76
+
77
+ | map | previous run | this model |
78
+ |---|---|---|
79
+ | albedo | 0.2474 | 0.1804 |
80
+ | depth | 0.3628 | 0.1754 |
81
+ | normal | 0.2744 | 0.1730 |
82
+ | **mean** | 0.3141 | **0.1763** |
83
+
84
+ Backbone, loss, resolution and training length all changed together, so the gain cannot be attributed to any single change.
85
+
86
+ ## Test-time ensembling
87
+
88
+ Which extra predictions of the same photo are worth averaging, and whether to take their mean or median? Each row combines several predictions, scored on the same 23 images, and is compared with the plain single pass image by image (the last column is the mean improvement in the average of the three L1s, plus or minus its standard error; positive is better). The normals are raw (not rescaled) in this first table.
89
+
90
+ | ensemble | forwards | albedo | depth | normal | mean | gain |
91
+ |---|---|---|---|---|---|---|
92
+ | single pass | 1 | 0.1804 | 0.1754 | 0.1730 | 0.1763 | — |
93
+ | noise draws x16, mean or median | 16 | 0.1804 | 0.1754 | 0.1729 | 0.1762 | +0.0000 ± 0.0000 |
94
+ | photo jitter x3, mean | 3 | 0.1791 | 0.1753 | 0.1726 | 0.1756 | +0.0006 ± 0.0002 |
95
+ | **mirror, mean** | 2 | 0.1794 | 0.1704 | 0.1549 | 0.1682 | **+0.0080 ± 0.0018** |
96
+ | mirror + photo jitter x3, mean | 6 | 0.1781 | 0.1703 | 0.1548 | 0.1677 | +0.0085 ± 0.0018 |
97
+ | shifts x5, mean | 5 | 0.1765 | 0.1967 | 0.1748 | 0.1826 | −0.0064 ± 0.0023 |
98
+ | shifts x5, median | 5 | 0.1768 | 0.1772 | 0.1738 | 0.1759 | +0.0003 ± 0.0021 |
99
+ | mirror + shifts x5, mean | 10 | 0.1760 | 0.1941 | 0.1592 | 0.1764 | −0.0001 ± 0.0031 |
100
+ | mirror + shifts x5, median | 10 | 0.1761 | 0.1755 | 0.1577 | 0.1698 | +0.0065 ± 0.0025 |
101
+
102
+ - Mirror averaging is the clearest win in this table: two forward passes for a 4.6% lower mean L1, mostly in the normals.
103
+ - Noise draws change nothing: the noise on the depth input moves the output by about 0.0001, so averaging over them is wasted work.
104
+ - Photo-jitter ensembles add little: 0.0005 on top of mirroring, for three times the cost.
105
+ - Mean versus median: on clean predictions (mirror, photo jitter) they are within 0.0004 of each other and the mean is slightly better. With shifted copies, which likely carry wrap-around artefacts at the borders, the mean is much worse on depth (0.1967 against 0.1772 for the median at five passes). The median needs at least five passes: at three it was worse than the mean.
106
+ - Shifted ensembles improve albedo but hurt depth and normals, so they are not used.
107
+
108
+ ### Rotations
109
+
110
+ A second study rotated the photo by a small angle (the training augmentation covers ±12 degrees), predicted, rotated the maps back with the normals reoriented, and averaged per pixel over the passes that cover it (a rotated canvas loses the corners of the frame). Unit-length normals are applied to every row here, and each row is compared both with the plain pass and with the mirror average.
111
+
112
+ | ensemble | forwards | albedo | depth | normal | mean | gain vs plain | gain vs mirror |
113
+ |---|---|---|---|---|---|---|---|
114
+ | single pass | 1 | 0.1804 | 0.1754 | 0.1713 | 0.1757 | — | — |
115
+ | mirror, mean | 2 | 0.1794 | 0.1704 | 0.1537 | 0.1679 | +0.0078 ± 0.0019 | — |
116
+ | rotations ±4°, mean | 3 | 0.1740 | 0.1688 | 0.1653 | 0.1693 | +0.0064 ± 0.0011 | −0.0015 ± 0.0018 |
117
+ | rotations ±4°, median | 3 | 0.1743 | 0.1703 | 0.1660 | 0.1702 | +0.0055 ± 0.0010 | −0.0024 ± 0.0018 |
118
+ | rotations ±12°, mean | 3 | 0.1738 | 0.1695 | 0.1650 | 0.1694 | +0.0063 ± 0.0015 | −0.0016 ± 0.0018 |
119
+ | rotations ±4°, ±8°, ±12°, mean | 7 | 0.1722 | 0.1674 | 0.1634 | 0.1677 | +0.0080 ± 0.0016 | +0.0002 ± 0.0019 |
120
+ | **mirror + rotations ±4°, mean** | 6 | 0.1734 | 0.1653 | 0.1497 | 0.1628 | +0.0129 ± 0.0023 | **+0.0051 ± 0.0009** |
121
+ | mirror + rotations ±4°, median | 6 | 0.1736 | 0.1657 | 0.1500 | 0.1631 | +0.0126 ± 0.0024 | +0.0047 ± 0.0009 |
122
+ | mirror + rotations ±4°, ±8°, mean | 10 | 0.1721 | 0.1651 | 0.1491 | 0.1621 | +0.0136 ± 0.0025 | +0.0058 ± 0.0012 |
123
+ | mirror + rotations ±4°, ±8°, ±12°, mean | 14 | 0.1713 | 0.1649 | 0.1492 | 0.1618 | +0.0139 ± 0.0027 | +0.0061 ± 0.0014 |
124
+
125
+ - Rotation alone works: three passes (the photo and ±4°) improve all three maps and beat the plain pass on 22 of 23 images, about as well as mirroring (the difference between them is within noise).
126
+ - Mirror and rotation stack: mirror + ±4° (six passes) is 0.0051 ± 0.0009 better than the mirror average alone, on 21 of 23 images. More angles help a little (ten passes 0.0058, fourteen 0.0061), with diminishing returns, so the card uses six.
127
+ - The angle hardly matters: ±4°, ±8° and ±12° give the same result with three passes (0.1693 to 0.1694), so a small tilt gets nearly all of the gain.
128
+ - Mean beats median here (0.1628 against 0.1631 with six passes, 0.1693 against 0.1702 with three): the passes are clean, so discarding values only loses information.
129
+ - The rotation sign was checked on real labels: rotating the label normals by R(+θ) keeps their correlation with the depth gradient, the opposite sign lowers it.
130
+
131
+ ## Gallery
132
+
133
+ Held-out images (never seen during training — all of them are in this run's validation split), rendered averaged over the mirrored photo and rotations of ±4 degrees (six forward passes) with unit-length normals. Each panel: input | albedo / depth | normal.
134
+
135
+ ### snowy mountain + people
136
+
137
+ ![snowy mountain + people](assets/2444741900_5cb3ef3e1d_result.png)
138
+
139
+ ### person against a wall
140
+
141
+ ![person against a wall](assets/3185371756_ff4e9fa8a6_result.png)
142
+
143
+ ### motocross on dirt
144
+
145
+ ![motocross on dirt](assets/3620492762_7f6a9b4746_result.png)
146
+
147
+ ### paraglider at sunset
148
+
149
+ ![paraglider at sunset](assets/265223843_9ef21e1872_result.png)
150
+
151
+ ### metro station interior
152
+
153
+ ![metro station interior](assets/3672057606_cb6393dbd9_result.png)
154
+
155
+ ### red building street
156
+
157
+ ![red building street](assets/3296500180_0d7a6650dc_result.png)
158
+
159
+ ### dog with a ball
160
+
161
+ ![dog with a ball](assets/3380519003_9f91d5a7fb_result.png)
162
+
163
+ ### skier on a cliff
164
+
165
+ ![skier on a cliff](assets/3351370405_e417e38f52_result.png)
166
+
167
+ ## Architecture
168
+
169
+ A `ParallelUNet` with two parallel encoders: a depthwise-separable conv UNet (full H/32 depth) and a **frozen DINOv2 ViT-S/14** (22.1M parameters, `facebook/dinov2-small`) that sees only the photo. At 448x448 the ViT produces a 32x32 token grid; four of its blocks (2, 5, 8, 11) are tapped, concatenated, 1x1-projected per level and resized to H/2 ... H/32, where they join the UNet's skip connections and bottleneck. The ViT never resizes its input: height and width must be multiples of 14 (the ViT) and 32 (the UNet pyramid), i.e. multiples of 224; the dictionary patch sizes narrow this to multiples of 448 (448 and 896 run, 224 and 672 do not).
170
+
171
+ Soft **patch dictionaries** (128 atoms each, with an addressing MLP, applied 4 times with shared weights) remain at 4 stages: `bottleneck` (patch 7), `d0` (patch 4), `d1` (patch 8), `d2` (patch 8). They hold 8.6M of the 12.6M trainable parameters. The other 10 stages (`in`, `u1`, `u2`, `u3`, `u4`, `u5`, `u6`, `d3`, `d4`, `out`) were trained with a dictionary too, but each ended up picking the same atom for every tile, so after training they were folded into one fixed pattern per stage (see Pruning). The output is an unbounded residual added to the starting state, through per-map heads (albedo 3ch / depth 1ch / normal 3ch).
172
+
173
+ Inference is one forward pass: `x_0 = P(photo)`, `x_1 = clamp(x_0 + f(photo, x_0 + beta*z))`. The starting prior `P` keeps the photo as albedo and blends 50/50 a simple photo cue (luminance for depth, the photo for normals) with a fixed prior (a vertical ramp for depth, a mean normal). `beta*z` perturbs only the network's *input view* of the depth channel (fixed noise field `z`, amplitude 0.3) and never enters the output. There is no time embedding and no diffusion schedule. Optionally the same pass is repeated on the mirrored photo and on photos rotated by ±4 degrees (reflected border); the maps are rotated and flipped back (normals reoriented, normal x negated for the mirror) and averaged per pixel over the passes that cover it, and the normals are rescaled to unit length; this is what the gallery shows.
174
+
175
+ ## Pruning
176
+
177
+ The model was trained with a patch dictionary at all 14 stages. Measured on 150 training images, at 10 of them the addressing picked the same single atom for at least 95% of tiles in every loop pass, i.e. the dictionary was acting as a constant bias. After training, each of those was replaced by that atom, folded with its learned scale and loop count into one [C, p, p] pattern tiled over the feature map. No retraining was done.
178
+
179
+ | | unpruned (epoch 19) | pruned (this card) |
180
+ |---|---|---|
181
+ | mean L1 | 0.1763 | 0.1763 |
182
+ | model loss | 0.2476 | 0.2476 |
183
+ | parameters | 50.34M | 34.65M |
184
+ | time per image | 70.7 ms | 44.8 ms |
185
+ | dictionaries | 14 | 4 + 10 fixed patterns |
186
+
187
+ Same 23 validation images and noise seeds for both; time is per image on an RTX A4000, batch 1, bf16, first image excluded. The largest difference at any pixel between the two models' outputs is 0.0195 on the [-1, 1] scale. `d0`, `d1` and `bottleneck` still choose between many atoms, and folding all 14 stages raised depth L1 from 0.1754 to 0.2258, so they stay dictionaries. `d2` splits its tiles about half and half between two atoms; it was also left as a dictionary because folding it adds a 0.0008 depth L1 cost and a 0.0898 maximum pixel difference.
188
+
189
+ ## Training
190
+
191
+ - Data: Flickr8k RGB with Marigold-V2 pseudo-labels for albedo, normal and depth. 8,054 training scenes, 23 held out; no label-quality filtering in this run.
192
+ - Warm start: weights-only transfer from the previous run's best checkpoint (itself warm-started from ShadeNet-3.2). The UNet and dictionary weights transfer; the DINOv2 projector and the two H/32 atom banks (patch size 7) start fresh.
193
+ - Per-map losses on the predicted maps: albedo = masked L1 + multiscale gradient matching; depth = scale-and-shift-invariant L1 + gradient matching + a small raw-L1 anchor (the output is clamped to [-1, 1] and SSI alone cannot tell a map from its inverse); normal = mean angle between predicted and target vectors + a small unit-length penalty. Equal weights across the three maps.
194
+ - A small PatchGAN (weight 0.02, albedo and normal maps only) is added; no perceptual loss, no EMA.
195
+ - Optimiser: schedule-free AdamW, lr 1e-4, bf16-mixed, batch 4 x gradient accumulation 2. One RTX A4000, about 28 minutes per epoch.
196
+ - Augmentation: zoom-in crop, smooth warp, in-plane roll (+-12 degrees, normals reoriented — an earlier version of the pipeline rotated them the wrong way and was fixed before this run), horizontal mirror, photometric jitter on the input photo only, and 35% of training photos replaced by a relit render (albedo x shading from the normals). No vertical mirror.
197
+ - Length: 19 epochs at 448px, stopped by hand once validation loss was improving by about 0.4% per epoch; the reported checkpoint is the one with the best mean per-map L1, pruned after training (see Pruning).
198
+
199
+ ## Usage
200
+
201
+ PyTorch only; there is no ONNX export for this checkpoint. The inference script loads the hyper-parameters stored in the checkpoint (including which stages are folded patterns); pass the input size explicitly (448 or 896):
202
+
203
+ ```bash
204
+ python infer.py photos/ \
205
+ --checkpoint best-l1-pruned10-ep19.ckpt \
206
+ --image-size 448 \
207
+ --enhanced \
208
+ --output-dir out/
209
+ ```
210
+
211
+ `--enhanced` turns on the post-processing described above in one switch: mirror average, rotations of ±4 degrees and unit-length normals (six forward passes). The three can also be set separately (`--flip-avg`, `--rot-avg 4`, `--unit-normals`); leave them all out for the plain single pass. All are off by default because they were only validated on this model.
212
+
213
+ Each input produces a panel image with the albedo, depth and normal maps. A GPU is recommended: the model has 35M parameters and runs at 448px.
214
+
215
+ ## Limitations
216
+
217
+ - Input sizes: multiples of 448 only (448 is what it was trained at). Other sizes must be resized first.
218
+
219
+ ## License & attribution
220
+
221
+ Apache-2.0. Backbone: DINOv2 (Meta AI, Apache-2.0). Albedo, normal and depth labels from Marigold-V2; images from Flickr8k (CC-licensed). Please cite/attribute the upstream datasets and models accordingly.