Implementing AI Document Authenticity Verification (Anti-Fraud) in a Mobile App
Forged passports printed on a laser printer have passed basic OCR checks in 30–40% of cases since 2022, according to industry reports. This is not theoretical—these are actual loan applications, account registrations, and employee onboarding with forged documents. Classic rules (MRZ matching with visual zone, date format) are insufficient. You need an ML layer that sees what rules don't describe.
What Exactly the AI Model Verifies
Document authenticity verification on a mobile device consists of several independent signals:
Texture and print artifact analysis. A genuine passport is printed on an intaglio press with tactile elements and specific raster structure. A scan or photo of a printout has JPEG-artifact patterns characteristic of consumer printers: blockiness on guilloché, loss of microprinting, even brightness where relief shadows should be. A CNN model trained on such examples outputs forgery_score as a continuous value—not binary "fake/real".
Geometric consistency. Text fields in a real passport are positioned at strict pixels relative to physical markers. Homography transformation aligns the document to a standard plane; MRZ, photo, and birth date fields are compared against a template using affine matrix. Deviation from template >2px—warning signal, >5px—high probability of editing.
Cross-field verification. Name in MRZ must match the visual zone, birth date—the MRZ check digit (ISO 7501-1 algorithm), document number—the database of lost/invalid documents (if external API connected, e.g., Interpol I-24/7 or national registries).
Architecture: On-Device vs Server-Side
Choice depends on privacy and latency requirements:
| On-device (CoreML / TFLite) | Server-side | |
|---|---|---|
| Latency | 300–800 ms | 1–3 s |
| Privacy | Data doesn't leave device | Requires image transmission |
| Model size | 5–50 MB in app | No constraints |
| Model freshness | OTA update via CoreML Model Deployment | Server deploy |
| Offline | Yes | No |
For most KYC scenarios, use a hybrid approach: on-device model performs quick initial check (capture quality, basic artifacts), heavy anti-forgery inference—on server with GPU. User sees progress indicator, not 3-second wait.
Implementing CoreML Model on iOS
Basic iOS pipeline:
// Model loading
let config = MLModelConfiguration()
config.computeUnits = .cpuAndNeuralEngine
let model = try DocumentAuthenticityModel(configuration: config)
// Preprocessing — normalization and crop to Region of Interest
let input = try MLMultiArray(shape: [1, 3, 224, 224], dataType: .float32)
// ... fill with pixels from CVPixelBuffer
// Inference
let prediction = try model.prediction(image: pixelBuffer)
let forgeryScore = prediction.forgery_score // Float, 0.0 – 1.0
ANE (Apple Neural Engine) on A14+ processes a 224×224 document in ~40 ms. On iPhone SE 2nd gen without ANE—~350 ms. The difference is significant; computeUnits threshold must be adapted to minimum supported device.
Model updates via CoreML Model Deployment in CloudKit or custom endpoint with signed .mlmodel file. Don't hardcode the model in the bundle if planning updates—IPA grows, each model update requires a release.
TensorFlow Lite on Android
Android implementation via TFLite + GPU Delegate or NNAPI:
val options = Interpreter.Options().apply {
addDelegate(GpuDelegate())
setNumThreads(4)
}
val interpreter = Interpreter(loadModelFile(assets, "doc_auth_v2.tflite"), options)
val inputBuffer = TensorImage.fromBitmap(preprocessedBitmap)
val outputBuffer = TensorBuffer.createFixedSize(intArrayOf(1, 2), DataType.FLOAT32)
interpreter.run(inputBuffer.buffer, outputBuffer.buffer)
val forgeryScore = outputBuffer.floatArray[1] // index 1 — "forgery" class
GPU Delegate reduces latency on Snapdragon 8 Gen 1 from ~600 ms to ~90 ms for EfficientNet-B2 model. On budget devices without GPU Delegate, the difference is less noticeable—NNAPI with automatic accelerator selection is better.
Model Training and Fine-Tuning
Ready-made anti-forgery models in public access are limited and quickly obsolete—fraudsters adapt. Train on synthetic data: real documents + augmented fakes (JPEG-compress, Gaussian noise, PrintScan simulation via albumentations library). Architecture—EfficientNet-B0 or MobileNetV3 for accuracy/speed balance.
After deployment, a feedback loop is critical: documents with borderline forgery_score (0.4–0.6) go to manual markup by operators and model retraining. Without this, the model degrades on new forgery patterns within 3–6 months.
Implementation Stages
Audit document types and scenarios → collect dataset → train/validate → convert to CoreML / TFLite → integrate in mobile client → A/B test with human verifier → threshold tuning → production → monitor drift.
Timeline: integrate ready-made model without fine-tuning—from 3 weeks. Full cycle (dataset, training, mobile integration, feedback loop)—2–4 months. Cost is calculated individually.







