KirubaLS's picture
Organize ParcelGuard and document methodology and real inference diagnostics
4cf5f4e verified
|
Raw History Blame Contribute Delete
3.91 kB

ParcelGuard Methodology

1. Objective

ParcelGuard explores reference-guided visual anomaly detection for parcel and packaging inspection.

A query image is compared with reference images representing the expected appearance of the item. Spatial feature discrepancies are used to produce an image-level anomaly score.

This is an exploratory research prototype, not a production-validated defect detection system.

2. Feature Extraction

The current baseline uses ResNet18.

Input images are:

  • Converted to RGB
  • Resized to 224 x 224
  • Converted to tensors
  • Normalized using ImageNet mean and standard deviation

The feature extractor consists of the ResNet18 stem, Layer1 and Layer2.

The final feature map has:

  • Channels: 128
  • Height: 28
  • Width: 28

Layer1 and Layer2 multi-scale experiments are documented separately in the results directory.

3. Spatial Cosine Distance

For query feature vector q at spatial position (u,v) and reference feature vector r at the same position:

distance(u,v) = 1 - cosine_similarity(q(u,v), r(u,v))

The comparison is performed at corresponding spatial coordinates.

The current baseline does not geometrically align query and reference images before comparing their feature maps.

4. Reference Aggregation

For multiple reference images, the baseline calculates a distance map for each reference and takes the minimum distance at each spatial location:

anomaly_map(u,v) = min(distance_reference_i(u,v))

This allows one close reference to explain a query region.

Minimum, mean and median aggregation have also been investigated experimentally. Their results are available under:

results/reference_analysis/

5. Image-Level Anomaly Score

The baseline calculates the 95th percentile of the spatial anomaly map:

anomaly_score = percentile(anomaly_map, 95)

The provisional classification threshold is 0.70.

score >= 0.70  -> DEFECT
score < 0.70   -> NORMAL

This threshold is exploratory and has not been validated on an independent holdout dataset.

6. Heatmap and Projection

The 28 x 28 anomaly map is resized to the original image dimensions for visualization.

A color heatmap is blended with the original image.

Top-percentile feature-map locations can also be projected onto the original image using their grid-cell centres.

These projections are approximate visual explanations. They are not pixel-accurate defect segmentation masks.

7. Multi-Scale Experiments

Layer1 and Layer2 feature maps were evaluated using different reference aggregation and spatial scoring strategies.

Rank fusion was explored to combine complementary anomaly rankings.

The selected fusion experiments are exploratory because candidate selection used the same 100 labelled queries.

See:

results/multiscale/
results/reference_analysis/

8. Known Limitations

  • Only 100 labelled query images were used in the primary sample.
  • No independent holdout or external validation has been completed.
  • Spatial comparison is sensitive to viewpoint and image alignment.
  • Reference images can differ in orientation and object placement.
  • Image-level anomaly scores do not provide verified damage localization.
  • The threshold is provisional.
  • Heatmap intensity is not a calibrated defect probability.
  • Production latency, throughput and robustness have not been established.

9. Current Research Direction

Future work should prioritize:

  • Independent evaluation data.
  • Robust query-reference alignment.
  • Viewpoint-aware feature comparison.
  • Verified defect localization.
  • Per-class error analysis.
  • Reproducible inference benchmarking.

10. Dataset

Experiments use a 100-query sample from the Kaputt dataset with 288 reference images.

Original dataset images are excluded from this repository. Users must obtain the dataset from its official source and comply with the applicable license and additional terms.