Keep the Needle, Prune the Haystack: Defect-Preserving Token Pruning for Efficient Zero-Shot Anomaly Detection
The paper proposes KeepAD, a defect-preserving token pruning framework that strategically retains anomalous tokens while aggressively removing redundant normal tokens across different network depths, enabling efficient zero-shot anomaly detection with up to a 7.9× speedup and minimal performance degradation.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are a detective trying to find a single, tiny scratch on a brand-new, expensive car. You have a super-smart robot assistant with a camera that can see every single inch of the vehicle. But here's the catch: the robot is so thorough that it inspects every square millimeter of the car, even the parts that are perfectly clean and shiny. It spends 99% of its time checking the clean paint, just to be absolutely sure, before it finally spots the scratch. This is incredibly slow and wasteful, especially if you have to inspect thousands of cars a day.
This is exactly the problem facing modern "Zero-Shot Anomaly Detection." In the world of computer vision, "Zero-Shot" means a computer can spot defects in things it has never seen before—like finding a crack in a new type of medical scan or a flaw in a factory part it wasn't trained on. To do this, these computers use massive "Vision Transformers" (ViTs), which are like giant brains that break an image into thousands of tiny puzzle pieces (called "tokens") and analyze them all. The problem is that these brains are heavy and slow. They treat a perfectly normal image and a broken one the same way, crunching numbers on every single piece of the puzzle, even though the "bad" piece is usually just a tiny speck in a sea of "good" ones.
Enter KeepAD, a new method that acts like a smart, risk-aware editor for these giant brains. Instead of letting the robot check every single inch of the car, KeepAD teaches the robot to quickly scan the surface, keep an eye on the most suspicious spots, and ignore the boring, perfect parts. But it does this with a very careful rule: "Don't throw away the evidence." If the robot is unsure if a spot is a scratch or just a shadow, it keeps it. It only deletes the boring, safe parts. The result? The robot becomes incredibly fast—up to nearly 8 times faster in some tests—without missing the tiny defects it's supposed to find. It's like having a detective who can spot a needle in a haystack in a fraction of the time, simply by ignoring the hay that is definitely just hay.
The Problem: The "Haystack" Trap
In the world of industrial and medical safety, finding defects is a game of "find the needle in the haystack." Most of the time, the images are perfect (the hay), and the defects are rare and tiny (the needle). Current AI models are like a very diligent but slow librarian who reads every single page of every book in the library to find one typo. Even though the typo is only on page 42, the librarian reads pages 1 through 41 with the same intensity.
This is inefficient. The paper points out a specific danger called the "Asymmetric Pruning Risk." If you try to speed things up by deleting "unimportant" pages (tokens), you might accidentally throw away the page with the typo. In normal image recognition (like identifying a cat), deleting a few pixels doesn't matter much because the cat's face is everywhere. But in defect detection, the "cat" is the whole image, and the "defect" is a tiny, hidden detail. If you delete the wrong token, you lose the only evidence of the problem.
The Solution: KeepAD's Two-Stage Strategy
The authors of this paper propose KeepAD (Keep Anomaly Detection), a system that acts like a smart filter. It doesn't just delete things randomly; it uses a two-step process that changes its strategy as it "looks" deeper into the image.
Stage 1: The "Safety Net" (Shallow Layers)
When the AI first looks at the image, it's not yet sure what a defect looks like. It's like looking at a blurry photo. If it tries to guess which parts to delete now, it might accidentally delete the defect. So, KeepAD uses a Coverage-Preserving strategy. Imagine the image is a grid of 2x2 squares. KeepAD says, "No matter what, we must keep at least one piece from every single 2x2 square." This ensures that even if a defect is tiny and isolated, it won't be completely wiped out. It also adds a "Rescue" mechanism: if a spot looks slightly risky, it gets saved even if it's not the most obvious thing. This stage is conservative; it's better to keep a little extra hay than to lose the needle.
Stage 2: The "Sniper" (Deep Layers)
As the AI processes the image deeper, it starts to understand the difference between normal texture and a real defect. Now, it can be more aggressive. KeepAD switches to an Anomaly-Adaptive mode. It uses "prototypes"—mental templates of what "normal" looks like and what "abnormal" looks like. If a token clearly matches the "normal" template, it gets deleted. If it looks like a defect, it stays.
Crucially, this second stage is Image-Adaptive. It doesn't use a fixed rule for every picture. If an image looks very suspicious (lots of potential defects), KeepAD keeps more tokens to be safe. If the image looks very clean, it deletes more tokens to save time. It's like a security guard who checks a suspicious bag thoroughly but just glances at a clear, empty one.
The Secret Sauce: Learning Without Losing
One of the hardest parts of this system is teaching the AI to make these decisions. If the AI deletes a token, the computer can't "see" it anymore to learn from it. To solve this, the authors use a trick called Dense-to-Sparse Self-Distillation.
Imagine a teacher and a student. The "Teacher" is the full, slow AI that looks at every token. The "Student" is the fast, pruned AI that only looks at a few. During training, the Teacher looks at the whole image and says, "Hey, look at this spot! Even though it looked boring at first, it turned out to be important later." The Student learns to pay attention to those spots before it deletes anything. This allows the Student to become fast without needing to see the whole picture every time. Once the training is done, the Teacher is gone, and the Student runs the show alone, super fast.
The Results: Fast and Accurate
The researchers tested KeepAD on 13 different benchmarks, ranging from industrial parts (like metal sheets and circuit boards) to medical images (like brain scans and X-rays).
- Speed: KeepAD is a speed demon. It reduced the number of tokens the AI had to process to less than 20% of the original amount. In the most aggressive setting, it was 7.9 times faster than the strongest existing method based on CLIP (a famous AI model).
- Accuracy: Despite throwing away so much data, it didn't miss the defects. The drop in accuracy was tiny—less than 2.7 percentage points on average. In many cases, it was almost as accurate as the slow, full version.
- Reliability: The system successfully avoided "complete misses" (where a defect is entirely deleted). The "Coverage-Preserving" stage in the beginning was key to this, ensuring that no tiny defect was ever lost in the shuffle.
Why It Matters
This paper doesn't just suggest a new way to make AI faster; it solves a specific, dangerous problem where speed usually comes at the cost of safety. By proving that you can prune (delete) most of the data without losing the critical "needle," KeepAD makes it possible to run high-level defect detection on real-world systems that need to be fast, like assembly lines or emergency medical screening. It shows that with the right strategy—being careful at the start and smart at the end—you can have your cake (speed) and eat it too (accuracy).
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.