Views
No views yet
torch, torchvision, transformers and PIL have to be installed):1import torch
2from PIL import Image
3import torchvision
4
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6
7anomalyvfm = torch.hub.load("MaticFuc/AnomalyVFM", "anomalyvfm_siglip2", trust_remote_code=True, force_reload=True).to(device) # Possible options: "anomalyvfm_radio", "anomalyvfm_dinov2", "anomalyvfm_clip" and "anomalyvfm_siglip2", more to be added
8img_trf = anomalyvfm.model.get_img_transform()
9
10image = Image.open("test.png").convert("RGB")
11image = image_trf(image).unsqueeze(0).to(device)
12with torch.no_grad():
13 score, mask = anomalyvfm(image)
14
15print(f"Anomaly Score: {score.item():.4f}")
16torchvision.utils.save_image(mask.float(), "pred.png")pred.png.1@InProceedings{fucka2026anomaly_vfm,
2 title={AnomalyVFM -- Transforming Vision Foundation Models into Zero-Shot Anomaly Detectors},
3 author={Fučka, Matic and Zavrtanik, Vitjan and Skočaj, Danijel},
4 booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
5 month = {June},
6 year = {2026}
7}