Inspiration

A signature can authorize a contract, approve a transaction, support an insurance claim, or become part of a legal record. When that signature is questioned, the consequences can extend far beyond a single document: financial loss, fraud investigations, disputes, and loss of trust.

The challenge is that signature examination is rarely a single-step decision. A reviewer may need to locate the relevant signature inside a document, compare it with trusted specimens, account for natural variation between genuine signatures, identify meaningful structural differences, and communicate the findings clearly enough for another person to review.

We wanted to build an AI system that could bring those steps together into one coherent workflow.

That became DocLens.

DocLens is an AI-assisted forensic signature analysis platform that transforms a questioned document and trusted reference signatures into a structured investigation containing a calibrated assessment, multi-reference comparison evidence, structural measurements, visual evidence, and an explainable report.

Our core principle is simple:

Don't just get a verdict. See the evidence.

The goal is not to replace qualified forensic examination. It is to make the analysis workflow more accessible, organized, inspectable, and efficient by connecting the computational result to the evidence that produced it.


What it does

DocLens turns signature verification into an end-to-end investigation rather than a single model prediction.

A user creates a case, provides document context, uploads a questioned document and trusted reference specimens, and lets DocLens perform the analysis pipeline.

The workflow

Document → Detection → Representation → Comparison → Evidence → Assessment → Explanation → Report

1. It starts with the document

Users do not have to manually crop the signature before analysis.

DocLens accepts:

  • JPEG/JPG
  • PNG
  • WebP
  • BMP
  • PDF

For PDFs, the backend can inspect pages, consider embedded images, evaluate candidate representations, and select the strongest analyzable representation for the downstream signature pipeline.

2. It automatically locates the signature

The OpenCV-based detection pipeline evaluates candidate regions using multiple visual signals, including:

  • aspect ratio
  • region area
  • ink density
  • horizontal span
  • vertical position
  • compactness
  • connected components
  • text-like penalties

The selected signature region is retained in document coordinates so the result can later be presented in its original document context.

3. It builds a deep visual representation

The extracted signature is processed through a pretrained Torchvision ResNet18 feature extractor.

The classification layer is removed and the resulting representation is converted into a normalized 512-dimensional embedding.

This representation provides the basis for comparing the questioned signature with trusted specimens.

4. It compares against the entire reference set

DocLens does not rely on one arbitrary reference image.

The questioned signature is compared against the supplied trusted references using normalized cosine similarity.

The system retains several signals from the reference set:

  • best-reference similarity
  • median reference similarity
  • reference-profile similarity
  • reference consensus
  • score spread across references

This allows the assessment to consider how the questioned signature behaves relative to the whole reference set.

5. It measures structural evidence

DocLens adds a classical computer-vision layer that examines differences between the questioned signature and its strongest reference comparison.

The current structural measurements include:

  • Stroke Width Variation
  • Letter Proportion Inconsistency
  • Baseline Deviation
  • Pen Lift Positions
  • Slant Deviation

These measurements are produced from image masks, connected components, distance transforms, projection profiles, baseline estimation, and principal-axis analysis.

DocLens also calculates a self-consistency signal from the questioned signature itself using spatial embedding consistency and ink-profile regularity.

6. It produces a calibrated assessment

The final assessment is generated from the comparison pipeline using the repository's frozen CEDAR calibration:

  • 95% deep embedding weight
  • 5% classical feature weight
  • 0.9271469 calibrated decision threshold

The assessment is therefore connected to a defined calibration protocol rather than being an arbitrary percentage selected for the interface.

7. It shows visual evidence

DocLens uses Grad-CAM-based explainability to identify visual regions associated with differences between the questioned signature and its strongest reference representation.

The evidence layer can expose:

  • detected signature boundaries
  • contextual document imagery
  • visual hotspots
  • hotspot intensity
  • numbered evidence markers
  • baseline location
  • pen-lift positions
  • ranked structural differences

