CoolFace
Modelpublic

Jwalit/document-moire-detector

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
1likes278downloads
Model Card

Document Moiré Detection Model (V2)

A fine-tuned DeiT-small Vision Transformer for detecting moiré patterns in document images.

Model Description

Binary classifier: detects whether a document image contains moiré artifacts (common from screen photography, scanning, or screen captures).

Labels:

  • clean (0): No moiré patterns
  • moire (1): Moiré patterns detected

V1 → V2 Comparison

V1 (DeiT-tiny)**V2 (DeiT-small)**
Parameters5.5M22M
Training samples6,0008,000
Moiré methods46 (+subtle, +localized)
Label smoothing0.05
Accuracy99.5%99.1%
F1 Score0.9950.991
Precision99.3%98.5%
Recall99.7%99.8%
Note: V2 was evaluated on harder examples including subtle single-frequency moiré and localized moiré patterns that V1 never trained on. V2 achieves near-perfect recall (99.75%) — it catches virtually all moiré patterns including very subtle ones, at the cost of slightly lower precision.

Training Details

ParameterValue
Base modelfacebook/deit-small-patch16-224
Parameters22M
Training samples8,000 (4,000 clean + 4,000 moiré)
Eval samples800 (400 clean + 400 moiré)
Epochs5
Learning rate3e-5 (cosine schedule)
Effective batch size64
Label smoothing0.05
Warmup steps60
Best checkpointEpoch 2 (by F1)

Moiré Generation Methods

  1. 1.Resize aliasing — downscale+upscale with NEAREST interpolation + pattern overlay
  2. 2.Pattern overlay — sinusoidal interference with per-channel color variation
  3. 3.Multi-frequency — 2-4 patterns at different frequencies + color displacement
  4. 4.Screen simulation — pixel grid + rotation + moiré overlay
  5. 5.Subtle moiré — very low strength single-frequency (hard examples)
  6. 6.Localized moiré — moiré in elliptical region with gaussian mask

Performance (Best Checkpoint)

MetricValue
Accuracy99.12%
F1 Score0.9913
Precision98.52%
Recall99.75%
Eval Loss0.170

Training Progression

EpochEval LossAccuracyF1PrecisionRecall
10.17399.0%0.99099.3%98.8%
20.17799.1%0.99199.0%99.3%
30.15499.1%0.99199.3%99.0%
40.17099.1%0.99198.5%99.8%
50.16899.0%0.99098.3%99.8%

Usage

python
from transformers import pipeline

classifier = pipeline("image-classification", model="Jwalit/document-moire-detector")
result = classifier("path/to/document.jpg")
print(result)
# [{'label': 'clean', 'score': 0.99}, {'label': 'moire', 'score': 0.01}]

Or manually:

python
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import torch

processor = AutoImageProcessor.from_pretrained("Jwalit/document-moire-detector")
model = AutoModelForImageClassification.from_pretrained("Jwalit/document-moire-detector")

image = Image.open("document.jpg")
inputs = processor(image, return_tensors="pt")
with torch.no_grad():
    logits = model(**inputs).logits
    predicted = logits.argmax(-1).item()

print(model.config.id2label[predicted])  # 'clean' or 'moire'

Limitations

  • Trained on synthetic moiré patterns — may not capture all real-world moiré variations
  • Optimized for document images; performance on natural scene images may vary
  • Input images resized to 224×224; very subtle moiré in high-resolution images may be lost
  • Higher recall than precision — may occasionally flag clean images as moiré (false positive rate ~1.5%)