Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ losses, fitting behavior, runnable examples and differences from the papers.
| `anomaly_detection/pipeline.py` | Shared experiment lifecycle |
| `anomaly_detection/smoke.py` | Synthetic training/reload and CUDA peak-memory checks |
| `anomaly_detection/predict.py` | Shared checkpoint reload and single-image prediction |
| `anomaly_detection/preprocessing.py` | Shared resize, center crop, normalization and mask geometry |
| `anomaly_detection/inference_utils.py` | Shared inference metrics, calibration and file helpers |
| `anomaly_detection/training/accumulation.py` | Sample-weighted gradient accumulation |
| `configs/` | Ready-to-edit YAML experiments for all five detectors |
| `docs/yaml_training.md` | YAML options, supported combinations and extension guide |
| `docs/gpu_memory.md` | DINOv2, larger inputs and GPU memory configuration |
| `tests/` | Regression tests for evaluation and model behavior |

See the [repository maintenance guide](docs/repository_layout.md) for file roles,
compatibility entry points and generated-file conventions.

## Installation

Use Python 3.10 or newer. Install a PyTorch build compatible with your CUDA
Expand Down Expand Up @@ -120,6 +125,10 @@ Existing run folders require a new `--run_name` or explicit `--overwrite`.

## Inference

For all five YAML-built detectors, use the shared command in the
[inference and preprocessing guide](docs/inference.md). It reads the saved
training crop settings and optionally returns source-size maps with valid-region masks.

New checkpoints automatically provide their model configuration. Inference
also automatically loads `calibration.json` from the checkpoint directory:

Expand Down
24 changes: 15 additions & 9 deletions anomaly_detection/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
Factories are explicit allowlists: YAML never imports or executes arbitrary code.
"""

from anomaly_detection.config import resolve_config
from anomaly_detection.modeling import FastFlowModel, SuperSimpleNetModel
from anomaly_detection.config import MODEL_PARAMS, resolve_config
from anomaly_detection.modeling import (
DinomalyModel, FastFlowModel, PadimModel, PatchcoreModel, SuperSimpleNetModel,
)
from anomaly_detection.training import FastFlowTrainer, SuperSimpleNetTrainer
from anomaly_detection.training.losses import FastFlowNLLLoss, SSNBCELoss, SSNLoss, SSNBCEDiceLoss, SSNFocalDiceLoss
from anomaly_detection.modeling.feature_heads import PadimModel, PatchcoreModel, DinomalyModel
from anomaly_detection.training.losses import (
FastFlowNLLLoss, SSNBCEDiceLoss, SSNBCELoss, SSNFocalDiceLoss, SSNLoss,
)
from anomaly_detection.training.feature_heads import FeatureHeadTrainer, ReconstructionLoss


MODEL_BUILDERS = {"fastflow": FastFlowModel, "ssn": SuperSimpleNetModel}
MODEL_BUILDERS.update(padim=PadimModel, patchcore=PatchcoreModel, dinomaly=DinomalyModel)
LOSS_BUILDERS = {"fastflow_nll": FastFlowNLLLoss, "ssn_focal": SSNLoss, "ssn_bce": SSNBCELoss}
LOSS_BUILDERS.update(ssn_bce_dice=SSNBCEDiceLoss, ssn_focal_dice=SSNFocalDiceLoss)
MODEL_BUILDERS = {
"fastflow": FastFlowModel, "ssn": SuperSimpleNetModel,
"padim": PadimModel, "patchcore": PatchcoreModel, "dinomaly": DinomalyModel,
}
LOSS_BUILDERS = {
"fastflow_nll": FastFlowNLLLoss, "ssn_focal": SSNLoss, "ssn_bce": SSNBCELoss,
"ssn_bce_dice": SSNBCEDiceLoss, "ssn_focal_dice": SSNFocalDiceLoss,
}


def model_kwargs(cfg):
Expand All @@ -34,7 +41,6 @@ def model_kwargs(cfg):
kwargs.update({key: cfg[key] for key in ("perlin_threshold", "layers", "adapt_cls_features")})
kwargs["stop_grad"] = True
else:
from anomaly_detection.config import MODEL_PARAMS
kwargs.pop("feature_channels")
kwargs.update({key: cfg[key] for key in MODEL_PARAMS[cfg["model"]]})
return kwargs
Expand Down
Loading
Loading