You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Copyright (C) 2024 Intel Corporation# SPDX-License-Identifier: Apache-2.0"""Getting Started with Anomalib Inference using the Python API.This example shows how to perform inference on a trained modelusing the Anomalib Python API."""# 1. Import required modulesfrompathlibimportPathfromanomalib.dataimportPredictDatasetfromanomalib.engineimportEnginefromanomalib.modelsimportEfficientAd# 2. Initialize the model and load weightsmodel=EfficientAd()
engine=Engine()
# 3. Prepare test data# You can use a single image or a folder of imagesdataset=PredictDataset(
path=Path("path/to/test/images"),
image_size=(256, 256),
)
# 4. Get predictionspredictions=engine.predict(
model=model,
dataset=dataset,
ckpt_path="path/to/model.ckpt",
)
# 5. Access the resultsifpredictionsisnotNone:
forpredictioninpredictions:
image_path=prediction.image_pathanomaly_map=prediction.anomaly_map# Pixel-level anomaly heatmappred_label=prediction.pred_label# Image-level label (0: normal, 1: anomalous)pred_score=prediction.pred_score# Image-level anomaly score
Activity
samet-akcay commentedon May 18, 2025
@monkeycc, you could refer to this documentation
https://anomalib.readthedocs.io/en/v2.0.0/markdown/guides/how_to/visualization/visualize_image.html