CASE STUDY / 03COMPUTER VISION / MODEL SERVING

A closer look.
A measurable signal.

InspectAI compares a bottle image with normal visual features and highlights unusual regions. A working model API connects the inspection workspace to a reproducible evaluation.

Try a live inspection Explore the source
RESEARCH PROTOTYPE Noncommercial MVTec AD bottle demo. The anomaly score is not a defect probability or a production quality guarantee.
InspectAI workspace showing an original bottle beside the model anomaly overlay and measured inspection results
A working inspection: original image, adjustable overlay, relative anomaly score, and real CPU inference timing.

01 / THE PROBLEM

Find unusual regions without fitting on defects.

A manufacturing inspection system may have many normal examples and fewer examples of what can go wrong. This project asks whether normal visual features can supply a useful review signal.

The first version focuses on one aligned bottle category. It separates a model’s anomaly signal from a human reviewer’s judgment, and keeps the original image beside the heatmap.

02 / THE MODEL

Frozen features. Normal patch memory.

PREPROCESSRGB image → 160 × 160 inputNormalize with the pretrained model’s ImageNet channel statistics.
EXTRACTFrozen ResNet18 → 20 × 20 feature gridPool and combine layer 1 and 2 features; 192 channels per patch.
COMPARENearest normal patch → anomaly field4,008 stratified random patches from 167 fitted normal images.
CALIBRATE & SERVE42 held-out normals → fixed review thresholdONNX Runtime serves the exported extractor through FastAPI.

The image score averages the three largest patch distances. Feature channels use the normal-fit standard deviation; the threshold is the 95th percentile of held-out normal image scores.

This is an independently implemented, simplified patch-memory approach inspired by normal-feature methods such as PatchCore ↗. It uses random stratified sampling, not a greedy coreset, and does not claim to reproduce the paper’s results.

03 / THE EVALUATION

One official test split. Both methods.

The 209 normal training images are split into 167 fit and 42 calibration images with seed 42. All 83 official test images—20 normal and 63 anomalous—remain outside fitting and threshold selection.

MVTec AD bottle · Recorded local CPU evaluation
MethodImage AUROCMissed defectsFalse alarms
Pixel-statistics baseline0.969812 / 630 / 20
CNN + normal patch memory0.99762 / 630 / 20

AUROC measures ranking, not percent accuracy. The primary method and its settings were fixed before examining test results. Threshold confusion counts use normal-only calibration; test labels did not choose the threshold.

Median local inference was 46.21 ms for the CNN method and 23.66 ms for the baseline, including file decoding. These are local CPU timings; network and server startup add latency.

Inspect all scores and split files

04 / THE LIMITS

Two contamination defects were missed.

The model placed contamination/003.png and contamination/019.png below the review threshold. Those are visible failures, even with a strong overall ranking score.

Zero false alarms among only 20 normal test images does not establish a zero false-alarm rate. New bottles, lighting, backgrounds and camera views are outside the measured scope.

The heatmap uses a fixed normal-calibration scale rather than stretching every image’s colors. It indicates unusual feature regions, and is not a verified segmentation mask. Pixel AUROC in the downloadable report uses masks and maps resized to 40 × 40.

The four demonstration samples are resized JPEG derivatives and are scored separately. The benchmark metrics use the original test PNGs. Independent data and camera-shift evaluation are the next steps.

05 / THE PRODUCT

From measured model to working inspection.

The FastAPI endpoint accepts bounded JPEG, PNG and WebP uploads, runs ONNX inference on CPU, and returns the review signal, anomaly heatmap and timing. Images are decoded in memory and are not persisted by the application.

The initial sample view clearly marks its saved result. Running a live inspection calls the deployed API. Review history stores metadata in the browser; users can confirm a signal, record a false alarm or missed issue, clear the history, and export JSON.

Fourteen automated checks cover artifact hashes, split separation, model calculations, real API inference and upload failures. A Dockerfile supplies a non-root container configuration; it is not presented as a tested container deployment.

DATASET ATTRIBUTION MVTec AD © 2019 MVTec Software GmbH. Dataset, displayed derivatives and normal-feature memory use CC BY-NC-SA 4.0. This is a noncommercial research demonstration.
Dataset and terms