The reviewer can therefore move from the assessment back toward the visual evidence that contributed to the analysis.

8. It explains the findings

The deterministic analysis produces structured findings.

When configured, DocLens uses Groq with llama-3.3-70b-versatile to turn those findings into a readable forensic-style narrative.

The reporting layer is instructed to preserve the calculated assessment and supplied findings rather than inventing evidence.

If the Groq service is unavailable, DocLens falls back to a deterministic report template.

9. It produces a complete report

The investigation can be exported as a professional PDF containing the case information, assessment, findings, evidence, and analysis summary.

The result is a complete workflow:

Questioned document → computational analysis → evidence → explanation → investigation report


Why the approach is technically interesting

The central engineering challenge was not simply placing an AI model behind a web interface.

DocLens combines several different forms of evidence into one investigation:

                 QUESTIONED DOCUMENT
                         │
                         ▼
                Document Processing
                         │
                         ▼
              Signature Localization
                         │
                         ▼
                Signature Extraction
                         │
            ┌────────────┴────────────┐
            ▼                         ▼
     Deep Visual Signal        Structural Signal
            │                         │
            ▼                         ▼
     Multi-reference          Feature Differences
       Comparison                     │
            │                         │
            └────────────┬────────────┘
                         ▼
               Reference Consensus
                         │
                         ▼
                 Self-Consistency
                         │
                         ▼
               Calibrated Assessment
                         │
              ┌──────────┴──────────┐
              ▼                     ▼
       Visual Evidence          Findings
              │                     │
              └──────────┬──────────┘
                         ▼
                 AI-Assisted Report
                         │
                         ▼
                    PDF Output

The interesting part is the connection between these layers.

A questioned signature is first found in context, converted into a machine-readable representation, compared against multiple references, examined through independent structural measurements, connected to visual evidence, and finally converted into a human-readable investigation.

That architecture makes the system useful as an analysis and decision-support workflow, rather than treating the model output as the entire product.


Validation and Results

We wanted the project to have measurable evidence behind its claims, so the repository contains an explicit CEDAR evaluation and calibration workflow.

CEDAR writer-disjoint evaluation

The frozen production calibration uses a writer-disjoint evaluation protocol with:

  • 55 writers
  • 1,320 genuine signatures
  • 1,320 forged signatures
  • 44 calibration writers
  • 11 held-out test writers
  • 8 enrollment signatures per writer
  • 1,760 calibration comparisons
  • 440 unseen test comparisons
  • seed 42

The CEDAR benchmark uses already-cropped signatures, so document-level signature localization is intentionally bypassed during this benchmark.

Recorded results

Metric Calibration Unseen Test
Balanced Accuracy 93.11% 96.50%
FAR 5.40% 3.03%
FRR 8.38% 3.98%
ROC AUC 99.59%
EER 3.41%
Comparisons 1,760 440

The frozen calibration produced the current 0.9271469 threshold with 95% embedding / 5% classical-feature weighting.

These results demonstrate the behavior of the signature-comparison pipeline under the recorded CEDAR writer-disjoint protocol. They are not presented as universal real-world forensic accuracy.

The repository also includes a dedicated multi-seed validation tool designed to evaluate stability across writer-disjoint splits using seeds 42, 43, 44, 45, and 46.

The validation tooling intentionally keeps the production calibration separate from experimental validation so that a benchmark experiment cannot silently change the deployed decision boundary.


How we built it

DocLens combines a React web application, FastAPI backend, computer vision, deep learning, cloud infrastructure, and AI-assisted reporting.

Frontend

  • React 18
  • Vite 6
  • JavaScript / JSX
  • HTML5 Canvas
  • Supabase JavaScript Client
  • jsPDF
  • Lucide React
  • QRCode

The frontend provides authentication, dashboard, case management, document/reference upload, analysis, evidence visualization, findings, summaries, and report export.

