Second Light · 第二束光

Research models for one question in visual inspection: does a surface flaw survive a change of lighting? They work on fixed-camera photographs of manufactured parts from the public M²AD dataset, where each part is photographed under ten lighting presets.

  • Relight. Predict the same view under presets that were not photographed, from one photo (v3) or four (v2 Edge).
  • Locate. From four real photos, decide whether to raise an alarm and return the single most likely flaw pixel (v3).

Try it in the browser · 中文 · v3 CPU example and full evaluation · v2 protocol

Status, 5 December 2026. v3 is the current release. Two later detector versions, v4 and v5, were trained and tested. Both failed release checks fixed before testing, so their weights are not published (what happened). Research use only. Not validated for industrial inspection.

Two Holder retest scratches under light 08 with matched brightening.

Released models

Task Weights Input presets Output Parameters
One-photo relighting · v3 v3/base/one-context (Holder, Cube) · v3/car/one-context (Car) 05 Presets 01–04 and 06–10 1,201,846
Four-photo relighting · v2 Edge v2/edge 05, 01, 03, 07 Presets 02, 04, 06, 08, 09 601,087
Four-photo localisation · v3 v3/{base,car}/detect-native and detect-context 05, 01, 03, 07 Alarm and peak pixel (x, y) 601,425 and 1,203,986
  • Inputs are aligned, same-view RGB images in [0, 1], 1024 × 1024 in the examples. Weights are float32 safetensors.
  • Weights are category-specific. v3/base/ serves Holder and Cube, v3/car/ serves Car. Calibration without Car training located 0 of 20 Car flaws.
  • Holder alarms use the native detector's best 32 × 32 local average. Cube and Car alarm only when both detectors exceed their thresholds, and report the context detector's peak. Final thresholds are in v3/car/decision.json. Scores are not probabilities.
  • The detector reads real photos only. It never sees a relit image or an annotation at inference.
  • v1 files at the repository root are kept for the record.
hf download sgyliu8/second-light --include "v3/*" --local-dir second-light
python second-light/v3/example.py

The example downloads four public M²AD photos of Holder/damage_2_015, writes a one-photo prediction of preset 08 and prints the four-photo alarm. Use Python 3.11+ with PyTorch, NumPy, Pillow, safetensors and huggingface_hub.

Results

Custom supervised split by category and object ID: all views and presets of one object stay together. Some annotated objects from the official test partition were used for training, so these numbers cannot be compared with the official unsupervised M²AD benchmark. Camera view A120 unless stated.

Relighting from one photo

Mean absolute RGB error (0–255) inside the flaw annotation, over nine hidden presets, averaged per part. Copy returns the input photo unchanged.

Category Material Marked parts Copy v2 v3
Holder (retest) metal 15 26.81 31.90 10.41
Cube (reused) wood 22 53.04 37.26 9.59
Car (new IDs) plastic 20 38.70 27.08 4.85

Holder error fell on 14 of 15 parts (mean 21.49, paired bootstrap 95% interval 14.29 to 29.10). It can still get worse: on exhibit damage_2_015 at preset 08, v3 error rose from 67.29 to 77.66.

Relighting from four photos · v2 Edge

Same masked error over five hidden presets. Affine is a per-channel linear mix of the four inputs plus an offset, fitted on training tiles.

Category Marked parts Affine Edge
Holder 15 9.19 2.36
Ring 20 16.59 2.16
Tube (category never seen in training) 44 33.56 20.70

Localisation from four photos · v3

A part is located when the detector raises an alarm and its single highest-scoring pixel falls inside the annotation. A false alarm is an alarm on an intact part. Fine scratches are annotations with a median width of 6 pixels or less, which is not a physical width.

Category Evidence Located False alarms Fine scratches located
Holder Retest of the v2 test parts 15/15 (v2: 9/15) 1/17 (v2: 2/17) 4/4 (v2: 1/4)
Cube Reused after the first blind test failed the false-alarm limit 16/22 1/20 none qualify
Car New IDs, sealed until the rule was fixed 7/20 0/20 2/7

On the first blind Cube test, the original rule located 17/22 with 3/20 false alarms, above the 10% limit. Requiring both detectors to alarm cut false alarms to 1/20 and cost one hit, and that rule was fixed before Car was opened. Fifteen out of fifteen still has a two-sided Wilson 95% interval of about 80% to 100%. The intervals do not cover seed or batch variation.

Training

Data. M²AD revision 05abc5d, Apache 2.0. Train / validation / test object IDs: Holder 32 / 22 / 34 plus 11 unscored exhibits, Cube 33 / 22 / 45, Car 33 / 22 / 45. The reader blocks test images until the decision file is written and checks archive fingerprints for duplicates. Physical part identity and production batch could not be verified.

