enhancesd-v6-model / README.md
matthewcodes's picture
Correct channel 10: it is a distrust mask, not a validity/confidence mask
565ec4a verified
|
Raw History Blame Contribute Delete
6.07 kB
metadata
license: openrail++
tags:
  - image-to-image
  - game-graphics
  - real-time
  - knowledge-distillation
library_name: pytorch
pipeline_tag: image-to-image

EnhanceSD v6

A small feed-forward network that restyles rendered game frames toward the look of body-worn camera footage: camera colour response, sensor grain and codec blocking, with the scene's geometry left intact.

23,111,107 parameters. Designed to run inside a frame budget, not offline.

What it does

Given a rendered frame plus the buffers a renderer already has, it outputs the same scene with a camera's character applied. It changes tone, colour, grain and compression texture. It does not change geometry, and it does not invent objects, signage or lighting that were not in the input.

Trained on interior and night exterior scenes from a single title. It has not been evaluated on other content.

Inputs and outputs

input [N, 11, H, W], float in [0,1]
output [N, 3, H, W], float in [0,1]

The 11 input channels, in order:

channels meaning
0–2 linear-ish RGB of the current frame
3 linearised depth
4–6 view-space normals derived from depth, encoded [-1,1] -> [0,1]
7–9 previous output, warped into the current frame by optical flow
10 how far to distrust that warped history (1 = unusable, 0 = trust it)

Channel 10 is a distrust signal, not a confidence: it is the union of every reason the warped history is wrong at a pixel β€” colour mismatch, depth mismatch, implausible flow, and UI overlay β€” so 1 means do not use the history there. Getting this backwards feeds the network garbage exactly where the history is least reliable, and it will not fail loudly.

On the first frame of a sequence, or after a reset, set channels 7–9 to the current colour and channel 10 to 1 β€” there is no history yet, so all of it is to be distrusted.

The output is a residual on the input colour with a straight-through clamp, so an untrained network is an exact passthrough and a saturated pixel can still recover during training.

Results

Measured on three held-out sequences from a level never seen in training. KID is computed against real photographs, so lower is closer to photographic; the identity row is the input frame with no model applied.

KID ↓ mean absolute change
identity (no model) 0.394 0
EnhanceSD v6 0.136 0.0329

A 2.9Γ— reduction in KID against real photographs.

Per sequence: 0.140 / 0.067 / 0.201, against an identity baseline of 0.596 / 0.139 / 0.448.

How it was trained

Adversarial distillation from a diffusion teacher. Targets were built in three stages, each chosen so that what the student has to learn is something a per-pixel network actually can learn:

  1. Content and lighting β€” a photoreal SDXL checkpoint (RealVisXL V5) run as img2img with a depth ControlNet at strength 0.60, so scene structure is held by both the initialisation and the depth map.
  2. Camera character β€” signal-dependent sensor grain, then real libx264 encoding per sequence at CRF 22, so the targets carry genuine inter-frame prediction, deblocking and ringing rather than an imitation of them. Grain goes on before the codec, following the real signal path.
  3. Colour and microcontrast β€” matched to statistics measured from real body-worn camera footage, conditioned on lightness band.

The student is trained with an adversarial term whose "real" examples are the teacher's own output at the same frame and the same crop, plus a perceptual term, a band-split pixel loss and a low-frequency colour anchor.

Why the grade is conditioned on lightness

Matching whole-image colour statistics between two sets of footage compares their content as much as their cameras. The reference footage is daylight; the training scenes are night. A global contrast match produced a 1.68Γ— stretch which, on a night scene, can only be achieved by crushing the blacks β€” that run scored 0.191 KID, worse than doing nothing to the colour at all.

Measured per lightness band the picture is different and physical: real footage carries less local detail in deep shadow (Γ—0.73) and much less in clipped highlights (Γ—0.43), and slightly more in the midtones β€” which is what a small sensor does. Applying that per band instead gave the 0.136 above. Same model, same parameter count, same pipeline; only the confound control differed.

Limitations

  • Tone, colour, grain and compression only. No lens distortion, no auto-exposure behaviour, no overlay. Lens warp in particular is not learnable by this network: convolution is translation-equivariant, so without positional input it cannot produce a position-dependent displacement.
  • Trained on one game, mostly night scenes. Daylight and other titles are untested.
  • No runtime parity test. The weights have not been validated against a shader implementation, so this is a reference model rather than a deployable one.
  • mean absolute change is a magnitude, not a quality measure. An earlier run scored 2.7Γ— the change of this one and was the worst model by KID.

Usage

import torch
from safetensors.torch import load_file
from model import Student           # included in this repo

net = Student(width=32, depth=5, spectral=True, width0=64, in_ch=11)
net.load_state_dict(load_file("enhancesd_v6.safetensors"))
net.eval()

x = torch.rand(1, 11, 288, 512)     # see the input table above
with torch.no_grad():
    y = net(x)                      # [1, 3, 288, 512]

training_config.json records the full training configuration, including every loss weight and the stability settings.

Licensing

Weights are distilled from the output of RealVisXL V5 (openrail++), so this model is released under the same terms. The colour and contrast statistics were measured from publicly released body-worn camera footage; no footage, frames or crops are included in this repository.