Backend

  • Python
  • FastAPI
  • Uvicorn
  • Pydantic
  • PyJWT
  • Python Multipart
  • Supabase Python SDK

The backend exposes versioned /api/v1 endpoints for authentication, case management, uploads, analysis, and health monitoring.

AI and Computer Vision

  • PyTorch
  • Torchvision
  • ResNet18
  • OpenCV
  • Pillow
  • NumPy
  • Grad-CAM
  • PyMuPDF

Generative AI

  • Groq API
  • llama-3.3-70b-versatile

Generative AI is used primarily as a reporting layer over structured findings produced by the analysis pipeline.

Cloud Infrastructure

  • Supabase Authentication
  • Supabase PostgreSQL
  • Supabase Storage
  • Render-compatible deployment

The analysis pipeline

Every investigation follows a structured sequence:

  1. Document preprocessing
  2. PDF inspection when applicable
  3. Signature candidate detection
  4. Signature extraction and normalization
  5. 512-dimensional ResNet18 embedding
  6. Multi-reference cosine similarity
  7. Reference profile and consensus analysis
  8. Structural feature analysis
  9. Questioned-signature self-consistency analysis
  10. Calibrated assessment
  11. Grad-CAM visual evidence generation
  12. Structured findings generation
  13. AI-assisted narrative generation
  14. PDF report generation

The pipeline combines learned visual representation with deterministic computer-vision measurements and a calibrated decision layer.


Challenges we ran into

1. Natural variation in genuine signatures

A genuine person's signatures are not identical copies.

They can vary because of writing speed, pen movement, writing surface, position, scale, scan quality, and other acquisition conditions.

A useful system therefore cannot simply assume that every pixel difference means forgery.

This influenced the architecture of DocLens.

Instead of relying on a single image comparison, we introduced:

  • multiple trusted references;
  • reference-set statistics;
  • deep visual similarity;
  • structural measurements;
  • self-consistency analysis;
  • calibrated decision thresholds.

The goal was to make the system evaluate a signature in relation to a reference distribution and multiple evidence signals.


2. Making a document-level system work with real uploads

A benchmark can provide perfectly cropped signature images.

A real user may instead upload an entire scanned contract.

That creates another problem: where is the signature?

We implemented an OpenCV-based localization pipeline that searches candidate regions using geometric, ink-density, connected-component, positional, compactness, and text-like signals.

For PDFs, we additionally built a candidate-selection process that can inspect pages and embedded images before selecting the strongest representation for downstream analysis.


3. Running deep learning under limited resources

During deployment, the backend encountered memory pressure on a constrained Render environment, including Exit Code 137 failures.

We had to optimize the inference path rather than simply assuming more compute was available.

The resulting engineering changes included:

  • torch.inference_mode()
  • single-threaded PyTorch configuration
  • explicit model/tensor cleanup
  • garbage collection
  • bounded image dimensions
  • bounded PDF processing
  • controlled inference resources
  • deterministic reporting fallback when the external LLM service is unavailable

This turned deployment optimization into an important part of the project rather than an afterthought.


4. Keeping generative AI from becoming the source of the forensic measurements

We deliberately separated the deterministic analysis layer from the generative reporting layer.

The computer-vision pipeline calculates the actual measurements and assessment.

The LLM receives structured findings and converts them into understandable language.

This separation allows DocLens to continue generating a deterministic report even when the Groq service is unavailable.

It also reduces the risk of a language model inventing measurements or changing the calculated assessment.


Accomplishments we're proud of

The biggest accomplishment is that DocLens became a complete working investigation platform rather than an isolated machine-learning experiment.

We built an end-to-end workflow

From:

document upload

to:

automatic signature localization

to:

deep visual comparison

to:

multi-reference evidence

to:

structural analysis

to:

calibrated assessment

to:

visual explanation

to:

AI-assisted report

to:

PDF export

—all inside one application.

We built measurable evaluation into the project