v3 networks. Each category stage trains four networks: a one-photo relighter and a four-photo detector, each in two forms.

  • Context (new, trained from scratch): a 128 × 128 full-frame U-Net with coordinate channels feeding a native-resolution U-Net. Relighter 1,201,846 parameters, detector 1,203,986.
  • Native (the v2 architecture, initialised from v2): relighter 599,563 parameters, detector 601,425.

Recipe. Base training on 721 multi-light stacks cut into 7,210 native 160 × 160 tiles, including crops centred on annotations and the two highest-scoring regions of each intact stack. Car adaptation starts from the four base checkpoints and uses 347 Car stacks. Each network ran 9,000 updates in base training and 6,000 in Car adaptation, 60,000 in total, on one Tesla T4.

  • AdamW with a cosine schedule, peak learning rate 0.0012 (context) or 0.00048 (native), mixed precision, batch 12 for relighting and 16 for detection.
  • Relighting loss: robust colour and spatial-gradient errors, weighted towards annotated pixels, plus a coarse colour term. Directional flips are disabled because they would change the lighting direction.
  • Detection loss: soft Dice, focal and a penalty on hard background responses.
  • Calibration: the alarm threshold is the upper empirical 95th percentile of peak scores from 15 intact validation IDs × 3 correlated views per category.

v2 Edge. The four-photo relighter fits an affine skip on the training set and learns an additive RGB residual on top. Gradient error is weighted ×4. AdamW, cosine 0.001 → 0.00003, batch 12, 6,000 updates, predictions averaged with a horizontal flip.

Software and hashes for every run are in each run.json and sums.json. Different seeds, devices or library versions can change decisions.

Development since v3, not released

Every round below fixed its pass criteria and thresholds before the test parts were opened. None passed, so v3 remains the release.

Round Data What changed Size and training Result Decision
v4 M²AD Car (plastic, retest) and Motor (metal, new IDs) Local contrast and directional lighting-difference inputs, hard-negative mining, two detectors averaged per category 2 × 602,001 parameters per category, 10,500 updates each Car 7 → 11 of 20 located, 0/20 false alarms. Motor 24/25 located, but 2/20 intact parts alarmed near the terminals Held: the v3 weights raised no Motor false alarms, and no extra false alarms were allowed
v5 · USB Real-IAD USB connectors Request a second camera view unless the first shows a strong alarm away from the pins, simulated with existing photos 126,154 parameters, 3,600 updates on CPU Fine metal scratches 14 → 16 of 17. False alarms 5/215 both ways, 1 beside the pins both ways. 224 of 269 parts needed the second photo Held: pin false alarms did not fall
v5 · gear CSEM-MISD gears, twelve lights Thin-line network: mean intensity, light differences and local contrast, 1 × 11 and 11 × 1 convolutions 127,450 parameters per seed, 2 seeds × 3,600 updates, one T4 9 → 15 of 19 located, false alarms 2/19 both ways, pixel AP 27.3% → 25.2% Gain on single points. Most flaw outline still undetected
v5 · terminals Real-IAD D³ crimp terminals White light alone versus white light plus four single lights, both fine-tuned from the gear network 126,586 parameters, 1,800 updates Metal contamination 19 → 17 of 20. Sleeve scratches 6/10 both ways. False alarms 0 → 3 of 100 Held: more false alarms

What blocks release:

  • Textured plastic beside USB pins alarmed in both camera views. No held-out part had a confirmed scratch on bare pin metal, so masking the pin area could not be tested honestly.
  • Of 925 scratched parts in Real-IAD D³, 64 met the fine-line width rule, and none of those could be confirmed on bare metal. The gear annotations do not separate scratches from oil.
  • On D³, three median colour values taken away from any flaw separated scratched from intact terminals with ROC AUC 0.93. Capture conditions may carry class cues.

The next experiment needs multi-light photographs of the same metal terminals from two sides, with every scratch on the pin body annotated, intact parts photographed in between, and the split made by physical part and capture batch.

Real-IAD and Real-IAD D³ are gated, research-only datasets under CC BY-NC-SA 4.0. CSEM-MISD is CC BY-NC-ND 4.0. No images, crops or weights from v4 or v5 are published. Only the aggregate counts above are reported.

Limitations

  • Results come from one public dataset with small cohorts, a fixed camera and the recorded lighting presets. Lighting outside those presets was never measured.
  • Holder and Cube are reused data. Only Car was a sealed new-ID test, and it shows how much the models depend on category-specific training.
  • Thin scratches remain hard, and annotation widths are pixels on the image, not physical sizes.
  • Relit images are predictions, not measurements. Do not use them as evidence that a part is intact.
  • No human inspection or production acceptance has been run.

Originals are public for viewing and download. Contact Yang Liu for other uses. M²AD photographs retain their Apache 2.0 licence.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train sgyliu8/second-light