stfpm_mvtec_capsule / README.md
Alexander Suslov
added sftpm model fine-tuned on capsule category of the MVTec dataset
98f2c2f
|
raw
history blame
2.61 kB
metadata
license: apache-2.0

SFTPM model from Anomalib fine-tuned for capsule category of the MVTec dataset. Checkpoint trained using the following notebook.

──────────────────────────────────────────────────
       Test metric             DataLoader 0
──────────────────────────────────────────────────
       image_AUROC          0.8436378240585327
      image_F1Score         0.9356223344802856
       pixel_AUROC          0.9719913601875305
      pixel_F1Score         0.41566985845565796
──────────────────────────────────────────────────

The main intent is to use it in samples and demos for model optimization. Here is the advantages:

  • MVTec dataset can automatically downloaded and is quite small.
  • The model from the anomaly detection domain such as SFTPM is sensitive to the optimization methods to allows demonstrate methods with accuracy controll.

Here is the code to test the checkpoint:

from pytorch_lightning import Trainer
from anomalib.config import get_configurable_parameters
from anomalib.data import get_datamodule
from anomalib.models import get_model
from anomalib.utils.callbacks import LoadModelCallback, get_callbacks

CHECKPOINT_URL = 'https://huggingface.co/alexsu52/sftpm_mvtec_capsule/resolve/main/pytorch_model.bin'
CHECKPOINT_PATH = '~/pytorch_model.bin'

#Download CHECKPOINT_URL to CHECKPOINT_PATH

config = get_configurable_parameters(config_path="./anomalib/models/sftpm/config.yaml")
config["dataset"]["path"] = <path_to_dataset>
config['dataset']['category'] = 'capsule'

datamodule = get_datamodule(config)
datamodule.setup()  # Downloads the dataset if it's not in the specified `root` directory
datamodule.prepare_data()  # Create train/val/test/prediction sets.

model = get_model(config)

callbacks = get_callbacks(config)
load_model_callback = LoadModelCallback(weights_path=CHECKPOINT_PATH)
callbacks.insert(0, load_model_callback)

trainer = Trainer(**config.trainer, callbacks=callbacks)
trainer.test(model=model, datamodule=datamodule)