DEV Community

orville wang
orville wang

Posted on

Building On-Device ML for iOS Photo Management

The average iPhone camera roll has over 10,000 photos. Most are never looked at again. Manual cleanup does not scale. Sending your photo library to a cloud API for classification is a privacy disaster waiting to happen. The answer is on-device machine learning.

Why On-Device Matters

Your camera roll contains the most personal data on your phone. Passport photos, bank screenshots, private conversations, medical documents. Uploading this to any server breaks fundamental trust.

Apple built the Neural Engine into every iPhone since the A11 chip. It runs ML inference at low power with exceptional throughput. For photo classification, it is the perfect workload — embarrassingly parallel, latency-sensitive, and privacy-critical.

The Model Pipeline

Screenshot Detection

Screenshots have distinct visual signatures: UI elements, status bars, text overlays, app chrome. A fine-tuned vision model classifies them with >95% accuracy. The key insight: status bar patterns are highly consistent across iOS versions, making them reliable features.

Perceptual Hashing for Duplicates

Perceptual hashing (pHash) computes a fingerprint for each image. Similar photos cluster below a distance threshold. This catches burst-mode variants, re-downloaded files, and near-identical edits. Running pHash on the CPU while the Neural Engine handles classification maximizes throughput.

Blur Detection via Laplacian Variance

Laplacian variance measures sharpness. Low variance indicates motion blur or a pocket shot. This is fast enough to compute during scrolling — sub-millisecond per image.

Sensitive Content Detection

OCR extracts text from images. The system flags document-like patterns: ID cards, passports, tax forms, bank statements. These are not auto-deleted — they are surfaced for user review. Privacy means never making decisions without consent.

Performance Considerations

Processing 10,000 photos requires careful orchestration:

  • Batch inference via VNImageRequestHandler with a serial queue to avoid thread explosion
  • Thumbnail-first approach: classify using low-resolution thumbnails first, full-resolution only for comparison
  • Background processing with BGTaskScheduler so the user never sees a loading spinner
  • Result caching: pHash values and classifications stored in a local SQLite database, avoiding recomputation

UX: The Swipe Interface

Classification is half the problem. The other half is making decisions fast. A Tinder-like card interface — swipe right to keep, left to delete — turns a tedious chore into a 5-minute activity. The AI pre-selects the likely action so most swipes are confirmations, not decisions.

Lessons Learned

  • Start with one model. We shipped three ML features at launch (screenshots, duplicates, blur). Focusing on duplicates alone would have been a cleaner v1.
  • Privacy messaging outperforms feature messaging. Users care more about on-device processing than any feature we could list.
  • Screenshots are the #1 storage culprit. Most users have 20-30% of their camera roll as forgotten screenshots.

On-device ML is no longer a differentiator — it is table stakes for any app that touches personal data.


Swipe Cleaner uses on-device Core ML for iOS photo management. View on OpenNomos.

Top comments (1)

Collapse
 
topstar_ai profile image
Luis

Great article. On-device ML is a great fit for photo management because it balances the three things users care about most: privacy, speed, and offline availability. Processing images locally with Core ML and the Neural Engine avoids unnecessary cloud uploads while delivering a much more responsive experience.

What stands out is that the real value isn't just image classification—it's designing an end-to-end workflow that helps users make decisions quickly. Combining efficient models with thoughtful UX, like smart grouping and actionable suggestions, is what turns ML into a genuinely useful feature rather than a technical demo. Nice work!