# Anomaly Detection vs. Object Detection: When to Use Which

> Source: <https://roboflow.com/blog/anomaly-detection-vs-object-detection>
> Published: 2026-11-25 19:22:52+00:00

**Key takeaway:** Train anomaly detection on good images only — 250 sufficed for one supplier's part — and add a classifier on the flagged crops when you need the defect type, since anomaly models return a score and heatmap but not a class.

Many production processes depend on someone looking at a product, deciding whether something is wrong, and acting on it. Perhaps it's a turbine component for a power plant, a jet engine where every part has to be in place before it leaves the facility, or a medical device where a microscopic flaw can harm a patient.

It's difficult for people to check thousands of units by eye, because they get tired or distracted, and skill varies from one inspector to the next. In those situations, it makes sense to deploy a vision system that can work alongside your team and provide a second set of eyes. Vision systems can check units in real time, determine if a problem exists in milliseconds, and flag the ones an operator should pull aside to recheck or rework.

Vision systems like this usually run on a model that's trained on images from your production line, because most general-purpose AI models haven't seen your parts and are often too slow or costly to run on thousands of units per day. When you are designing a system and getting ready to train a model, there are different tools and strategies you might want to implement. This article looks at two of them, a detector and an anomaly detection model, and where each one tends to fit.

How the two approaches differ

Both of these approaches can be used for finding defects, but they differ in a few ways:

An object detector (or instance segmentation model) learns the classes you label and returns a box or mask with a class name. You can use bounding boxes/masks in pixel space with some logic to eg. detect whether all the parts are where they should be.

An anomaly detection model trains on good images only. It compares each patch of a new image to what it saw in training and returns an anomaly score and a heatmap.

In this article, “a detector plus rules” means an object detection, instance segmentation, or keypoint model with a few lines of logic on top of its output.

Detector plus rules

Anomaly detection

Training data

Labeled examples of every class, including each defect type

Good images only, no labels

Output

Boxes or masks with class names

Anomaly score, heatmap, pass/fail

Tells you the defect type

Yes

No

Catches defects it never saw

No

Yes, if its feature extractor can represent them

Measures sizes and distances

Yes, with code on top

No

That difference points to a good first question. Do you need to find a specific thing? A detector is trained to find the things you label and tell them apart from everything else in the image, whether that's a type of defect, a part, or the empty spot where a part should be. An anomaly detection model isn't trained to recognize anything in particular. It learns what normal looks like and tells you when an image departs from it, so it can say that something is off but not what it is.

In practice, two things matter most:

Anomaly detection only needs good images. There's nothing to label, and any defect images you do have go into validation and test to help set the threshold. In one supplier project, 250 good images of a part handled every test case. That makes it a good first step even if you'll want a detector later.

Anomaly detection tells you pass or fail, not the defect type. For many lines that's enough, since a bad orange is rejected whether it's bruised or moldy. If you need the type or severity, add a classifier on the crops the anomaly model flags.

When a detector plus rules tends to fit

A detector plus rules is a good place to start when you can name what you're looking for.

Known defects on identical parts

Manufactured parts are close to identical from one unit to the next, and the defects that matter are often few and well defined: a nut is missing, a connector isn't seated, a label is on the wrong side. In that case the defect is just another object you can label.

In the image above, a segmentation model checks the fasteners on a carburetor. A missing nut is one of the classes the model was trained on, so the bare stud is a detection of its own, and the rule is simple: every stud has a nut. The detector also tells you which stud is missing its nut, which an operator can act on right away, and it's easy to debug when it gets something wrong. You do need examples of the defect, but for something like a missing nut they're easy to stage: leave a few off and take some photos. Our webinar Build a Missing Part Detection System with Computer Vision (opens in a new tab) walks through how that system was built.

Measuring distances and tolerances

This was a question from our recent anomaly detection webinar (opens in a new tab). If you need to know whether a distance, diameter or angle is within spec, find the features you measure from with an object detection, segmentation or keypoint model, then compute the measurement in code.

