Update README.md
Browse files
README.md
CHANGED
|
@@ -7,65 +7,257 @@ tags:
|
|
| 7 |
- experimental
|
| 8 |
---
|
| 9 |
|
| 10 |
-
# ParcelGuard
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
It extracts ResNet18 spatial features, calculates cosine-distance anomaly maps,
|
| 18 |
-
and returns a provisional defect decision with a visual overlay.
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
3. Extract intermediate spatial features.
|
| 25 |
-
4. Compare query features against each reference at corresponding locations.
|
| 26 |
-
5. Take the minimum distance across references at each location.
|
| 27 |
-
6. Calculate the 95th percentile anomaly score.
|
| 28 |
-
7. Compare the score with an exploratory threshold of 0.70.
|
| 29 |
-
8. Return a predicted label and anomaly heatmap overlay.
|
| 30 |
|
| 31 |
-
##
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
The P95 score achieved approximately 0.684 ROC-AUC in an exploratory comparison.
|
| 45 |
|
| 46 |
-
|
| 47 |
-
This threshold has not been validated on a separate held-out dataset.
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
- A demonstrated defective sample was classified as NORMAL at threshold 0.70.
|
| 53 |
-
- Heatmaps can highlight packaging, reflections, texture, and alignment differences.
|
| 54 |
-
- Heatmaps are anomaly estimates, not verified defect segmentation masks.
|
| 55 |
-
- The current spatial comparison does not robustly handle different product views.
|
| 56 |
-
- No independent held-out test result is claimed.
|
| 57 |
-
- This project is experimental and is not production validated.
|
| 58 |
|
| 59 |
-
##
|
| 60 |
|
| 61 |
-
|
| 62 |
-
terms and any applicable model/artifact licensing obligations before redistribution
|
| 63 |
-
or commercial use. Original dataset images are not included in this repository.
|
| 64 |
|
| 65 |
-
The
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
## Reproducibility
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
- experimental
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# ParcelGuard: Reference-Guided Parcel Defect Detection
|
| 11 |
|
| 12 |
+
**ParcelGuard** is an exploratory computer-vision project that
|
| 13 |
+
investigates detecting parcel and packaging anomalies by comparing a
|
| 14 |
+
query image with reference images of the expected item.
|
| 15 |
|
| 16 |
+
> **Status:** Research prototype. The reported experiments use a
|
| 17 |
+
> 100-query sample from the Kaputt dataset. Results are preliminary;
|
| 18 |
+
> independent holdout and external validation are pending.
|
| 19 |
|
| 20 |
+
## Problem
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
A parcel may differ from its references because of damage, packaging
|
| 23 |
+
changes, viewpoint, orientation, lighting, or capture variation.
|
| 24 |
+
ParcelGuard explores spatial feature comparison between query and
|
| 25 |
+
reference images to produce an image-level anomaly ranking.
|
| 26 |
|
| 27 |
+
The current prototype evaluates query-level defect ranking. It does not
|
| 28 |
+
claim pixel-accurate damage segmentation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
## Dataset
|
| 31 |
|
| 32 |
+
Experiments use a 100-query sample from the Kaputt parcel-damage
|
| 33 |
+
dataset.
|
| 34 |
|
| 35 |
+
Component Count
|
| 36 |
+
------------------------- -------
|
| 37 |
+
Query images 100
|
| 38 |
+
Reference images 288
|
| 39 |
+
Unique item identifiers 100
|
| 40 |
+
Normal queries 63
|
| 41 |
+
Defective queries 37
|
| 42 |
|
| 43 |
+
There are 1--3 references per query; 92 queries have three references.
|
| 44 |
|
| 45 |
+
The dataset masks were inspected, but their semantic classes have not
|
| 46 |
+
been authoritatively verified as defect masks. Mask-derived region
|
| 47 |
+
experiments are therefore exploratory.
|
|
|
|
| 48 |
|
| 49 |
+
### Dataset access and licensing
|
|
|
|
| 50 |
|
| 51 |
+
Obtain the dataset from its official source and follow its applicable
|
| 52 |
+
license. The project research notes identify **CC BY-NC-ND 4.0 with
|
| 53 |
+
additional/superseding terms**; consult the original terms directly,
|
| 54 |
+
especially before redistribution or commercial use.
|
| 55 |
|
| 56 |
+
Original dataset images are intentionally excluded from this repository.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
## Method
|
| 59 |
|
| 60 |
+
### Feature extraction
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
The feature backbone is ResNet18. Intermediate spatial feature maps are
|
| 63 |
+
extracted at two scales for a 224 × 224 input:
|
| 64 |
+
|
| 65 |
+
Feature level Channels Spatial resolution
|
| 66 |
+
--------------- ---------- --------------------
|
| 67 |
+
Layer1 64 56 × 56
|
| 68 |
+
Layer2 128 28 × 28
|
| 69 |
+
|
| 70 |
+
### Spatial query-reference comparison
|
| 71 |
+
|
| 72 |
+
For query feature vector (q\_{u,v}) and reference feature vector
|
| 73 |
+
(r\_{u,v}) at spatial location ((u,v)), cosine distance is:
|
| 74 |
+
|
| 75 |
+
\[ d\_{u,v}=1-`\frac{q_{u,v}\cdot r_{u,v}}`{=tex}
|
| 76 |
+
{\|q\_{u,v}\|*2\|r*{u,v}\|\_2} \]
|
| 77 |
+
|
| 78 |
+
Distances are calculated at corresponding spatial coordinates. The
|
| 79 |
+
current method does not geometrically register query and reference
|
| 80 |
+
images, so viewpoint, orientation, and alignment differences may
|
| 81 |
+
influence anomaly maps.
|
| 82 |
+
|
| 83 |
+
### Reference aggregation
|
| 84 |
+
|
| 85 |
+
Spatial distance maps from multiple references are combined using:
|
| 86 |
+
|
| 87 |
+
- **Minimum:** smallest distance at each spatial location.
|
| 88 |
+
- **Mean:** average distance across references.
|
| 89 |
+
- **Median:** median distance across references.
|
| 90 |
+
|
| 91 |
+
These represent different assumptions about how multiple references
|
| 92 |
+
should explain a query.
|
| 93 |
+
|
| 94 |
+
### Spatial aggregation
|
| 95 |
+
|
| 96 |
+
The resulting distance map is reduced to an image-level score using its
|
| 97 |
+
spatial mean or 95th percentile (P95). P95 emphasizes locations with
|
| 98 |
+
relatively high discrepancy. These scores are ranking signals, not
|
| 99 |
+
calibrated defect probabilities.
|
| 100 |
+
|
| 101 |
+
### Multi-scale rank fusion
|
| 102 |
+
|
| 103 |
+
Exploratory fusion combines anomaly-score rankings from different
|
| 104 |
+
feature levels:
|
| 105 |
+
|
| 106 |
+
\[ S\_{`\mathrm{fusion}`{=tex}} =
|
| 107 |
+
`\frac{1}{2}`{=tex}`\left`{=tex}(`\operatorname{rank}`{=tex}(S_1)+`\operatorname{rank}`{=tex}(S_2)`\right`{=tex})
|
| 108 |
+
\]
|
| 109 |
+
|
| 110 |
+
Rank fusion avoids directly combining raw scores with potentially
|
| 111 |
+
different scales.
|
| 112 |
+
|
| 113 |
+
## Experimental Results
|
| 114 |
+
|
| 115 |
+
### Selected experiments on 100 queries
|
| 116 |
+
|
| 117 |
+
Method ROC-AUC Average Precision
|
| 118 |
+
----------------------------------------- ------------ -------------------
|
| 119 |
+
ResNet18 Layer2 baseline, unaligned P95 0.6838 0.5821
|
| 120 |
+
Layer1, minimum-reference mean 0.7044 0.5723
|
| 121 |
+
Layer2, minimum-reference P95 0.6860 0.6009
|
| 122 |
+
Layer1 + baseline rank fusion **0.7381** **0.6270**
|
| 123 |
+
Three-score rank fusion 0.7293 0.6154
|
| 124 |
+
|
| 125 |
+
The two-score fusion was the strongest selected exploratory candidate on
|
| 126 |
+
this sample. However, candidate selection used the same labels, so its
|
| 127 |
+
apparent advantage is subject to model-selection bias.
|
| 128 |
+
|
| 129 |
+
A repeated stratified 5-fold evaluation (5 repeats) of fixed score
|
| 130 |
+
vectors gave these descriptive averages:
|
| 131 |
+
|
| 132 |
+
Method Mean ROC-AUC Mean AP
|
| 133 |
+
-------------------------- -------------- ------------
|
| 134 |
+
Baseline 0.6840 0.6341
|
| 135 |
+
Layer1 0.7024 0.6275
|
| 136 |
+
Layer1 + baseline fusion **0.7361** **0.6619**
|
| 137 |
+
|
| 138 |
+
These folds reuse the same 100 queries. They are not independent
|
| 139 |
+
experiments or external validation; candidate selection also used this
|
| 140 |
+
dataset.
|
| 141 |
+
|
| 142 |
+
### Reference aggregation on the 92 queries with three references
|
| 143 |
+
|
| 144 |
+
Layer Reference aggregation Spatial score ROC-AUC AP
|
| 145 |
+
-------- ----------------------- --------------- ------------ ------------
|
| 146 |
+
Layer2 Median P95 **0.7075** 0.5541
|
| 147 |
+
Layer1 Mean P95 0.7059 0.5398
|
| 148 |
+
Layer1 Median P95 0.7059 0.5494
|
| 149 |
+
Layer1 Minimum P95 0.7048 0.5384
|
| 150 |
+
Layer1 Minimum Mean 0.7043 0.5271
|
| 151 |
+
Layer2 Mean P95 0.6801 0.5321
|
| 152 |
+
Layer2 Minimum P95 0.6763 **0.5581**
|
| 153 |
+
|
| 154 |
+
Rank-fusion comparison on the same 92 queries:
|
| 155 |
+
|
| 156 |
+
Method ROC-AUC AP
|
| 157 |
+
------------------------------------------- ------------ ------------
|
| 158 |
+
Layer1 + Layer2 median-P95 rank fusion **0.7148** 0.5281
|
| 159 |
+
Layer2 median-P95 0.7075 **0.5541**
|
| 160 |
+
Layer1 + Layer2 minimum-based rank fusion 0.7065 0.5224
|
| 161 |
+
Layer1 median-P95 0.7059 0.5494
|
| 162 |
+
|
| 163 |
+
The best ROC-AUC and best AP belong to different methods. Both metrics
|
| 164 |
+
are reported because they capture different aspects of ranking quality.
|
| 165 |
+
|
| 166 |
+
**Do not directly compare the 92-query results with the 100-query
|
| 167 |
+
results as if they used the same evaluation population.**
|
| 168 |
+
|
| 169 |
+
## Additional Ablations
|
| 170 |
+
|
| 171 |
+
The project also explores:
|
| 172 |
+
|
| 173 |
+
- **Reference position:** reference 3 had higher individual ROC-AUC
|
| 174 |
+
than reference 1 in this sample.
|
| 175 |
+
- **Reference removal:** excluding reference 1 and retaining
|
| 176 |
+
references 2 and 3 improved some scores in a three-reference subset.
|
| 177 |
+
- **Reference consistency:** pairwise reference disagreement was not
|
| 178 |
+
strongly associated with defect labels.
|
| 179 |
+
- **Region-aware scoring:** mask-derived product and
|
| 180 |
+
surrounding-region scores did not consistently improve over
|
| 181 |
+
multi-scale fusion.
|
| 182 |
+
- **Feature complementarity:** Layer1 and baseline rankings showed
|
| 183 |
+
modest correlation, suggesting they may contain different ranking
|
| 184 |
+
information.
|
| 185 |
+
|
| 186 |
+
Reference positions are row-order positions, not established semantic
|
| 187 |
+
roles. These observations do not justify hardcoding a reference position
|
| 188 |
+
to discard.
|
| 189 |
+
|
| 190 |
+
## Limitations
|
| 191 |
+
|
| 192 |
+
1. Only 100 labelled queries are used in the primary experiments.
|
| 193 |
+
2. Repeated experimentation and candidate selection used the same
|
| 194 |
+
sample; selection bias is possible.
|
| 195 |
+
3. No independent holdout or external dataset validation has been
|
| 196 |
+
completed.
|
| 197 |
+
4. Query and reference features are compared at corresponding
|
| 198 |
+
coordinates without geometric registration.
|
| 199 |
+
5. Reported metrics evaluate image-level ranking, not defect
|
| 200 |
+
localization accuracy.
|
| 201 |
+
6. Viewpoint, orientation, reference count, and reference variability
|
| 202 |
+
can affect anomaly scores.
|
| 203 |
+
7. Scores are not calibrated probabilities.
|
| 204 |
+
8. Latency, throughput, monitoring, and deployment robustness have not
|
| 205 |
+
been established.
|
| 206 |
+
|
| 207 |
+
Results should be interpreted as exploratory research findings, not
|
| 208 |
+
production performance.
|
| 209 |
+
|
| 210 |
+
## Repository Contents
|
| 211 |
+
|
| 212 |
+
The uploaded project artifacts include implementation code, notebooks,
|
| 213 |
+
ResNet18 checkpoint(s), multi-scale scoring experiments, reference
|
| 214 |
+
aggregation and fusion comparisons, reference consistency/removal
|
| 215 |
+
analyses, region-aware experiments, and CSV result files, where present.
|
| 216 |
+
|
| 217 |
+
The original Kaputt images and generated multiscale feature cache are
|
| 218 |
+
excluded. Exact filenames may evolve as the repository is organized.
|
| 219 |
|
| 220 |
## Reproducibility
|
| 221 |
|
| 222 |
+
A reproducible run requires:
|
| 223 |
+
|
| 224 |
+
1. Python and compatible versions of PyTorch, torchvision, NumPy,
|
| 225 |
+
pandas, scikit-learn, and the other dependencies used by the
|
| 226 |
+
notebooks.
|
| 227 |
+
2. Access to Kaputt under its applicable license.
|
| 228 |
+
3. Project code, notebooks, and required checkpoint(s) from this
|
| 229 |
+
repository.
|
| 230 |
+
4. Dataset paths configured for the local environment.
|
| 231 |
+
|
| 232 |
+
Development and experiments were run in Google Colab with a Tesla T4
|
| 233 |
+
GPU. Record exact dependency versions and execution details with future
|
| 234 |
+
benchmark runs.
|
| 235 |
+
|
| 236 |
+
## Next Steps
|
| 237 |
+
|
| 238 |
+
- Freeze candidate methods and a pre-defined evaluation protocol.
|
| 239 |
+
- Obtain additional labelled data or establish a genuinely independent
|
| 240 |
+
evaluation set.
|
| 241 |
+
- Compare all candidates on the same pre-defined split.
|
| 242 |
+
- Report confidence intervals and per-class error analysis.
|
| 243 |
+
- Investigate geometric alignment and viewpoint-aware feature
|
| 244 |
+
comparison.
|
| 245 |
+
- Evaluate localization using verified pixel-level annotations.
|
| 246 |
+
- Measure inference latency, memory use, and operational robustness
|
| 247 |
+
before considering deployment.
|
| 248 |
+
|
| 249 |
+
## Acknowledgements
|
| 250 |
+
|
| 251 |
+
This project uses the Kaputt dataset for research and experimentation.
|
| 252 |
+
Consult the dataset's official publication and license for attribution
|
| 253 |
+
requirements.
|
| 254 |
+
|
| 255 |
+
------------------------------------------------------------------------
|
| 256 |
+
|
| 257 |
+
**Project status:** Active research prototype\
|
| 258 |
+
**Primary task:** Reference-guided visual anomaly ranking for parcel
|
| 259 |
+
inspection\
|
| 260 |
+
**Backbone:** ResNet18\
|
| 261 |
+
**Evaluation sample:** 100 queries, including a 92-query three-reference
|
| 262 |
+
subset\
|
| 263 |
+
**Validation status:** Exploratory; independent validation pending
|