KirubaLS commited on
Commit
1a54fc5
·
verified ·
1 Parent(s): 7c5d998

Update ParcelGuard raw-image inference pipeline

Browse files
.gitignore ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ sample-data/
2
+ metadata/
3
+ *.parquet
4
+ *.jpg
5
+ *.jpeg
6
+ *.png
7
+ *.mp4
8
+ .env
9
+ .env.*
10
+ **/__pycache__/
11
+ .ipynb_checkpoints/
MODEL_CARD.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ParcelGuard Model Card
2
+
3
+ ## Model purpose
4
+ Experimental reference-guided anomaly scoring for product images.
5
+
6
+ ## Inputs
7
+ - One query product image.
8
+ - One or more reference images for the same item.
9
+
10
+ ## Outputs
11
+ - P95 anomaly score.
12
+ - Binary label from a provisional fixed threshold.
13
+ - Spatial anomaly map and overlay.
14
+
15
+ ## Architecture
16
+ ResNet18 pretrained on ImageNet, using layer2 spatial features.
17
+ Cosine distances are computed at corresponding feature-map locations;
18
+ the minimum distance across references is used at each location.
19
+
20
+ ## Evaluation
21
+ Current sample: 100 queries, 37 defective and 63 normal.
22
+ Exploratory classifier cross-validation: balanced accuracy 0.594, ROC-AUC 0.607.
23
+ Exploratory P95-only ROC-AUC: approximately 0.684.
24
+ These are exploratory results, not a held-out benchmark.
25
+
26
+ ## Failure example
27
+ One defective sample had a P95 score of approximately 0.654 and was classified
28
+ as NORMAL using the provisional threshold of 0.70.
29
+
30
+ ## Limitations and risks
31
+ The method is sensitive to view changes, alignment, packaging, texture and lighting.
32
+ The heatmap is not verified pixel-level defect localization.
33
+ The threshold was selected on the exploratory sample and requires independent validation.
34
+
35
+ ## Intended use
36
+ Research and experimentation only. Do not use as an autonomous quality-control
37
+ decision system without rigorous validation on representative held-out data.
38
+
39
+ ## Data and licensing
40
+ The project uses the Amazon Kaputt dataset. Review its CC BY-NC-ND 4.0 terms.
41
+ No original dataset images are intentionally included in this repository.
README.md CHANGED
@@ -1,40 +1,71 @@
1
  ---
2
- title: ParcelGuard
3
- emoji: 📦
4
- colorFrom: blue
5
- colorTo: green
6
- pinned: false
 
7
  ---
8
 
9
  # ParcelGuard
10
 
11
- Reference-guided visual defect detection — experimental baseline.
12
 
13
  ## Overview
14
- ParcelGuard explores visual anomaly scoring by comparing a query product image with reference images.
15
 
16
- ## Current model
17
- The current classifier uses two precomputed features: `unaligned_mean` and `unaligned_p95`.
18
- It does not yet perform end-to-end raw-image inference.
19
 
20
- ## Exploratory evaluation
21
- - Sample size: 100 queries
22
- - Evaluation: 5-fold stratified cross-validation
23
- - Balanced accuracy: 0.591 ± 0.120
24
- - F1 score: 0.505
25
- - ROC-AUC: 0.635 ± 0.147
26
 
27
- These results are preliminary and are not evidence of production readiness.
28
- Repeated experiments on the same small sample may introduce selection bias.
 
 
 
 
 
 
29
 
30
- ## Installation
31
- Install dependencies with `pip install -r requirements.txt`.
32
 
33
- See `src/predict.py` for the feature-level prediction interface.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  ## Dataset and licensing
36
- Developed using the Amazon Kaputt dataset. Review its CC BY-NC-ND 4.0 terms before redistribution or commercial use.
37
- Original dataset images are not included in this repository.
38
 
39
- ## Limitations
40
- This is an experimental baseline. It has not been validated for real-world deployment.
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: other
3
+ tags:
4
+ - computer-vision
5
+ - anomaly-detection
6
+ - image-classification
7
+ - experimental
8
  ---
9
 
10
  # ParcelGuard
11
 
12
+ Reference-guided visual anomaly detection for product inspection.
13
 
14
  ## Overview
 
15
 
16
+ ParcelGuard compares a query product image with one or more reference images.
17
+ It extracts ResNet18 spatial features, calculates cosine-distance anomaly maps,
18
+ and returns a provisional defect decision with a visual overlay.
19
 
20
+ ## Current pipeline
 
 
 
 
 
21
 
22
+ 1. Load a query image and reference images.
23
+ 2. Resize and normalize images for ResNet18.
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
+ ## Inference
 
32
 
33
+ See `src/predict.py`. The predictor requires the saved backbone artifact
34
+ `parcelguard_resnet18_layer2.pt` and accepts image paths rather than precomputed features.
35
+
36
+ The classifier artifact is retained for feature-based experiments; the current
37
+ raw-image predictor uses the P95 anomaly score directly.
38
+
39
+ ## Exploratory results
40
+
41
+ Initial experiments used a sample of 100 query images.
42
+ The two-feature classifier achieved approximately 0.594 balanced accuracy
43
+ and 0.607 ROC-AUC in five-fold stratified cross-validation.
44
+ The P95 score achieved approximately 0.684 ROC-AUC in an exploratory comparison.
45
+
46
+ A threshold of 0.70 was selected during exploratory threshold diagnostics.
47
+ This threshold has not been validated on a separate held-out dataset.
48
+
49
+ ## Known limitations
50
+
51
+ - The dataset sample is small and results may be affected by selection bias.
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
  ## Dataset and licensing
 
 
60
 
61
+ Developed using the Amazon Kaputt dataset. Review the dataset's CC BY-NC-ND 4.0
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 repository metadata uses `license: other` because the model's redistribution
66
+ license has not been independently established here. This is not a legal conclusion.
67
+
68
+ ## Reproducibility
69
+
70
+ See `requirements.txt`, `environment.json`, `pipeline_config.json`, and the
71
+ evaluation JSON/CSV files for the current environment and experimental artifacts.
environment.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "python": "3.13.16 (main, Oct 1 2026, 15:40:24) [GCC 13.3.0]",
3
+ "numpy": "2.1.3",
4
+ "pandas": "2.2.3",
5
+ "scikit_learn": "1.6.1",
6
+ "torch": "2.11.0+cu130",
7
+ "torchvision": "0.26.0+cu130",
8
+ "joblib": "1.6.0"
9
+ }
image_extracted_features.csv ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ capture_id,item_identifier,defect,item_material,unaligned_mean,unaligned_p95,reference_count,status,error
2
+ ce1f8d1b-a92a-45ff-98d6-29a695da97b6,013aef02,1,plastic_tight_wrap,0.35627877712249756,0.6537764668464661,3,ok,
3
+ cdac9f9f-c6d2-4abd-af9e-c520e31bfa48,ef5dafc8,0,cardboard,0.3987042307853699,0.6926890015602112,3,ok,
4
+ 55fc68a8-4cce-4de5-a9e8-4c4de771f52c,317028ef,1,cardboard,0.4580015540122986,0.7062972187995911,3,ok,
5
+ 7da18730-4491-4272-8321-800320318fd5,eb63b921,1,plastic_tight_wrap,0.45774540305137634,0.7232344746589661,3,ok,
6
+ ba9c7312-6acc-4b08-8e3a-eb4d150bb94b,b62901ba,0,plastic_loose_bag,0.47890642285346985,0.6638749837875366,3,ok,
7
+ 7830db50-d449-44d1-bb90-184cd4897420,157d53f5,1,plastic_loose_bag,0.5276075601577759,0.7142903208732605,3,ok,
8
+ ed39ecbe-e0eb-4b7f-9ac9-39dc39c4be74,f6f8b5f4,1,plastic_tight_wrap,0.35759010910987854,0.599012017250061,3,ok,
9
+ 7ecb921a-6b72-4e8e-ab66-3311533795ed,191c1e75,1,cardboard,0.4579542875289917,0.7532495856285095,2,ok,
10
+ 70011413-2d26-46de-8300-23661d81f244,907c4d0f,0,book_paper,0.4046044647693634,0.705961287021637,3,ok,
11
+ 10329afd-8f47-412b-9c92-ee2c6fcf36f9,8c54ed85,0,cardboard,0.48198652267456055,0.7266709208488464,3,ok,
12
+ 1b1077bc-f398-46dd-aa5b-e03d5075394b,e65aa80b,0,plastic_loose_bag,0.4616168737411499,0.6889091730117798,3,ok,
13
+ 32316a2d-5fa9-4ed6-9ad5-b16841f8b255,b54c2e1a,1,cardboard,0.49733084440231323,0.7301851511001587,3,ok,
14
+ 66356818-317e-4cbc-aeb6-9eb11ec63296,317d6c6a,1,plastic_tight_wrap,0.5358393788337708,0.7571166157722473,3,ok,
15
+ ba9385b8-3256-4c33-b5d2-896dfaffa499,347ca3ad,0,cardboard,0.2698674201965332,0.5285285711288452,3,ok,
16
+ eaa2e987-955f-43e4-b12d-776c56509fb5,695fc44f,1,cardboard,0.4984833896160126,0.7370227575302124,2,ok,
17
+ 8f0d56eb-1f4e-42c4-9c50-a60cfb9764d7,c34aa1d6,0,plastic_hard,0.35209202766418457,0.6093997955322266,3,ok,
18
+ dd0c0ec1-e395-447c-aae1-d80d5949b3f4,fa44a1ca,1,book_paper,0.4266515374183655,0.7052961587905884,3,ok,
19
+ eba75816-8e56-4397-bdbf-10c0e9e432e1,80053258,0,plastic_tight_wrap,0.4429893493652344,0.7157601118087769,3,ok,
20
+ 0576c499-b132-4463-9da5-43a8c1fb0170,6ec62be0,0,book_paper,0.41315242648124695,0.6690501570701599,3,ok,
21
+ c4756aab-0ed7-48d6-8728-fc11999312c6,6a089d81,0,book_paper,0.4753403663635254,0.729053795337677,3,ok,
22
+ 03891eb0-8a50-4c3e-b3eb-684f1a0b2e46,ba8d493f,0,book_paper,0.4078952372074127,0.6532648205757141,3,ok,
23
+ d278cd31-1c5b-4af3-97f3-75619b84d248,ebeb5087,0,plastic_loose_bag,0.4566151797771454,0.6768727898597717,3,ok,
24
+ d7186b3e-732b-4101-9018-0f3dbb811af9,db683599,0,cardboard,0.46899858117103577,0.688582718372345,3,ok,
25
+ 7e6b7b8a-8438-4fc9-898c-b648174d8339,08b6453a,0,plastic_loose_bag,0.4941263794898987,0.7099595069885254,3,ok,
26
+ 5c508431-023f-4ced-b3aa-450e6d6b6529,d88767dd,0,plastic_tight_wrap,0.4608427584171295,0.6984899044036865,3,ok,
27
+ 10a42c0e-822c-4c04-80ae-6fd038893a01,fb079173,0,plastic_loose_bag,0.45747312903404236,0.6898187398910522,3,ok,
28
+ e3d84cfd-9925-48a8-b447-1f67080a57c6,2c0f1f1b,0,plastic_hard,0.3721645176410675,0.6253659725189209,3,ok,
29
+ 72d387e6-4381-4d90-9aa7-ac9c72021208,ca9a1f03,0,plastic_loose_bag,0.4799305200576782,0.7120817303657532,3,ok,
30
+ 77d6663d-1165-4c12-9d85-b7a6d4fc00a5,16559ccc,1,book_paper,0.2669348120689392,0.514133095741272,3,ok,
31
+ 55900370-6b66-4d52-b42c-eff4d2eebd23,cb8d0006,1,cardboard,0.38211822509765625,0.627932608127594,3,ok,
32
+ 5e8d6d4a-e0fa-4758-844c-ea7f7b7861d6,c8cf2548,0,other,0.550700306892395,0.7622522711753845,3,ok,
33
+ 8d3bc3b9-717b-4e4f-8704-196072d88535,06bbfff8,1,plastic_loose_bag,0.4524429142475128,0.6785510182380676,3,ok,
34
+ 132240a7-8489-40a6-86dd-8d0aa5a9f98a,e6370344,0,cardboard,0.4961780607700348,0.723197877407074,3,ok,
35
+ 14edea6c-66b1-4465-b4cd-22ae88ef1b3e,c0bb16a7,1,cardboard,0.5516060590744019,0.752123236656189,3,ok,
36
+ da5c26e9-2843-4e3e-8926-82d1f512cd2f,a9bc74ac,1,book_paper,0.46243923902511597,0.7098153829574585,3,ok,
37
+ 9e12d477-de43-4580-bc9a-b76c04266003,6fe6152c,0,other,0.4733660817146301,0.6963954567909241,3,ok,
38
+ 0276a193-563b-4fff-836f-4de03b65a3cf,dc6edd51,1,cardboard,0.415161669254303,0.6613745093345642,3,ok,
39
+ 665a1601-641f-4cf5-9cdb-c57e355cd162,0305f1d1,0,cardboard,0.4891031086444855,0.6879621744155884,3,ok,
40
+ 4f8c9e3d-06f5-4923-b2f0-d11c0f899d6a,bd1e1cd7,1,plastic_loose_bag,0.556549072265625,0.7656486630439758,1,ok,
41
+ 9e9cda89-00e4-430e-ab68-24762f2ac5b1,89f40e71,0,cardboard,0.3782241940498352,0.6799495220184326,3,ok,
42
+ 28382f2d-5a84-4107-83fe-42e7c3117485,ee7074d4,0,plastic_hard,0.47022581100463867,0.6701549291610718,3,ok,
43
+ 68fc5e70-9716-434d-937b-e5fac05bbf38,09b7b657,1,book_paper,0.4407956898212433,0.7079201340675354,3,ok,
44
+ 32e891de-fb61-4255-a982-9efd281e34a6,464cf483,0,book_paper,0.25827106833457947,0.5440506935119629,3,ok,
45
+ a227ac47-3d74-4142-b583-7ab4362c5692,65cc0346,0,book_paper,0.480347603559494,0.735040009021759,3,ok,
46
+ 6cf537b3-924f-450e-86fb-2e07a6c7a48a,77f9c75c,1,plastic_tight_wrap,0.46656379103660583,0.7056427597999573,3,ok,
47
+ e8810453-f791-4b0b-95f0-72ee441f7da7,3b420d44,0,cardboard,0.4937344491481781,0.6935549974441528,3,ok,
48
+ d3dd25e6-a7fe-4478-8bdd-179c1231a37e,ea315389,1,book_paper,0.1831742376089096,0.3810464143753052,3,ok,
49
+ 9731ece9-abf0-42b6-a0cc-70a54ebc0651,16804243,1,plastic_loose_bag,0.4700523316860199,0.6788854598999023,3,ok,
50
+ 14ee34b7-9977-4352-8897-5280d6ccd3a5,dbbb150c,1,book_paper,0.5300252437591553,0.8074590563774109,1,ok,
51
+ d8c33355-472f-4cbd-8588-e4fe93954d58,26ef13e6,0,book_paper,0.4794357419013977,0.7387665510177612,3,ok,
52
+ 83c4c228-e647-40ea-874a-c7bab3607b86,82b599a3,0,cardboard,0.34120458364486694,0.6153524518013,3,ok,
53
+ 6cebe214-3daf-41e2-9718-e7696f11e54d,463751e9,0,book_paper,0.5426834225654602,0.8088444471359253,1,ok,
54
+ 15244401-b21f-4419-9e74-09cb355a9ddc,7e001bec,0,plastic_loose_bag,0.4096498191356659,0.6430224180221558,3,ok,
55
+ 754fe098-360a-426c-b294-354209efe21f,be7fa075,0,plastic_loose_bag,0.359021931886673,0.6226292252540588,3,ok,
56
+ eeed7ef4-3e1e-4156-95f3-498e0f4c470f,8465c821,1,plastic_loose_bag,0.3802911937236786,0.6541786193847656,3,ok,
57
+ 4c8fa715-5e93-43da-bdd2-8b4cc28c8808,61593bca,0,cardboard,0.44609811902046204,0.7251598238945007,3,ok,
58
+ 09159dc6-7a12-4075-b0bd-1dcf9bf6ef6c,34b5e164,0,cardboard,0.39850181341171265,0.6852228045463562,3,ok,
59
+ 810d6ed9-9a75-4872-bce7-e48f0840dcdb,7aaa8d0d,0,plastic_loose_bag,0.37890446186065674,0.6603807210922241,3,ok,
60
+ 2689e621-9ad3-4ea8-8059-039477e3fe65,570e64f3,0,cardboard,0.38275861740112305,0.6769934892654419,3,ok,
61
+ 1d4e43ae-a463-4590-87ac-7fa6e8114473,9514f0c1,1,plastic_tight_wrap,0.4223305881023407,0.7097806334495544,3,ok,
62
+ 1da2fd8c-f61a-49b6-9c29-547d95548df8,c2cfdd7e,0,cardboard,0.31909629702568054,0.6552318334579468,3,ok,
63
+ aa490d01-0211-4985-aa9d-2ec4fb815062,5baf8331,0,cardboard,0.4737735688686371,0.7293909788131714,3,ok,
64
+ 7ca1b984-6504-4515-86a1-28cc8f1d127f,9761ce5e,1,plastic_loose_bag,0.43298712372779846,0.7279478907585144,2,ok,
65
+ fe219ec5-904a-4e8a-a133-df01b8f45a7b,ce533958,0,book_paper,0.24774017930030823,0.5309467911720276,3,ok,
66
+ c60afd8d-f803-4265-b0a1-333f2795085a,d2d4298c,0,plastic_loose_bag,0.43877941370010376,0.6823380589485168,3,ok,
67
+ d0c06331-e840-48fc-b739-8e85cb9835b3,7b791ee6,0,book_paper,0.40734824538230896,0.6921342015266418,3,ok,
68
+ 691f0627-afb2-46d2-965f-f760cf699e1a,dd97788d,1,plastic_loose_bag,0.44030633568763733,0.6671016216278076,3,ok,
69
+ d6bd14ba-8ee7-4db1-8580-7d46a1575dba,dd964fea,1,book_paper,0.5771564841270447,0.8264408111572266,1,ok,
70
+ 5e239334-62f0-4d41-b7a6-587306465e85,580bbb4f,1,cardboard,0.4567321538925171,0.6950039267539978,3,ok,
71
+ 20f7be26-b9c9-4ec4-877c-59519507178b,bc4186fa,1,plastic_loose_bag,0.47447431087493896,0.6924605369567871,3,ok,
72
+ 027689fb-02da-4ace-a812-1df4857a74db,6d8d11f7,0,plastic_tight_wrap,0.3265800178050995,0.5882118940353394,3,ok,
73
+ 0209d15f-f1ab-4107-97da-f076247d9bb2,2e600c6f,0,plastic_loose_bag,0.48510387539863586,0.6923578381538391,3,ok,
74
+ 6bdb1a1e-e126-460f-b7bb-0eaed9c039c5,100330bb,0,cardboard,0.4009793698787689,0.6530646085739136,3,ok,
75
+ abbcc05d-7b73-4f3a-80c9-db7acfab0ff2,3abedeec,0,plastic_hard,0.4442612826824188,0.7187825441360474,3,ok,
76
+ 8d2ee448-d6c6-4d5f-827f-1c9d37f6e429,bb8b9e03,1,book_paper,0.5187292098999023,0.7346292734146118,3,ok,
77
+ da3268de-1e49-4f42-8cab-4e01bf1743f3,0cc8e1c6,0,plastic_hard,0.3166924715042114,0.5805547833442688,3,ok,
78
+ d933b0f2-c58a-4053-885c-b38459ce0767,f0025ae4,0,book_paper,0.44616377353668213,0.7063854336738586,3,ok,
79
+ b254a0fe-6484-410c-8ce9-4d0db0d51649,ee5dbbeb,0,cardboard,0.3698452413082123,0.6864824295043945,3,ok,
80
+ f4b6c0f9-9c31-4b00-9e3c-a90756d3b859,fbaa7b25,1,book_paper,0.4505879282951355,0.7018393874168396,3,ok,
81
+ d8dd88a0-d477-431a-80e2-1bed93c4bfeb,91f53f64,0,cardboard,0.48106637597084045,0.7266586422920227,3,ok,
82
+ 3ec8cbd9-3200-4e9b-a8e7-9f695832d06f,1b108d7a,0,cardboard,0.21092282235622406,0.4809436500072479,3,ok,
83
+ 8f65ddfe-f23c-413c-b849-24b1d4637345,5476dae3,0,plastic_tight_wrap,0.3976413905620575,0.650898277759552,3,ok,
84
+ a0994f06-73d3-43fa-986a-54e0e00dcccf,529f714b,0,cardboard,0.46662506461143494,0.7039357423782349,3,ok,
85
+ 4fb0ad81-1387-4e9a-90a9-8e295a076539,703a2703,0,cardboard,0.3229234516620636,0.5796516537666321,3,ok,
86
+ 4da58afa-b2d9-4653-bd81-6063e6fcb128,38dfb39d,1,cardboard,0.40469852089881897,0.7393936514854431,2,ok,
87
+ 69bfa3d5-066d-43d0-ba2e-55227f4d63c3,8819c69a,1,plastic_tight_wrap,0.49680095911026,0.7398384213447571,3,ok,
88
+ 43065489-603f-4d9f-a4e2-e7dad256661e,8938c6cb,0,plastic_hard,0.3817671835422516,0.653298556804657,3,ok,
89
+ a806a59c-71f0-4fef-8520-34ea1b72693f,4dec693f,1,paper,0.43753886222839355,0.7035834193229675,3,ok,
90
+ 4ab03df3-6ba8-4db4-9e0c-156412d2b580,22511590,0,cardboard,0.28521838784217834,0.5342108607292175,3,ok,
91
+ a3bed498-6f1c-4d84-8539-83a351f6595b,b8a20913,1,cardboard,0.5098595023155212,0.7369166016578674,3,ok,
92
+ 4a22d114-f087-4632-9743-da5b8873f441,70590300,0,cardboard,0.35791462659835815,0.631213366985321,3,ok,
93
+ fcc1b0b2-c02e-47cd-9452-3a0046f79fe1,4b8dc2de,0,plastic_tight_wrap,0.5018361806869507,0.6950836777687073,3,ok,
94
+ ae6fcf1f-b2a8-4b4a-910a-0961c2826f13,9fffbd7f,0,cardboard,0.46686965227127075,0.7018765211105347,3,ok,
95
+ a60a8f95-60ff-47d6-8f15-292c41ec7168,2de7e44c,0,plastic_hard,0.4138047397136688,0.6608284711837769,3,ok,
96
+ 20cbbb3d-5ca3-46be-9854-3bd52cae0c94,e739208d,1,plastic_hard,0.5516871213912964,0.7148386240005493,3,ok,
97
+ 274e2a65-3509-4359-ace0-b7f8347dc5e1,ac4cf963,0,cardboard,0.407815545797348,0.6674976944923401,3,ok,
98
+ 3613954a-4625-4d8f-8074-8307b6315177,8656003d,1,cardboard,0.5198462605476379,0.7352252006530762,3,ok,
99
+ 5aa99757-2e7b-43b9-9008-88d737ef3585,2be8e468,0,cardboard,0.5417534708976746,0.74265456199646,3,ok,
100
+ 66e8ab1e-722e-498d-99c5-4569b740a2e3,447e4a18,0,plastic_loose_bag,0.48966917395591736,0.709572970867157,3,ok,
101
+ 374a28e6-07bb-49c7-84a6-22a597a704b3,b37207cf,0,plastic_hard,0.3554178476333618,0.6601542234420776,3,ok,
image_pipeline_evaluation.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "experiment": "reconstructed_resnet18_spatial_features",
3
+ "sample_size": 100,
4
+ "feature_names": [
5
+ "unaligned_mean",
6
+ "unaligned_p95"
7
+ ],
8
+ "validation": "5-fold stratified out-of-fold predictions",
9
+ "threshold": 0.5,
10
+ "balanced_accuracy": 0.5941655941655941,
11
+ "precision": 0.4528301886792453,
12
+ "recall": 0.6486486486486487,
13
+ "f1": 0.5333333333333333,
14
+ "roc_auc": 0.607035607035607,
15
+ "limitations": [
16
+ "Small exploratory sample of 100 queries",
17
+ "Repeated experimentation on this sample may cause selection bias",
18
+ "Not a held-out production evaluation"
19
+ ]
20
+ }
image_pipeline_oof_predictions.csv ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ capture_id,item_identifier,defect,item_material,unaligned_mean,unaligned_p95,reference_count,status,error,out_of_fold_probability,out_of_fold_prediction
2
+ ce1f8d1b-a92a-45ff-98d6-29a695da97b6,013aef02,1,plastic_tight_wrap,0.3562787771224975,0.6537764668464661,3,ok,,0.3178280775325906,0
3
+ cdac9f9f-c6d2-4abd-af9e-c520e31bfa48,ef5dafc8,0,cardboard,0.3987042307853699,0.6926890015602112,3,ok,,0.46897035840256046,0
4
+ 55fc68a8-4cce-4de5-a9e8-4c4de771f52c,317028ef,1,cardboard,0.4580015540122986,0.7062972187995911,3,ok,,0.5388317183037885,1
5
+ 7da18730-4491-4272-8321-800320318fd5,eb63b921,1,plastic_tight_wrap,0.4577454030513763,0.7232344746589661,3,ok,,0.5232548055511291,1
6
+ ba9c7312-6acc-4b08-8e3a-eb4d150bb94b,b62901ba,0,plastic_loose_bag,0.4789064228534698,0.6638749837875366,3,ok,,0.5710678169367801,1
7
+ 7830db50-d449-44d1-bb90-184cd4897420,157d53f5,1,plastic_loose_bag,0.5276075601577759,0.7142903208732605,3,ok,,0.6223827411926608,1
8
+ ed39ecbe-e0eb-4b7f-9ac9-39dc39c4be74,f6f8b5f4,1,plastic_tight_wrap,0.3575901091098785,0.599012017250061,3,ok,,0.38765483150028085,0
9
+ 7ecb921a-6b72-4e8e-ab66-3311533795ed,191c1e75,1,cardboard,0.4579542875289917,0.7532495856285095,2,ok,,0.5197827929586446,1
10
+ 70011413-2d26-46de-8300-23661d81f244,907c4d0f,0,book_paper,0.4046044647693634,0.705961287021637,3,ok,,0.4565044070655382,0
11
+ 10329afd-8f47-412b-9c92-ee2c6fcf36f9,8c54ed85,0,cardboard,0.4819865226745605,0.7266709208488464,3,ok,,0.546508619614534,1
12
+ 1b1077bc-f398-46dd-aa5b-e03d5075394b,e65aa80b,0,plastic_loose_bag,0.4616168737411499,0.6889091730117798,3,ok,,0.5419175479752514,1
13
+ 32316a2d-5fa9-4ed6-9ad5-b16841f8b255,b54c2e1a,1,cardboard,0.4973308444023132,0.7301851511001587,3,ok,,0.5744652846393182,1
14
+ 66356818-317e-4cbc-aeb6-9eb11ec63296,317d6c6a,1,plastic_tight_wrap,0.5358393788337708,0.7571166157722473,3,ok,,0.6221118046665272,1
15
+ ba9385b8-3256-4c33-b5d2-896dfaffa499,347ca3ad,0,cardboard,0.2698674201965332,0.5285285711288452,3,ok,,0.3367149103337453,0
16
+ eaa2e987-955f-43e4-b12d-776c56509fb5,695fc44f,1,cardboard,0.4984833896160126,0.7370227575302124,2,ok,,0.5785790181515115,1
17
+ 8f0d56eb-1f4e-42c4-9c50-a60cfb9764d7,c34aa1d6,0,plastic_hard,0.3520920276641845,0.6093997955322266,3,ok,,0.3677201948993037,0
18
+ dd0c0ec1-e395-447c-aae1-d80d5949b3f4,fa44a1ca,1,book_paper,0.4266515374183655,0.7052961587905884,3,ok,,0.42642060605230775,0
19
+ eba75816-8e56-4397-bdbf-10c0e9e432e1,80053258,0,plastic_tight_wrap,0.4429893493652344,0.7157601118087769,3,ok,,0.45538441449452416,0
20
+ 0576c499-b132-4463-9da5-43a8c1fb0170,6ec62be0,0,book_paper,0.4131524264812469,0.6690501570701599,3,ok,,0.3858822788613043,0
21
+ c4756aab-0ed7-48d6-8728-fc11999312c6,6a089d81,0,book_paper,0.4753403663635254,0.729053795337677,3,ok,,0.5452577516901503,1
22
+ 03891eb0-8a50-4c3e-b3eb-684f1a0b2e46,ba8d493f,0,book_paper,0.4078952372074127,0.6532648205757141,3,ok,,0.4785557004594872,0
23
+ d278cd31-1c5b-4af3-97f3-75619b84d248,ebeb5087,0,plastic_loose_bag,0.4566151797771454,0.6768727898597717,3,ok,,0.5383674524328121,1
24
+ d7186b3e-732b-4101-9018-0f3dbb811af9,db683599,0,cardboard,0.4689985811710357,0.688582718372345,3,ok,,0.5497894915683087,1
25
+ 7e6b7b8a-8438-4fc9-898c-b648174d8339,08b6453a,0,plastic_loose_bag,0.4941263794898987,0.7099595069885254,3,ok,,0.582358181167256,1
26
+ 5c508431-023f-4ced-b3aa-450e6d6b6529,d88767dd,0,plastic_tight_wrap,0.4608427584171295,0.6984899044036865,3,ok,,0.5175756987487791,1
27
+ 10a42c0e-822c-4c04-80ae-6fd038893a01,fb079173,0,plastic_loose_bag,0.4574731290340423,0.6898187398910522,3,ok,,0.5170212710589118,1
28
+ e3d84cfd-9925-48a8-b447-1f67080a57c6,2c0f1f1b,0,plastic_hard,0.3721645176410675,0.6253659725189209,3,ok,,0.41256427329895407,0
29
+ 72d387e6-4381-4d90-9aa7-ac9c72021208,ca9a1f03,0,plastic_loose_bag,0.4799305200576782,0.7120817303657532,3,ok,,0.5473682574324007,1
30
+ 77d6663d-1165-4c12-9d85-b7a6d4fc00a5,16559ccc,1,book_paper,0.2669348120689392,0.514133095741272,3,ok,,0.05228631082333383,0
31
+ 55900370-6b66-4d52-b42c-eff4d2eebd23,cb8d0006,1,cardboard,0.3821182250976562,0.627932608127594,3,ok,,0.25314105056840175,0
32
+ 5e8d6d4a-e0fa-4758-844c-ea7f7b7861d6,c8cf2548,0,other,0.550700306892395,0.7622522711753845,3,ok,,0.6301504172196979,1
33
+ 8d3bc3b9-717b-4e4f-8704-196072d88535,06bbfff8,1,plastic_loose_bag,0.4524429142475128,0.6785510182380676,3,ok,,0.44899933760558913,0
34
+ 132240a7-8489-40a6-86dd-8d0aa5a9f98a,e6370344,0,cardboard,0.4961780607700348,0.723197877407074,3,ok,,0.5791363294088394,1
35
+ 14edea6c-66b1-4465-b4cd-22ae88ef1b3e,c0bb16a7,1,cardboard,0.5516060590744019,0.752123236656189,3,ok,,0.6259606220997337,1
36
+ da5c26e9-2843-4e3e-8926-82d1f512cd2f,a9bc74ac,1,book_paper,0.4624392390251159,0.7098153829574585,3,ok,,0.5535354812424919,1
37
+ 9e12d477-de43-4580-bc9a-b76c04266003,6fe6152c,0,other,0.4733660817146301,0.6963954567909241,3,ok,,0.5225848178602109,1
38
+ 0276a193-563b-4fff-836f-4de03b65a3cf,dc6edd51,1,cardboard,0.415161669254303,0.6613745093345642,3,ok,,0.46051944072940143,0
39
+ 665a1601-641f-4cf5-9cdb-c57e355cd162,0305f1d1,0,cardboard,0.4891031086444855,0.6879621744155884,3,ok,,0.5789670247973506,1
40
+ 4f8c9e3d-06f5-4923-b2f0-d11c0f899d6a,bd1e1cd7,1,plastic_loose_bag,0.556549072265625,0.7656486630439758,1,ok,,0.6403759629870499,1
41
+ 9e9cda89-00e4-430e-ab68-24762f2ac5b1,89f40e71,0,cardboard,0.3782241940498352,0.6799495220184326,3,ok,,0.4452704510034816,0
42
+ 28382f2d-5a84-4107-83fe-42e7c3117485,ee7074d4,0,plastic_hard,0.4702258110046386,0.6701549291610718,3,ok,,0.5981778000262808,1
43
+ 68fc5e70-9716-434d-937b-e5fac05bbf38,09b7b657,1,book_paper,0.4407956898212433,0.7079201340675354,3,ok,,0.5123330903374856,1
44
+ 32e891de-fb61-4255-a982-9efd281e34a6,464cf483,0,book_paper,0.2582710683345794,0.5440506935119629,3,ok,,0.07160487488042695,0
45
+ a227ac47-3d74-4142-b583-7ab4362c5692,65cc0346,0,book_paper,0.480347603559494,0.735040009021759,3,ok,,0.5294371425111726,1
46
+ 6cf537b3-924f-450e-86fb-2e07a6c7a48a,77f9c75c,1,plastic_tight_wrap,0.4665637910366058,0.7056427597999573,3,ok,,0.5409641347782914,1
47
+ e8810453-f791-4b0b-95f0-72ee441f7da7,3b420d44,0,cardboard,0.4937344491481781,0.6935549974441528,3,ok,,0.5836368405748026,1
48
+ d3dd25e6-a7fe-4478-8bdd-179c1231a37e,ea315389,1,book_paper,0.1831742376089096,0.3810464143753052,3,ok,,0.007889333664086607,0
49
+ 9731ece9-abf0-42b6-a0cc-70a54ebc0651,16804243,1,plastic_loose_bag,0.4700523316860199,0.6788854598999023,3,ok,,0.5543471148507547,1
50
+ 14ee34b7-9977-4352-8897-5280d6ccd3a5,dbbb150c,1,book_paper,0.5300252437591553,0.8074590563774109,1,ok,,0.6017919380761343,1
51
+ d8c33355-472f-4cbd-8588-e4fe93954d58,26ef13e6,0,book_paper,0.4794357419013977,0.7387665510177612,3,ok,,0.6529116843725573,1
52
+ 83c4c228-e647-40ea-874a-c7bab3607b86,82b599a3,0,cardboard,0.3412045836448669,0.6153524518013,3,ok,,0.20012124689918953,0
53
+ 6cebe214-3daf-41e2-9718-e7696f11e54d,463751e9,0,book_paper,0.5426834225654602,0.8088444471359253,1,ok,,0.6178139552872084,1
54
+ 15244401-b21f-4419-9e74-09cb355a9ddc,7e001bec,0,plastic_loose_bag,0.4096498191356659,0.6430224180221558,3,ok,,0.47293543568093577,0
55
+ 754fe098-360a-426c-b294-354209efe21f,be7fa075,0,plastic_loose_bag,0.359021931886673,0.6226292252540588,3,ok,,0.3669640399541668,0
56
+ eeed7ef4-3e1e-4156-95f3-498e0f4c470f,8465c821,1,plastic_loose_bag,0.3802911937236786,0.6541786193847656,3,ok,,0.3774109384665216,0
57
+ 4c8fa715-5e93-43da-bdd2-8b4cc28c8808,61593bca,0,cardboard,0.446098119020462,0.7251598238945007,3,ok,,0.5067464693263632,1
58
+ 09159dc6-7a12-4075-b0bd-1dcf9bf6ef6c,34b5e164,0,cardboard,0.3985018134117126,0.6852228045463562,3,ok,,0.4649487818714382,0
59
+ 810d6ed9-9a75-4872-bce7-e48f0840dcdb,7aaa8d0d,0,plastic_loose_bag,0.3789044618606567,0.6603807210922241,3,ok,,0.43584074491071534,0
60
+ 2689e621-9ad3-4ea8-8059-039477e3fe65,570e64f3,0,cardboard,0.382758617401123,0.6769934892654419,3,ok,,0.35181297251344035,0
61
+ 1d4e43ae-a463-4590-87ac-7fa6e8114473,9514f0c1,1,plastic_tight_wrap,0.4223305881023407,0.7097806334495544,3,ok,,0.47934899841285294,0
62
+ 1da2fd8c-f61a-49b6-9c29-547d95548df8,c2cfdd7e,0,cardboard,0.3190962970256805,0.6552318334579468,3,ok,,0.3610576579371054,0
63
+ aa490d01-0211-4985-aa9d-2ec4fb815062,5baf8331,0,cardboard,0.4737735688686371,0.7293909788131714,3,ok,,0.5430268141584512,1
64
+ 7ca1b984-6504-4515-86a1-28cc8f1d127f,9761ce5e,1,plastic_loose_bag,0.4329871237277984,0.7279478907585144,2,ok,,0.5161187103312582,1
65
+ fe219ec5-904a-4e8a-a133-df01b8f45a7b,ce533958,0,book_paper,0.2477401793003082,0.5309467911720276,3,ok,,0.2750842434965959,0
66
+ c60afd8d-f803-4265-b0a1-333f2795085a,d2d4298c,0,plastic_loose_bag,0.4387794137001037,0.6823380589485168,3,ok,,0.49737962706126615,0
67
+ d0c06331-e840-48fc-b739-8e85cb9835b3,7b791ee6,0,book_paper,0.4073482453823089,0.6921342015266418,3,ok,,0.46742754814230747,0
68
+ 691f0627-afb2-46d2-965f-f760cf699e1a,dd97788d,1,plastic_loose_bag,0.4403063356876373,0.6671016216278076,3,ok,,0.49077450785574556,0
69
+ d6bd14ba-8ee7-4db1-8580-7d46a1575dba,dd964fea,1,book_paper,0.5771564841270447,0.8264408111572266,1,ok,,0.6479433815183158,1
70
+ 5e239334-62f0-4d41-b7a6-587306465e85,580bbb4f,1,cardboard,0.4567321538925171,0.6950039267539978,3,ok,,0.5190800002276074,1
71
+ 20f7be26-b9c9-4ec4-877c-59519507178b,bc4186fa,1,plastic_loose_bag,0.4744743108749389,0.6924605369567871,3,ok,,0.5582761400998552,1
72
+ 027689fb-02da-4ace-a812-1df4857a74db,6d8d11f7,0,plastic_tight_wrap,0.3265800178050995,0.5882118940353394,3,ok,,0.3326437095570536,0
73
+ 0209d15f-f1ab-4107-97da-f076247d9bb2,2e600c6f,0,plastic_loose_bag,0.4851038753986358,0.6923578381538391,3,ok,,0.5209341631492342,1
74
+ 6bdb1a1e-e126-460f-b7bb-0eaed9c039c5,100330bb,0,cardboard,0.4009793698787689,0.6530646085739136,3,ok,,0.4504823186062484,0
75
+ abbcc05d-7b73-4f3a-80c9-db7acfab0ff2,3abedeec,0,plastic_hard,0.4442612826824188,0.7187825441360474,3,ok,,0.45434615749777657,0
76
+ 8d2ee448-d6c6-4d5f-827f-1c9d37f6e429,bb8b9e03,1,book_paper,0.5187292098999023,0.7346292734146118,3,ok,,0.590906544147291,1
77
+ da3268de-1e49-4f42-8cab-4e01bf1743f3,0cc8e1c6,0,plastic_hard,0.3166924715042114,0.5805547833442688,3,ok,,0.37980580569958117,0
78
+ d933b0f2-c58a-4053-885c-b38459ce0767,f0025ae4,0,book_paper,0.4461637735366821,0.7063854336738586,3,ok,,0.5163201613658496,1
79
+ b254a0fe-6484-410c-8ce9-4d0db0d51649,ee5dbbeb,0,cardboard,0.3698452413082123,0.6864824295043945,3,ok,,0.44163298291365854,0
80
+ f4b6c0f9-9c31-4b00-9e3c-a90756d3b859,fbaa7b25,1,book_paper,0.4505879282951355,0.7018393874168396,3,ok,,0.5184739325451034,1
81
+ d8dd88a0-d477-431a-80e2-1bed93c4bfeb,91f53f64,0,cardboard,0.4810663759708404,0.7266586422920227,3,ok,,0.5580742331549282,1
82
+ 3ec8cbd9-3200-4e9b-a8e7-9f695832d06f,1b108d7a,0,cardboard,0.210922822356224,0.4809436500072479,3,ok,,0.209530743776201,0
83
+ 8f65ddfe-f23c-413c-b849-24b1d4637345,5476dae3,0,plastic_tight_wrap,0.3976413905620575,0.650898277759552,3,ok,,0.322180039316246,0
84
+ a0994f06-73d3-43fa-986a-54e0e00dcccf,529f714b,0,cardboard,0.4666250646114349,0.7039357423782349,3,ok,,0.541601319662412,1
85
+ 4fb0ad81-1387-4e9a-90a9-8e295a076539,703a2703,0,cardboard,0.3229234516620636,0.5796516537666321,3,ok,,0.335148012292035,0
86
+ 4da58afa-b2d9-4653-bd81-6063e6fcb128,38dfb39d,1,cardboard,0.4046985208988189,0.7393936514854431,2,ok,,0.3218422695538572,0
87
+ 69bfa3d5-066d-43d0-ba2e-55227f4d63c3,8819c69a,1,plastic_tight_wrap,0.49680095911026,0.7398384213447571,3,ok,,0.5673188858365507,1
88
+ 43065489-603f-4d9f-a4e2-e7dad256661e,8938c6cb,0,plastic_hard,0.3817671835422516,0.653298556804657,3,ok,,0.4346076601034353,0
89
+ a806a59c-71f0-4fef-8520-34ea1b72693f,4dec693f,1,paper,0.4375388622283935,0.7035834193229675,3,ok,,0.45867511869411104,0
90
+ 4ab03df3-6ba8-4db4-9e0c-156412d2b580,22511590,0,cardboard,0.2852183878421783,0.5342108607292175,3,ok,,0.34858997330481256,0
91
+ a3bed498-6f1c-4d84-8539-83a351f6595b,b8a20913,1,cardboard,0.5098595023155212,0.7369166016578674,3,ok,,0.5889643005367382,1
92
+ 4a22d114-f087-4632-9743-da5b8873f441,70590300,0,cardboard,0.3579146265983581,0.631213366985321,3,ok,,0.24413923380038707,0
93
+ fcc1b0b2-c02e-47cd-9452-3a0046f79fe1,4b8dc2de,0,plastic_tight_wrap,0.5018361806869507,0.6950836777687073,3,ok,,0.6449669503900729,1
94
+ ae6fcf1f-b2a8-4b4a-910a-0961c2826f13,9fffbd7f,0,cardboard,0.4668696522712707,0.7018765211105347,3,ok,,0.542601031165778,1
95
+ a60a8f95-60ff-47d6-8f15-292c41ec7168,2de7e44c,0,plastic_hard,0.4138047397136688,0.6608284711837769,3,ok,,0.3628453570420301,0
96
+ 20cbbb3d-5ca3-46be-9854-3bd52cae0c94,e739208d,1,plastic_hard,0.5516871213912964,0.7148386240005493,3,ok,,0.6462246869573676,1
97
+ 274e2a65-3509-4359-ace0-b7f8347dc5e1,ac4cf963,0,cardboard,0.407815545797348,0.6674976944923401,3,ok,,0.47464134282211917,0
98
+ 3613954a-4625-4d8f-8074-8307b6315177,8656003d,1,cardboard,0.5198462605476379,0.7352252006530762,3,ok,,0.6070739131563349,1
99
+ 5aa99757-2e7b-43b9-9008-88d737ef3585,2be8e468,0,cardboard,0.5417534708976746,0.74265456199646,3,ok,,0.6286175308576372,1
100
+ 66e8ab1e-722e-498d-99c5-4569b740a2e3,447e4a18,0,plastic_loose_bag,0.4896691739559173,0.709572970867157,3,ok,,0.5772380217937587,1
101
+ 374a28e6-07bb-49c7-84a6-22a597a704b3,b37207cf,0,plastic_hard,0.3554178476333618,0.6601542234420776,3,ok,,0.40539354131206007,0
parcelguard_image_classifier.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84087ec83b47d2bd0a28bc0e0b02d618166cd425e106207d93b329f0784c4b4e
3
+ size 1425
parcelguard_resnet18_layer2.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f730807982412de0d4b26eaa61f01d88b51c3c7789b50566f258f20d0cd3fa1
3
+ size 2760407
pipeline_config.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "project": "ParcelGuard",
3
+ "task": "reference-guided visual anomaly detection",
4
+ "backbone": "ResNet18",
5
+ "feature_layer": "layer2",
6
+ "input_size": [
7
+ 224,
8
+ 224
9
+ ],
10
+ "feature_map_shape": [
11
+ 128,
12
+ 28,
13
+ 28
14
+ ],
15
+ "scoring": "minimum cosine distance across references at each spatial location",
16
+ "primary_score": "95th percentile of spatial anomaly map",
17
+ "provisional_threshold": 0.7,
18
+ "threshold_status": "exploratory; not validated on held-out data",
19
+ "classifier_artifact": "parcelguard_image_classifier.joblib",
20
+ "backbone_artifact": "parcelguard_resnet18_layer2.pt",
21
+ "inference_module": "src/predict.py",
22
+ "status": "experimental"
23
+ }
pipeline_error_analysis.csv ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ capture_id,item_identifier,defect,item_material,unaligned_mean,unaligned_p95,reference_count,status,error,oof_probability,oof_prediction,error_type
2
+ ce1f8d1b-a92a-45ff-98d6-29a695da97b6,013aef02,1,plastic_tight_wrap,0.3562787771224975,0.6537764668464661,3,ok,,0.3178280775325906,0,false_negative
3
+ cdac9f9f-c6d2-4abd-af9e-c520e31bfa48,ef5dafc8,0,cardboard,0.3987042307853699,0.6926890015602112,3,ok,,0.46897035840256046,0,correct
4
+ 55fc68a8-4cce-4de5-a9e8-4c4de771f52c,317028ef,1,cardboard,0.4580015540122986,0.7062972187995911,3,ok,,0.5388317183037885,1,correct
5
+ 7da18730-4491-4272-8321-800320318fd5,eb63b921,1,plastic_tight_wrap,0.4577454030513763,0.7232344746589661,3,ok,,0.5232548055511291,1,correct
6
+ ba9c7312-6acc-4b08-8e3a-eb4d150bb94b,b62901ba,0,plastic_loose_bag,0.4789064228534698,0.6638749837875366,3,ok,,0.5710678169367801,1,false_positive
7
+ 7830db50-d449-44d1-bb90-184cd4897420,157d53f5,1,plastic_loose_bag,0.5276075601577759,0.7142903208732605,3,ok,,0.6223827411926608,1,correct
8
+ ed39ecbe-e0eb-4b7f-9ac9-39dc39c4be74,f6f8b5f4,1,plastic_tight_wrap,0.3575901091098785,0.599012017250061,3,ok,,0.38765483150028085,0,false_negative
9
+ 7ecb921a-6b72-4e8e-ab66-3311533795ed,191c1e75,1,cardboard,0.4579542875289917,0.7532495856285095,2,ok,,0.5197827929586446,1,correct
10
+ 70011413-2d26-46de-8300-23661d81f244,907c4d0f,0,book_paper,0.4046044647693634,0.705961287021637,3,ok,,0.4565044070655382,0,correct
11
+ 10329afd-8f47-412b-9c92-ee2c6fcf36f9,8c54ed85,0,cardboard,0.4819865226745605,0.7266709208488464,3,ok,,0.546508619614534,1,false_positive
12
+ 1b1077bc-f398-46dd-aa5b-e03d5075394b,e65aa80b,0,plastic_loose_bag,0.4616168737411499,0.6889091730117798,3,ok,,0.5419175479752514,1,false_positive
13
+ 32316a2d-5fa9-4ed6-9ad5-b16841f8b255,b54c2e1a,1,cardboard,0.4973308444023132,0.7301851511001587,3,ok,,0.5744652846393182,1,correct
14
+ 66356818-317e-4cbc-aeb6-9eb11ec63296,317d6c6a,1,plastic_tight_wrap,0.5358393788337708,0.7571166157722473,3,ok,,0.6221118046665272,1,correct
15
+ ba9385b8-3256-4c33-b5d2-896dfaffa499,347ca3ad,0,cardboard,0.2698674201965332,0.5285285711288452,3,ok,,0.3367149103337453,0,correct
16
+ eaa2e987-955f-43e4-b12d-776c56509fb5,695fc44f,1,cardboard,0.4984833896160126,0.7370227575302124,2,ok,,0.5785790181515115,1,correct
17
+ 8f0d56eb-1f4e-42c4-9c50-a60cfb9764d7,c34aa1d6,0,plastic_hard,0.3520920276641845,0.6093997955322266,3,ok,,0.3677201948993037,0,correct
18
+ dd0c0ec1-e395-447c-aae1-d80d5949b3f4,fa44a1ca,1,book_paper,0.4266515374183655,0.7052961587905884,3,ok,,0.42642060605230775,0,false_negative
19
+ eba75816-8e56-4397-bdbf-10c0e9e432e1,80053258,0,plastic_tight_wrap,0.4429893493652344,0.7157601118087769,3,ok,,0.45538441449452416,0,correct
20
+ 0576c499-b132-4463-9da5-43a8c1fb0170,6ec62be0,0,book_paper,0.4131524264812469,0.6690501570701599,3,ok,,0.3858822788613043,0,correct
21
+ c4756aab-0ed7-48d6-8728-fc11999312c6,6a089d81,0,book_paper,0.4753403663635254,0.729053795337677,3,ok,,0.5452577516901503,1,false_positive
22
+ 03891eb0-8a50-4c3e-b3eb-684f1a0b2e46,ba8d493f,0,book_paper,0.4078952372074127,0.6532648205757141,3,ok,,0.4785557004594872,0,correct
23
+ d278cd31-1c5b-4af3-97f3-75619b84d248,ebeb5087,0,plastic_loose_bag,0.4566151797771454,0.6768727898597717,3,ok,,0.5383674524328121,1,false_positive
24
+ d7186b3e-732b-4101-9018-0f3dbb811af9,db683599,0,cardboard,0.4689985811710357,0.688582718372345,3,ok,,0.5497894915683087,1,false_positive
25
+ 7e6b7b8a-8438-4fc9-898c-b648174d8339,08b6453a,0,plastic_loose_bag,0.4941263794898987,0.7099595069885254,3,ok,,0.582358181167256,1,false_positive
26
+ 5c508431-023f-4ced-b3aa-450e6d6b6529,d88767dd,0,plastic_tight_wrap,0.4608427584171295,0.6984899044036865,3,ok,,0.5175756987487791,1,false_positive
27
+ 10a42c0e-822c-4c04-80ae-6fd038893a01,fb079173,0,plastic_loose_bag,0.4574731290340423,0.6898187398910522,3,ok,,0.5170212710589118,1,false_positive
28
+ e3d84cfd-9925-48a8-b447-1f67080a57c6,2c0f1f1b,0,plastic_hard,0.3721645176410675,0.6253659725189209,3,ok,,0.41256427329895407,0,correct
29
+ 72d387e6-4381-4d90-9aa7-ac9c72021208,ca9a1f03,0,plastic_loose_bag,0.4799305200576782,0.7120817303657532,3,ok,,0.5473682574324007,1,false_positive
30
+ 77d6663d-1165-4c12-9d85-b7a6d4fc00a5,16559ccc,1,book_paper,0.2669348120689392,0.514133095741272,3,ok,,0.05228631082333383,0,false_negative
31
+ 55900370-6b66-4d52-b42c-eff4d2eebd23,cb8d0006,1,cardboard,0.3821182250976562,0.627932608127594,3,ok,,0.25314105056840175,0,false_negative
32
+ 5e8d6d4a-e0fa-4758-844c-ea7f7b7861d6,c8cf2548,0,other,0.550700306892395,0.7622522711753845,3,ok,,0.6301504172196979,1,false_positive
33
+ 8d3bc3b9-717b-4e4f-8704-196072d88535,06bbfff8,1,plastic_loose_bag,0.4524429142475128,0.6785510182380676,3,ok,,0.44899933760558913,0,false_negative
34
+ 132240a7-8489-40a6-86dd-8d0aa5a9f98a,e6370344,0,cardboard,0.4961780607700348,0.723197877407074,3,ok,,0.5791363294088394,1,false_positive
35
+ 14edea6c-66b1-4465-b4cd-22ae88ef1b3e,c0bb16a7,1,cardboard,0.5516060590744019,0.752123236656189,3,ok,,0.6259606220997337,1,correct
36
+ da5c26e9-2843-4e3e-8926-82d1f512cd2f,a9bc74ac,1,book_paper,0.4624392390251159,0.7098153829574585,3,ok,,0.5535354812424919,1,correct
37
+ 9e12d477-de43-4580-bc9a-b76c04266003,6fe6152c,0,other,0.4733660817146301,0.6963954567909241,3,ok,,0.5225848178602109,1,false_positive
38
+ 0276a193-563b-4fff-836f-4de03b65a3cf,dc6edd51,1,cardboard,0.415161669254303,0.6613745093345642,3,ok,,0.46051944072940143,0,false_negative
39
+ 665a1601-641f-4cf5-9cdb-c57e355cd162,0305f1d1,0,cardboard,0.4891031086444855,0.6879621744155884,3,ok,,0.5789670247973506,1,false_positive
40
+ 4f8c9e3d-06f5-4923-b2f0-d11c0f899d6a,bd1e1cd7,1,plastic_loose_bag,0.556549072265625,0.7656486630439758,1,ok,,0.6403759629870499,1,correct
41
+ 9e9cda89-00e4-430e-ab68-24762f2ac5b1,89f40e71,0,cardboard,0.3782241940498352,0.6799495220184326,3,ok,,0.4452704510034816,0,correct
42
+ 28382f2d-5a84-4107-83fe-42e7c3117485,ee7074d4,0,plastic_hard,0.4702258110046386,0.6701549291610718,3,ok,,0.5981778000262808,1,false_positive
43
+ 68fc5e70-9716-434d-937b-e5fac05bbf38,09b7b657,1,book_paper,0.4407956898212433,0.7079201340675354,3,ok,,0.5123330903374856,1,correct
44
+ 32e891de-fb61-4255-a982-9efd281e34a6,464cf483,0,book_paper,0.2582710683345794,0.5440506935119629,3,ok,,0.07160487488042695,0,correct
45
+ a227ac47-3d74-4142-b583-7ab4362c5692,65cc0346,0,book_paper,0.480347603559494,0.735040009021759,3,ok,,0.5294371425111726,1,false_positive
46
+ 6cf537b3-924f-450e-86fb-2e07a6c7a48a,77f9c75c,1,plastic_tight_wrap,0.4665637910366058,0.7056427597999573,3,ok,,0.5409641347782914,1,correct
47
+ e8810453-f791-4b0b-95f0-72ee441f7da7,3b420d44,0,cardboard,0.4937344491481781,0.6935549974441528,3,ok,,0.5836368405748026,1,false_positive
48
+ d3dd25e6-a7fe-4478-8bdd-179c1231a37e,ea315389,1,book_paper,0.1831742376089096,0.3810464143753052,3,ok,,0.007889333664086607,0,false_negative
49
+ 9731ece9-abf0-42b6-a0cc-70a54ebc0651,16804243,1,plastic_loose_bag,0.4700523316860199,0.6788854598999023,3,ok,,0.5543471148507547,1,correct
50
+ 14ee34b7-9977-4352-8897-5280d6ccd3a5,dbbb150c,1,book_paper,0.5300252437591553,0.8074590563774109,1,ok,,0.6017919380761343,1,correct
51
+ d8c33355-472f-4cbd-8588-e4fe93954d58,26ef13e6,0,book_paper,0.4794357419013977,0.7387665510177612,3,ok,,0.6529116843725573,1,false_positive
52
+ 83c4c228-e647-40ea-874a-c7bab3607b86,82b599a3,0,cardboard,0.3412045836448669,0.6153524518013,3,ok,,0.20012124689918953,0,correct
53
+ 6cebe214-3daf-41e2-9718-e7696f11e54d,463751e9,0,book_paper,0.5426834225654602,0.8088444471359253,1,ok,,0.6178139552872084,1,false_positive
54
+ 15244401-b21f-4419-9e74-09cb355a9ddc,7e001bec,0,plastic_loose_bag,0.4096498191356659,0.6430224180221558,3,ok,,0.47293543568093577,0,correct
55
+ 754fe098-360a-426c-b294-354209efe21f,be7fa075,0,plastic_loose_bag,0.359021931886673,0.6226292252540588,3,ok,,0.3669640399541668,0,correct
56
+ eeed7ef4-3e1e-4156-95f3-498e0f4c470f,8465c821,1,plastic_loose_bag,0.3802911937236786,0.6541786193847656,3,ok,,0.3774109384665216,0,false_negative
57
+ 4c8fa715-5e93-43da-bdd2-8b4cc28c8808,61593bca,0,cardboard,0.446098119020462,0.7251598238945007,3,ok,,0.5067464693263632,1,false_positive
58
+ 09159dc6-7a12-4075-b0bd-1dcf9bf6ef6c,34b5e164,0,cardboard,0.3985018134117126,0.6852228045463562,3,ok,,0.4649487818714382,0,correct
59
+ 810d6ed9-9a75-4872-bce7-e48f0840dcdb,7aaa8d0d,0,plastic_loose_bag,0.3789044618606567,0.6603807210922241,3,ok,,0.43584074491071534,0,correct
60
+ 2689e621-9ad3-4ea8-8059-039477e3fe65,570e64f3,0,cardboard,0.382758617401123,0.6769934892654419,3,ok,,0.35181297251344035,0,correct
61
+ 1d4e43ae-a463-4590-87ac-7fa6e8114473,9514f0c1,1,plastic_tight_wrap,0.4223305881023407,0.7097806334495544,3,ok,,0.47934899841285294,0,false_negative
62
+ 1da2fd8c-f61a-49b6-9c29-547d95548df8,c2cfdd7e,0,cardboard,0.3190962970256805,0.6552318334579468,3,ok,,0.3610576579371054,0,correct
63
+ aa490d01-0211-4985-aa9d-2ec4fb815062,5baf8331,0,cardboard,0.4737735688686371,0.7293909788131714,3,ok,,0.5430268141584512,1,false_positive
64
+ 7ca1b984-6504-4515-86a1-28cc8f1d127f,9761ce5e,1,plastic_loose_bag,0.4329871237277984,0.7279478907585144,2,ok,,0.5161187103312582,1,correct
65
+ fe219ec5-904a-4e8a-a133-df01b8f45a7b,ce533958,0,book_paper,0.2477401793003082,0.5309467911720276,3,ok,,0.2750842434965959,0,correct
66
+ c60afd8d-f803-4265-b0a1-333f2795085a,d2d4298c,0,plastic_loose_bag,0.4387794137001037,0.6823380589485168,3,ok,,0.49737962706126615,0,correct
67
+ d0c06331-e840-48fc-b739-8e85cb9835b3,7b791ee6,0,book_paper,0.4073482453823089,0.6921342015266418,3,ok,,0.46742754814230747,0,correct
68
+ 691f0627-afb2-46d2-965f-f760cf699e1a,dd97788d,1,plastic_loose_bag,0.4403063356876373,0.6671016216278076,3,ok,,0.49077450785574556,0,false_negative
69
+ d6bd14ba-8ee7-4db1-8580-7d46a1575dba,dd964fea,1,book_paper,0.5771564841270447,0.8264408111572266,1,ok,,0.6479433815183158,1,correct
70
+ 5e239334-62f0-4d41-b7a6-587306465e85,580bbb4f,1,cardboard,0.4567321538925171,0.6950039267539978,3,ok,,0.5190800002276074,1,correct
71
+ 20f7be26-b9c9-4ec4-877c-59519507178b,bc4186fa,1,plastic_loose_bag,0.4744743108749389,0.6924605369567871,3,ok,,0.5582761400998552,1,correct
72
+ 027689fb-02da-4ace-a812-1df4857a74db,6d8d11f7,0,plastic_tight_wrap,0.3265800178050995,0.5882118940353394,3,ok,,0.3326437095570536,0,correct
73
+ 0209d15f-f1ab-4107-97da-f076247d9bb2,2e600c6f,0,plastic_loose_bag,0.4851038753986358,0.6923578381538391,3,ok,,0.5209341631492342,1,false_positive
74
+ 6bdb1a1e-e126-460f-b7bb-0eaed9c039c5,100330bb,0,cardboard,0.4009793698787689,0.6530646085739136,3,ok,,0.4504823186062484,0,correct
75
+ abbcc05d-7b73-4f3a-80c9-db7acfab0ff2,3abedeec,0,plastic_hard,0.4442612826824188,0.7187825441360474,3,ok,,0.45434615749777657,0,correct
76
+ 8d2ee448-d6c6-4d5f-827f-1c9d37f6e429,bb8b9e03,1,book_paper,0.5187292098999023,0.7346292734146118,3,ok,,0.590906544147291,1,correct
77
+ da3268de-1e49-4f42-8cab-4e01bf1743f3,0cc8e1c6,0,plastic_hard,0.3166924715042114,0.5805547833442688,3,ok,,0.37980580569958117,0,correct
78
+ d933b0f2-c58a-4053-885c-b38459ce0767,f0025ae4,0,book_paper,0.4461637735366821,0.7063854336738586,3,ok,,0.5163201613658496,1,false_positive
79
+ b254a0fe-6484-410c-8ce9-4d0db0d51649,ee5dbbeb,0,cardboard,0.3698452413082123,0.6864824295043945,3,ok,,0.44163298291365854,0,correct
80
+ f4b6c0f9-9c31-4b00-9e3c-a90756d3b859,fbaa7b25,1,book_paper,0.4505879282951355,0.7018393874168396,3,ok,,0.5184739325451034,1,correct
81
+ d8dd88a0-d477-431a-80e2-1bed93c4bfeb,91f53f64,0,cardboard,0.4810663759708404,0.7266586422920227,3,ok,,0.5580742331549282,1,false_positive
82
+ 3ec8cbd9-3200-4e9b-a8e7-9f695832d06f,1b108d7a,0,cardboard,0.210922822356224,0.4809436500072479,3,ok,,0.209530743776201,0,correct
83
+ 8f65ddfe-f23c-413c-b849-24b1d4637345,5476dae3,0,plastic_tight_wrap,0.3976413905620575,0.650898277759552,3,ok,,0.322180039316246,0,correct
84
+ a0994f06-73d3-43fa-986a-54e0e00dcccf,529f714b,0,cardboard,0.4666250646114349,0.7039357423782349,3,ok,,0.541601319662412,1,false_positive
85
+ 4fb0ad81-1387-4e9a-90a9-8e295a076539,703a2703,0,cardboard,0.3229234516620636,0.5796516537666321,3,ok,,0.335148012292035,0,correct
86
+ 4da58afa-b2d9-4653-bd81-6063e6fcb128,38dfb39d,1,cardboard,0.4046985208988189,0.7393936514854431,2,ok,,0.3218422695538572,0,false_negative
87
+ 69bfa3d5-066d-43d0-ba2e-55227f4d63c3,8819c69a,1,plastic_tight_wrap,0.49680095911026,0.7398384213447571,3,ok,,0.5673188858365507,1,correct
88
+ 43065489-603f-4d9f-a4e2-e7dad256661e,8938c6cb,0,plastic_hard,0.3817671835422516,0.653298556804657,3,ok,,0.4346076601034353,0,correct
89
+ a806a59c-71f0-4fef-8520-34ea1b72693f,4dec693f,1,paper,0.4375388622283935,0.7035834193229675,3,ok,,0.45867511869411104,0,false_negative
90
+ 4ab03df3-6ba8-4db4-9e0c-156412d2b580,22511590,0,cardboard,0.2852183878421783,0.5342108607292175,3,ok,,0.34858997330481256,0,correct
91
+ a3bed498-6f1c-4d84-8539-83a351f6595b,b8a20913,1,cardboard,0.5098595023155212,0.7369166016578674,3,ok,,0.5889643005367382,1,correct
92
+ 4a22d114-f087-4632-9743-da5b8873f441,70590300,0,cardboard,0.3579146265983581,0.631213366985321,3,ok,,0.24413923380038707,0,correct
93
+ fcc1b0b2-c02e-47cd-9452-3a0046f79fe1,4b8dc2de,0,plastic_tight_wrap,0.5018361806869507,0.6950836777687073,3,ok,,0.6449669503900729,1,false_positive
94
+ ae6fcf1f-b2a8-4b4a-910a-0961c2826f13,9fffbd7f,0,cardboard,0.4668696522712707,0.7018765211105347,3,ok,,0.542601031165778,1,false_positive
95
+ a60a8f95-60ff-47d6-8f15-292c41ec7168,2de7e44c,0,plastic_hard,0.4138047397136688,0.6608284711837769,3,ok,,0.3628453570420301,0,correct
96
+ 20cbbb3d-5ca3-46be-9854-3bd52cae0c94,e739208d,1,plastic_hard,0.5516871213912964,0.7148386240005493,3,ok,,0.6462246869573676,1,correct
97
+ 274e2a65-3509-4359-ace0-b7f8347dc5e1,ac4cf963,0,cardboard,0.407815545797348,0.6674976944923401,3,ok,,0.47464134282211917,0,correct
98
+ 3613954a-4625-4d8f-8074-8307b6315177,8656003d,1,cardboard,0.5198462605476379,0.7352252006530762,3,ok,,0.6070739131563349,1,correct
99
+ 5aa99757-2e7b-43b9-9008-88d737ef3585,2be8e468,0,cardboard,0.5417534708976746,0.74265456199646,3,ok,,0.6286175308576372,1,false_positive
100
+ 66e8ab1e-722e-498d-99c5-4569b740a2e3,447e4a18,0,plastic_loose_bag,0.4896691739559173,0.709572970867157,3,ok,,0.5772380217937587,1,false_positive
101
+ 374a28e6-07bb-49c7-84a6-22a597a704b3,b37207cf,0,plastic_hard,0.3554178476333618,0.6601542234420776,3,ok,,0.40539354131206007,0,correct
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ numpy==2.1.3
2
+ pandas==2.2.3
3
+ scikit-learn==1.6.1
4
+ joblib==1.6.0
5
+ torch==2.11.0
6
+ torchvision==0.26.0+cu130
7
+ opencv-python-headless==5.0.0
8
+ Pillow
score_method_comparison.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ method,roc_auc,balanced_accuracy_at_0.5,f1_at_0.5
2
+ p95_only,0.6838266838266838,0.4944229944229944,0.5333333333333333
3
+ mean_plus_p95_rank_average,0.6645216645216646,0.6402831402831404,0.5894736842105263
4
+ mean_only,0.6387816387816388,0.6033891033891035,0.39215686274509803
5
+ logistic_regression_oof,0.607035607035607,0.5941655941655941,0.5333333333333333
src/predict.py CHANGED
@@ -1,31 +1,78 @@
1
-
2
- import joblib
3
  import numpy as np
 
 
 
 
 
 