The repository contains the CEDAR evaluation and calibration tooling rather than relying entirely on qualitative demonstrations.

The frozen seed-42 evaluation produced:

  • 96.50% balanced accuracy on unseen writers
  • 99.59% ROC AUC
  • 3.41% EER
  • 3.03% FAR
  • 3.98% FRR

under the documented writer-disjoint protocol.

We built for real documents, not only cropped datasets

The benchmark intentionally isolates signature comparison, while the deployed application additionally handles complete documents, PDF processing, signature localization, case context, authentication, storage, evidence visualization, and reporting.

That distinction helped us design the system as a practical application rather than optimizing only for a benchmark.

We built around evidence

The final assessment is connected to:

  • reference comparisons;
  • reference consensus;
  • structural measurements;
  • self-consistency;
  • visual evidence;
  • human-readable findings.

That makes the output substantially more useful for inspection and communication.


What we learned

Building DocLens taught us that an AI application is much more than its model.

We learned how to:

  • build an end-to-end computer-vision product;
  • work with pretrained deep-learning representations;
  • design writer-disjoint evaluation protocols;
  • calibrate thresholds from held-out data;
  • combine learned representations with classical computer vision;
  • build explainability into an AI workflow;
  • process real-world documents rather than only clean datasets;
  • optimize PyTorch inference for constrained infrastructure;
  • separate deterministic analysis from generative reporting;
  • design authenticated multi-case workflows;
  • turn complex technical findings into understandable reports.

One of the most important lessons was that accuracy alone is not the entire user experience.

For a high-stakes analysis workflow, the system also needs to communicate what it found, preserve the evidence, show where that evidence appears, and make the result understandable to the person reviewing it.

That principle shaped the entire architecture of DocLens.


What's next for DocLens

DocLens currently focuses on signature analysis, but the architecture is designed to grow into a broader document-forensics platform.

Our next priorities include:

Stronger signature intelligence

  • Signature-specific representation learning
  • Larger and more diverse forensic datasets
  • Additional writer-disjoint benchmarks
  • Cross-dataset evaluation
  • Improved borderline-case handling
  • Uncertainty and abstention mechanisms

Broader document analysis

  • Multi-page investigation workflows
  • Multiple-signature detection
  • Altered text detection
  • Date and number manipulation detection
  • Font and formatting inconsistencies
  • White-out and erasure detection
  • Broader document-integrity analysis

Examiner-oriented workflows

  • Detailed audit trails
  • Investigation history
  • Improved case management
  • Stronger evidence provenance
  • Examiner review workflows
  • More comprehensive forensic reporting

Our long-term vision is to build an AI-assisted document analysis platform where important authenticity decisions are supported by structured computational evidence, transparent visual findings, and reproducible analysis.


Responsible Use

DocLens is an AI-assisted forensic analysis and decision-support system.

It does not independently establish:

  • legal validity;
  • authorship;
  • intent;
  • identity;
  • or definitive forensic conclusions.

The current ResNet18 representation is a pretrained ImageNet feature extractor, not an end-to-end signature-authorship model.

Likewise, the CEDAR benchmark evaluates the signature-comparison component using pre-cropped signatures and therefore should not be interpreted as universal accuracy for every document, scanner, writer, or real-world condition.

Trusted reference specimens are also assumed to be genuine and representative.

For consequential decisions, DocLens is intended to support rather than replace qualified forensic document examination.


Why DocLens

DocLens brings together capabilities that normally belong to separate stages of an investigation:

Document Processing

Automatic Signature Localization

Deep Visual Representation

Multi-Reference Comparison

Structural Measurements

Reference Consensus & Self-Consistency

Calibrated Assessment

Visual Evidence

AI-Assisted Explanation

Professional Report

The result is a complete AI-assisted workflow designed around one idea:

The assessment should remain connected to the evidence behind it.

That is what we set out to build with DocLens.

Built With

Share this project:

Updates