r/computervision • • Oct 28 '26

Showcase [Anomaly Detection] PatchCore on Orange line 🍊

PatchCore running on orange line, trained on good oranges only 🍊

  • RF-DETR (instance seg) detects every orange, ByteTrack tracks them
  • Cropped orange imgs are sent to PatchCore, which compares each patch to a memory bank of normal patches → heatmap
  • Each orange is inspected multiple times while it rolls around on rolling conveyor, as anomaly could be present only on one side and not the other

This is super useful in cases where anomalous data is hard to come by, and anomaly detection training requires zero defect/anomalous labels. PatchCore runs at ~100ms on Jetson Orin AGX (at ~200 images, compute time scales with training data).

513 Upvotes

44 comments sorted by

24

u/Lethandralis Oct 28 '26

Does it just compare feature vectors with a database of known good oranges? And flag as anomaly if distance is high?

16

u/erik_kokalj Oct 28 '26

yeah that’s basically how PatchCore works, but for patches, not full images of oranges. Each patch of a new image gets compared to its nearest patch from the good images, and biggest distance is anomaly score. Tried also FoundAD (frozen DinoV3 backbone, small predictor gets trained), but it's accuracy was worse for this demo

3

u/bfyvfftujijg Oct 28 '26

How does it know which are the good images?

Do you need an anomaly-free dataset for training?

4

u/erik_kokalj Oct 28 '26

yes, we train the model on "good" images

1

u/bfyvfftujijg Oct 29 '26

So do you have to make sure no anomalous images go into training?

1

u/erik_kokalj Oct 29 '26

yep, exactly

1

u/bfyvfftujijg Oct 29 '26

Any ideas on how to find them in the first place? I have some quite large training datasets that intentionally contain anomalies, but were never labeled as such 😬

If you don’t remove anomalies prior to training do you think this model would still pick them up, just maybe with less confidence since technically they’re “in domain”?

1

u/erik_kokalj Oct 29 '26

if its a somewhat common object, you can just use large models (gemini, gpt, claude..) to annotate your dataset and find potential anomalies

2

u/gargantua5iux 27d ago

If you extract CLIP / DINO embeddings for your images, you can cluster them into good / anomalous clusters and clean your dataset. This depends on how obvious the anomaly is I assume.

2

u/Much_Highlight_1309 Oct 28 '26

How does it identify patches?

2

u/erik_kokalj Oct 28 '26

it's just a grid, input img gets split into 784 (28x28) patches (~ 8x8 px), see https://arxiv.org/pdf/2106.08265

2

u/Much_Highlight_1309 Oct 29 '26

Ah ok. Simple enough

5

u/Paseyyy Oct 29 '26

100ms for a single PatchCore inference is rough. Given 30 oranges on the screen each frame you would need 3 seconds per frame. Any plans to speed the process up to approach real time performance?

5

u/erik_kokalj Oct 29 '26

it's not running anomaly det on every frame for every orange, as that'd mean we're inspecting it at almost the same angle. There's some timeout (~200ms), so oranges actually rotate a bit before we inspect them again

1

u/Paseyyy Oct 29 '26

Good idea, but that's still 3s of processing time every 200ms no?

2

u/erik_kokalj Oct 29 '26

yep, but with batching you can make it much more efficient. The bottleneck isn't GPU util, so it can still run in realtime.

Also, FoundAD arch is usually better for prod, as anomaly det latency doesn't scale with "training" data (like it does for patchCore)

1

u/Paseyyy Oct 29 '26

Good point, I didn't think about the batch size at all! Love this project, well done

My team mainly uses EfficientAD or Dinomaly these days, both of which scale better with training set size. But we also deal with much higher variance scenes. Haven't heard of FoundAD yet

1

u/erik_kokalj Oct 29 '26

thank you! Yeah it's a bit newer (oct 2025): https://arxiv.org/pdf/2510.01934

1

u/7pointsome1 Oct 30 '26

Do you use EfficientAD from anomalib or wrote your own code ? Has EfficientAD published their code ?

3

u/Competitive-Bar-5882 Oct 28 '26

Is it a geometric function or machine learning?

1

u/erik_kokalj Oct 28 '26

depends on the model:) see my comment below!

1

u/Competitive-Bar-5882 Oct 29 '26

So PatchCore is ML and RF-DETR is geometric?

3

u/erik_kokalj Oct 29 '26

right the opposite, RF-DETR will update the weights during training, PatchCore is basically just vector similarity (across neighboring patches), training doesn't update model weights

2

u/mr_birrd Oct 28 '26

Does Roboflow now have patchcore?

3

u/erik_kokalj Oct 28 '26

yes sir, as well as FoundAD 🫡

2

u/Pale_Platypus_2058 Oct 29 '26

Any free sources?

2

u/erik_kokalj Oct 29 '26

dataset sources? or code?

3

u/Pale_Platypus_2058 Oct 29 '26

If available, both

2

u/erik_kokalj Oct 29 '26

here u go: https://universe.roboflow.com/erikrf/orange-anomaly-detection-98spz

i'm sure any ai agent can 1-shot the code if you just give it this link!

2

u/q-rka Oct 29 '26

Intel's Anomalib in GitHub is a good place to start.

1

u/Ian_610 Oct 29 '26

Is there a good place to find training data (images / vidoes) for things like this

1

u/erik_kokalj Oct 29 '26

I used roboflow universe for orange detector, for anomaly det i just published it here: https://universe.roboflow.com/erikrf/orange-anomaly-detection-98spz

1

u/beyond-the-joystick Oct 29 '26

How do you train the model and how much data did you use?

2

u/erik_kokalj Oct 29 '26 • Heartwarming

i used roboflow, it was about 250 images of "good" data, but accuracy wouldn't be that different even at ~50 images, as patchCore doesn't do "training" per se (tuning model weights), it's just vector similarity of patches

1

u/Senior_Tea_842 Oct 28 '26

Have you rolled out this solution to production?

4

u/laserborg Oct 28 '26

probably needs a global shutter camera first

1

u/MatterTraditional806 Oct 29 '26

cool! How many defective oranges did you need to train the model to recognise defects?
how did you manage to be able to not confuse defects with the orange's stem's scar?

1

u/LuxTronic 28d ago

Nice work! Great to see.

1

u/CuriousAIVillager 25d ago

People are really this wowed by patchcore?

1

u/Level_Cockroach_955 19d ago

Curious how bad the false positives get once the fruit isn't uniform.

0

u/Philipnova Oct 29 '26

When the same orange is inspected across several rotations, how do you combine the anomaly scores into one decision per tracked orange—maximum score, repeated confirmation, or something else? I’d be interested in the false-reject rate per orange, since checking more views improves surface coverage but may also give a good orange more chances to trigger an alert.

Disclosure: I’m with SingNova, a local AI hardware project. I haven’t reproduced this pipeline; this question was drafted with AI assistance.