Skip to content

Build and train configurable anomaly detectors from YAML - #4

Merged
yxteo2 merged 3 commits into
mainfrom
feat/yaml-model-builder
Sep 10, 2026
Merged

yxteo2 merged 3 commits into
mainfrom
feat/yaml-model-builder

Conversation

@yxteo2

@yxteo2 yxteo2 commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Summary

Add a YAML-first experiment builder for the supported anomaly detectors:

  • choose ResNet-18, ResNet-34 or Wide-ResNet-50-2 and FastFlow or SSN
  • select FastFlow NLL, SSN focal + truncation, or SSN BCE; configure compatible loss parameters
  • configure model parameters, dataset, epochs, batch size, learning rate, device, seed, validation thresholds and named output runs
  • validate safely before constructing/downloading models, including duplicate/unknown keys and incompatible choices
  • preserve the existing CLI and inference checkpoint metadata
  • save reloadable resolved YAML and experiment settings with checkpoints, and require opt-in for overwriting outputs
  • wire SSN optimizer settings through, and avoid epoch-zero LR decay on short runs

Run

Edit the dataset location/category, then:

python -m pip install -r requirements.txt
python train.py --config configs/fastflow.yaml --check-config
python train.py --config configs/fastflow.yaml
# Equivalent package entry point:
python -m anomaly_detection --config configs/ssn.yaml

Examples: configs/fastflow.yaml, configs/ssn.yaml, configs/ssn_bce.yaml. Full reference: docs/yaml_training.md.

Verification

  • 70 tests passed locally on CPU, including the existing seven regressions
  • real one-epoch YAML training, validation-only calibration and final evaluation for all three model/loss combinations (ResNet-18, random initialization, tiny synthetic MVTec fixtures)
  • selected loss calls and effective optimizer learning rates/weight decay verified
  • checkpoints reloaded through both existing inference engines
  • syntax compilation, pyflakes and git diff --check passed
  • GitHub Actions runs the same offline suite

These are software correctness smoke tests, not real-dataset accuracy benchmarks or GPU validation.

Dependency / merge order

This is a stacked PR targeting refactor/package-layout, so the diff contains only the new feature. It depends on the organization work in #3. Merge #3 first and retarget this PR to main before merging this feature. Neither PR has been merged by this change.

Move dataset, model, and trainer implementations under anomaly_detection; remove the obsolete duplicate SSN trainer from the FastFlow module; and update imports, tests, and documentation.
Add a strict safe configuration schema, model/loss factories and shared training runner. Support configurable FastFlow NLL and SSN focal/BCE losses, honor SSN optimizer settings, save resolved experiments, preserve inference compatibility, and prevent accidental output overwrites.

Include three example configs, documentation and offline tests covering YAML validation, real one-epoch CPU training, calibration and inference reloads.
@yxteo2
yxteo2 changed the base branch from refactor/package-layout to main September 10, 2026 00:38
…r files

Main tree equals the original package-layout base. Preserve the exact tested feature tree while reconciling the squash-merge ancestry.
@yxteo2
yxteo2 merged commit c40788a into main Sep 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant