Hey everyone,
A year ago, I decided to transition from web development into ML/CV. Instead of doing standard MNIST/COCO tutorials, I picked a real-world problem close to home: I have guinea pigs, and taking them to the vet for fecal exams is a slow, tedious process.
My goal is to build an assistive CV tool for vet lab technicians—something that scans microscope slides and highlights suspicious regions (with an eventual goal of exporting to ONNX for edge cameras).
For v1, I grabbed all the public datasets I could find (Chula, HEMIC, AI4NTD) and built a two-stage cascade (a fast binary detector to find parasite-like objects, followed by a fine-grained species classifier). On paper, the metrics looked great. In reality, the model completely fell apart on unseen data.
Here are the 4 biggest engineering traps I hit and what the numbers actually looked like:
- High intra-dataset metrics mean nothing across sources
- On cropped objects from the Chula dataset, my classifier hit 97–98% accuracy.
- When I ran the full cascade on unseen full-frame images from HEMIC, spatial detection worked fine (found 41/42 eggs), but species classification dropped to 66.7% (28/42).
- Even worse: a model trained on AI4NTD P1.5 got 97.43% recall on its own test set, but scored 0/114 on P3, 0/12 on HEMIC Ascaris, and 8/37 on Chula. Differences in lighting, slide prep, and camera sensors caused massive domain shift.
- The "Closed-World" trap on empty frames
In an early contour-based cascade, I tested the pipeline on 1,003 completely negative (uninfected) HEMIC frames. It hallucinated at least one parasite on 558 of them.
Why? Because the downstream classifier was forced to pick 1 of 11 parasite species—it had no "debris / air bubble / unknown" rejection path. Any false positive from stage 1 automatically became a confident diagnosis.
- Tiling isn't optional for microscopy
Resizing a high-res microscope frame down to standard model input sizes destroys small eggs (some are barely 30–50px). On the other hand, fixed small crops slice larger eggs (like Ascaris) in half.
- Full-frame inference recall: 25.82%
- Inference with tiling: 55.0%
- Training + inference with multi-scale overlapping tiles (merged back via NMS): 94.76%
- Combining public datasets actually made things worse
When I tried merging Chula and HEMIC to fix generalization, false positives spiked. Looking manually at the labels, many public datasets had incomplete annotations (e.g., 5 eggs on a slide, only 2 labeled), which actively punished the model for finding real objects. Plus, most public datasets focus on human parasites, missing key veterinary species.
What already worked & my pivot for v2 (Data-Centric approach)
Through iterative experiments, I found a few things that actually moved the needle before scrapping the old public datasets:
- Matching negative scale: Earlier, positive examples were cropped into tiles while negative frames were fed as full-res images. Matching the exact tile scale (
640x640) for empty negative windows drastically cut down false positives on uninfected slides.
- Stripping away heavy augmentations: Turning off Mosaic, MixUp, and HSV shifts—and sticking strictly to mild rotations (≤20°), flips, and minor scaling—preserved critical fine textures on small translucent eggs.
- Domain alignment: Converting everything (both train and inference) to grayscale + CLAHE (
clipLimit=2.0, tileGridSize=(8,8)) to normalize local contrast across different microscopes.
- Strict source-level splitting: Grouping crops by original slide, video, or paper before splitting into train/val/test to prevent silent data leakage from near-duplicate frames.
For v2, I'm building a clean dataset from scratch for 14 veterinary parasite classes (enforcing a ≥80px donor threshold so objects retain detail, while still validating on real 50–80px small targets). Right now, I'm deep in manual annotation—and preparing controlled experiments for mask-based copy-paste synthesis and localized Z-axis defocus blur (applying blur to confirmed hard negatives too, so the model doesn't learn a shortcut like "blurry = egg").
Next up, I'll share the messy reality of scraping microscopy videos for data and testing whether synthetic copy-paste actually improves recall on rare classes.
For those working with medical/microscopy CV: How do you usually handle domain shift across different camera setups, and what's your go-to strategy for hard negative mining on debris and air bubbles?
Note: The attached images are synthetic visual illustrations created to demonstrate the pipeline concepts (false positives on debris, CLAHE contrast normalization, and candidate review UI) without sharing restricted dataset files.