4
 
5
  class ParcelGuardPredictor:
6
- def __init__(self, model_path):
7
- self.model = joblib.load(model_path)
8
-
9
- def predict(self, unaligned_mean, unaligned_p95):
10
- """
11
- Predict using precomputed reference-based anomaly features.
12
-
13
- These inputs are NOT raw images. The image-processing pipeline
14
- must calculate the two features before calling this method.
15
- """
16
- features = np.array(
17
- [[unaligned_mean, unaligned_p95]],
18
- dtype=np.float64,
19
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- if not np.isfinite(features).all():
22
- raise ValueError("Features must be finite numbers.")
 
 
 
 
 
 
 
 
 
23
 
24
- probability = float(self.model.predict_proba(features)[0, 1])
25
- prediction = int(probability >= 0.5)
 
 
 
 
 
 
 
26
 
27
  return {
28
- "defect_probability": probability,
29
- "predicted_defect": prediction,
30
- "threshold": 0.5,
 
 
 
31
  }
 
1
+ from pathlib import Path
2
+ import cv2
3
  import numpy as np
4
+ import torch
5
+ import torch.nn as nn
6
+ import torchvision.transforms as T
7
+ from PIL import Image
8
+ from torchvision import models
9
+
10
 
11
  class ParcelGuardPredictor:
12
+ def __init__(self, backbone_path, threshold=0.70, device=None):
13
+ self.device = torch.device(device or ('cuda' if torch.cuda.is_available() else 'cpu'))
14
+ self.threshold = float(threshold)
15
+
16
+ backbone = models.resnet18(weights=None)
17
+ self.extractor = nn.Sequential(
18
+ backbone.conv1, backbone.bn1, backbone.relu, backbone.maxpool,
19
+ backbone.layer1, backbone.layer2
 
 
 
 
 
20
  )
21
+ state = torch.load(backbone_path, map_location='cpu', weights_only=True)
22
+ self.extractor.load_state_dict(state, strict=True)
23
+ self.extractor.to(self.device).eval()
24
+
25
+ self.transform = T.Compose([
26
+ T.Resize((224, 224)),
27
+ T.ToTensor(),
28
+ T.Normalize(mean=[0.485, 0.456, 0.406],
29
+ std=[0.229, 0.224, 0.225]),
30
+ ])
31
+
32
+ @torch.inference_mode()
33
+ def _features(self, image_path):
34
+ path = Path(image_path)
35
+ if not path.is_file():
36
+ raise FileNotFoundError(f'Image not found: {path}')
37
+ image = Image.open(path).convert('RGB')
38
+ tensor = self.transform(image).unsqueeze(0).to(self.device)
39
+ return self.extractor(tensor)[0].cpu().numpy()
40
+
41
+ @staticmethod
42
+ def _distance(query_features, reference_features):
43
+ q = query_features.transpose(1, 2, 0)
44
+ r = reference_features.transpose(1, 2, 0)
45
+ q = q / (np.linalg.norm(q, axis=-1, keepdims=True) + 1e-8)
46
+ r = r / (np.linalg.norm(r, axis=-1, keepdims=True) + 1e-8)
47
+ return 1.0 - np.sum(q * r, axis=-1)
48
 
49
+ def predict(self, query_image, reference_images):
50
+ if not reference_images:
51
+ raise ValueError('Provide at least one reference image.')
52
+ query_features = self._features(query_image)
53
+ maps = []
54
+ for ref_path in reference_images:
55
+ ref_features = self._features(ref_path)
56
+ maps.append(self._distance(query_features, ref_features))
57
+ anomaly_map = np.min(np.stack(maps), axis=0)
58
+ score = float(np.percentile(anomaly_map, 95))
59
+ prediction = int(score >= self.threshold)
60
 
61
+ image = cv2.imread(str(query_image))
62
+ if image is None:
63
+ raise ValueError('OpenCV could not read the query image.')
64
+ heatmap = cv2.resize(anomaly_map.astype(np.float32),
65
+ (image.shape[1], image.shape[0]))
66
+ heatmap = cv2.normalize(heatmap, None, 0, 255,
67
+ cv2.NORM_MINMAX).astype(np.uint8)
68
+ color = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET)
69
+ overlay = cv2.addWeighted(image, 0.60, color, 0.40, 0)
70
 