Anomaly detection isn't a good fit here. The models run at a coarser resolution than precise measurement needs, and they compare the look of patches, not exact positions, so a hole that's 0.1 mm out of place looks perfectly normal patch by patch. And since you already know exactly what to measure, there's nothing left for an anomaly model to discover.

Other cases where a detector fits better

Finding or counting normal objects - anomaly detection only finds what's unusual. If you want to count every apple on the belt, train a detector

Layout and arrangement problems - anomaly models look at one patch at a time. A part shifted a few millimeters, items in the wrong order, or one item too many can look normal patch by patch

Lots of labeled data - if you already have plenty of labeled defect examples, an object detection model will usually match or beat an anomaly detector

When anomaly detection tends to fit

Anomaly detection is worth trying first when you can't list everything that might go wrong, or when you have no examples of it yet.

Many possible defects

A PCB can have hundreds of components, and each one of them could be missing, tombstoned or the wrong part. Solder joints can bridge, crack or come out cold, traces can get scratched, and debris can land anywhere. Training a detector means labeling examples of each of those, and the rare ones are exactly the ones you don't have photos of.

Anomaly detection turns the problem around. You train it on boards that passed inspection, and it flags anything that doesn't look like them, including defect types nobody thought to label. The same goes for new products. One pattern we see is turning on anomaly detection as soon as a new part starts coming down the line, before anyone knows how it tends to fail, and retraining it as more good images come in.

One limit to keep in mind: an anomaly model can only notice differences its feature extractor can see (a ResNet for PatchCore, DINOv3 for FoundAD). Visible surface defects are well within that. Something like the wrong text printed on a label may not be.

Problems you can't predict

Some problems can't be listed ahead of time. On a conveyor carrying pebbles, almost anything could end up on the belt, and you can't collect photos of all of it to train a detector.

In the example above, we trained an anomaly detection model on images of normal pebbles. It flagged a stray bolt, and later in the same video it flagged a dark piece of debris. The two objects look nothing alike, and nobody labeled either one. We had watched the video many times and spotted the bolt, but we only noticed the debris after the model flagged it.

High-variance objects

Fruit, vegetables, eggs and other natural products don't come out identical. Every orange has a slightly different size, color and peel texture, and the defects vary just as much: bruises, rot, mold, cuts, stem damage. There's no fixed shape for a detector to learn, so you'd need a lot of labeled examples to cover them all.

An anomaly detection model learns the normal range from good examples and flags whatever falls outside it. The catch is that your training set has to cover that whole range. If all your training oranges are large and bright, a small pale one will look anomalous even when it's fine, so collect good examples across sizes, colors, lighting and seasons.

When to use both

The orange demo above uses both approaches. An RF-DETR instance segmentation model finds and tracks each orange, the orange is cropped and its background masked out, and only that crop goes to the anomaly model. Do the same whenever you're checking one kind of item in a busy scene: each item fills the model's input, so small spots stay visible, and nothing on the conveyor can make a good orange look anomalous.

Where to start for your situation

Situation

Where to start

A few known defects on identical parts (missing nut, missing label)

Object detection + rules

Measuring distances, diameters or angles

Detection, segmentation or keypoints + code

Many possible defects, or new ones keep appearing (complex PCB)

Anomaly detection

Foreign objects you can't predict (debris on a conveyor)

Anomaly detection

Natural products with a lot of variety (fruit, vegetables, eggs)

Anomaly detection

A specific item in a busy scene

Detection or segmentation, then anomaly detection on each crop

No defect examples yet

Anomaly detection

You need the defect type or severity

Detector, or a classifier on anomaly-flagged crops

Counting or locating normal objects

Object detection

Get started

Create an Anomaly Detection project in Roboflow, upload good images, mark them as normal, and train PatchCore or FoundAD (step-by-step guide). FoundAD is usually a bit more accurate, while PatchCore is faster but uses more memory as your dataset grows; PatchCore Anomaly Detection: Tutorial and FoundAD Comparison has the numbers. To chain a detector and an anomaly model like in the orange demo, build it as a Roboflow Workflow.

To see both models trained and run on real examples, including the pebbles, oranges, and eggs, watch the webinar recording.
