Skip to main content
Back

MEDISEG Trains AI to Spot Overlapping Pills With 3x Better Accuracy

A new instance-segmentation dataset captures overlapping pills in dosette boxes, and few-shot experiments show it transfers better than existing pill datasets.

Pro

  • MEDISEG releases 8,262 pill images with instance segmentation masks across 32 classes, focused on overlapping and occluded scenes
  • Captured in real dosette boxes under varied lighting, unlike prior datasets that used isolated pills in controlled conditions
  • YOLOv8 and YOLOv9 baselines reach 99.5% mAP@50 on 3-Pills and 80.1% on the 32-Pills subset
  • Few-shot base training on MEDISEG beats CURE by 20-30 accuracy points on overlapping test images
  • Dataset on Figshare under CC BY 4.0 in COCO format, code on GitHub
  • Limitations: single-device capture, Hong Kong-specific drug metadata, no clinical validation yet

Pill recognition looks like a solved computer vision problem until you actually put pills in a dosette box, dim the lights, and let a few tablets rest on top of each other. That is the gap a new dataset called MEDISEG is aimed at, and the authors back it up with YOLOv8/YOLOv9 baselines plus a few-shot detection study that shows base training on MEDISEG transfers noticeably better to unseen pills than the current go-to public dataset.

Why existing pill datasets keep breaking

Medication mix-ups are not a fringe safety issue. An average of 8.9% of fatalities for which adverse events of medical treatment were the primary cause were ascribed to adverse drug events over the period from 1980 to 2014, and the risk rises sharply with age and polypharmacy. AI-based pill identification could help, but the training data has not kept up with the problem.

Chart of adverse event trends and age distribution

The authors survey five existing datasets and find a common pattern: images are typically taken under optimal lighting conditions with high-quality cameras and feature single, unobstructed pills. The NIH Pillbox program, once the largest reference collection, was discontinued and its consumer-grade images are no longer available. The CURE dataset, one of the few still public, has only partial instance segmentation and leans on synthetic images. None of them look much like a real dosette box on a kitchen counter.

What is inside MEDISEG

MEDISEG provides instance segmentation annotations for 32 distinct pill types across 8,262 images, and it ships in two configurations:

  • 3-Pills subset: three deliberately confusable tablets, two sharing shape and two sharing a peach-like color, designed to force models to learn fine-grained cues.
  • 32-Pills subset: a wider set including multiple near-identical small white tablets, with scenes containing anywhere from one to 13 pills per frame.

Images were captured with an iPhone 12 Pro Max under varied lighting angles and intensities, using a standard four-by-seven dosette box that naturally produces overlaps and partial occlusions from the box walls. Each image was annotated with instance segmentation masks that accurately delineate pill borders, even in overlap or partial occlusion instances, using COCO Annotator, with a second reviewer checking every image.

The dataset ships in COCO format with a metadata.csv mapping each pill to its Hong Kong drug registration number, brand name, active ingredients, and sale requirement (OTC, pharmacy-only, or prescription-only). It is released on Figshare under CC BY 4.0, and the training notebooks live on GitHub.

YOLO baselines and the few-shot twist

The authors train YOLOv8 and YOLOv9 with a 70/20/10 split and tune hyperparameters with a genetic algorithm over 70 iterations. The headline numbers: mAP@50 of 99.5% on the 3-Pills subset and 80.1% on the 32-Pills subset. YOLOv8 converges faster early on, but YOLOv9 pulls ahead on mAP@50-95, which is the stricter localization metric.

The more interesting experiment is the few-shot detection study. Using the FsDet framework, a two-stage training paradigm that decomposes training into a base learning stage and a few-shot fine-tuning stage (Faster R-CNN with a ResNet backbone and FPN, with only the ROI heads fine-tuned on novel classes), they compare base-training on MEDISEG against base-training on CURE, then evaluate on a held-out set of overlapping, occluded multi-pill scenes.

Cropped dosette box slots showing pill arrangements

On the overlap-only test set, the gap is large:

SettingBase: CURE (fg acc)Base: MEDISEG (fg acc)
1-shot0.1310.406
5-shot0.3720.625
10-shot0.5580.740

Base training on MEDISEG was associated with lower region proposal and total detection losses, indicating more stable localisation and classification behaviour in visually complex scenes. In plain terms, seeing real overlap and clutter during pretraining teaches the model a representation that generalizes to new pill types with far fewer labels.

Where it helps and where it does not

The obvious use case is medication verification at the bedside or in home dosette preparation, where new formulations show up all the time and labeled data is scarce. The few-shot results suggest MEDISEG-pretrained detectors could adapt to a novel tablet with as few as 5 to 10 annotated instances and still handle cluttered arrangements.

Limitations worth naming:

  • Single capture device. Every image was shot on the same iPhone. Cross-device robustness is untested.
  • Fine-grained color confusions remain. On the 3-Pills subset, most misclassifications came from two pills that look nearly identical from the side profile.
  • Not clinically validated. The authors are explicit that prospective evaluation in live healthcare or pharmacy environments would be required prior to deployment.
  • Regulatory metadata is Hong Kong specific, so linking pills to formularies elsewhere requires extra work.

For anyone building pill-identification pipelines, dosette-preparation checks, or adherence apps, MEDISEG is currently the most realistic public benchmark for the messy end of the problem, and the COCO format means dropping it into Detectron2, Ultralytics, or a custom PyTorch loop is a matter of pointing at the annotation JSON.