71
  return {
72
+ 'anomaly_score_p95': score,
73
+ 'predicted_defect': prediction,
74
+ 'label': 'DEFECT' if prediction else 'NORMAL',
75
+ 'threshold': self.threshold,
76
+ 'anomaly_map': anomaly_map,
77
+ 'overlay_bgr': overlay,
78
  }
threshold_diagnostics.csv ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ method,threshold,balanced_accuracy,precision,recall,f1
2
+ p95_only,0.5979320049285889,0.5364650364650365,0.3888888888888889,0.9459459459459459,0.5511811023622047
3
+ p95_only,0.627547612786293,0.5546975546975548,0.4,0.918918918918919,0.5573770491803278
4
+ p95_only,0.653224778175354,0.5729300729300729,0.4125,0.8918918918918919,0.5641025641025641
5
+ p95_only,0.6589236259460449,0.5697125697125697,0.41333333333333333,0.8378378378378378,0.5535714285714286
6
+ p95_only,0.6661336302757264,0.5879450879450879,0.42857142857142855,0.8108108108108109,0.5607476635514018
7
+ p95_only,0.6769512444734573,0.6061776061776062,0.4461538461538462,0.7837837837837838,0.5686274509803921
8
+ p95_only,0.6840689063072205,0.6029601029601029,0.45,0.7297297297297297,0.5567010309278351
9
+ p95_only,0.6894094347953796,0.6426426426426426,0.4909090909090909,0.7297297297297297,0.5869565217391305
10
+ p95_only,0.693121999502182,0.6608751608751608,0.52,0.7027027027027027,0.5977011494252874
11
+ p95_only,0.6999971717596054,0.6791076791076791,0.5555555555555556,0.6756756756756757,0.6097560975609756
12
+ p95_only,0.7054347991943359,0.6544401544401545,0.55,0.5945945945945946,0.5714285714285714
13
+ p95_only,0.708498626947403,0.6297726297726298,0.5428571428571428,0.5135135135135135,0.5277777777777778
14
+ p95_only,0.7127443075180054,0.6265551265551266,0.5666666666666667,0.4594594594594595,0.5074626865671642
15
+ p95_only,0.723207026720047,0.6233376233376233,0.6,0.40540540540540543,0.4838709677419355
16
+ p95_only,0.728169071674347,0.6201201201201201,0.65,0.35135135135135137,0.45614035087719296
17
+ p95_only,0.7350677877664566,0.6169026169026169,0.7333333333333333,0.2972972972972973,0.4230769230769231
18
+ p95_only,0.7394381284713745,0.5707850707850708,0.7,0.1891891891891892,0.2978723404255319
19
+ combined_rank,0.12300000000000001,0.5364650364650365,0.3888888888888889,0.9459459459459459,0.5511811023622047
20
+ combined_rank,0.17,0.5546975546975548,0.4,0.918918918918919,0.5573770491803278
21
+ combined_rank,0.225,0.5514800514800515,0.4,0.8648648648648649,0.5470085470085471
22
+ combined_rank,0.265,0.5697125697125697,0.41333333333333333,0.8378378378378378,0.5535714285714286
23
+ combined_rank,0.32400000000000007,0.6093951093951093,0.44285714285714284,0.8378378378378378,0.5794392523364486
24
+ combined_rank,0.36949999999999994,0.6276276276276276,0.46153846153846156,0.8108108108108109,0.5882352941176471
25
+ combined_rank,0.443,0.6458601458601458,0.48333333333333334,0.7837837837837838,0.5979381443298969
26
+ combined_rank,0.505,0.6402831402831404,0.4827586206896552,0.7567567567567568,0.5894736842105263
27
+ combined_rank,0.5325,0.6179751179751181,0.48,0.6486486486486487,0.5517241379310345
28
+ combined_rank,0.5700000000000001,0.5853710853710854,0.45652173913043476,0.5675675675675675,0.5060240963855421
29
+ combined_rank,0.607,0.5900900900900901,0.475,0.5135135135135135,0.4935064935064935
30
+ combined_rank,0.61,0.5900900900900901,0.475,0.5135135135135135,0.4935064935064935
31
+ combined_rank,0.6495000000000002,0.5836550836550837,0.5,0.40540540540540543,0.44776119402985076
32
+ combined_rank,0.73625,0.6018876018876018,0.56,0.3783783783783784,0.45161290322580644
33
+ combined_rank,0.772,0.6201201201201201,0.65,0.35135135135135137,0.45614035087719296
34
+ combined_rank,0.8144999999999998,0.6383526383526383,0.8,0.32432432432432434,0.46153846153846156
35
+ combined_rank,0.875,0.5842985842985843,0.7272727272727273,0.21621621621621623,0.3333333333333333