1import torch
2from transformers import AutoModelForCausalLM
3from PIL import Image
4
5# Load the model
6model = AutoModelForCausalLM.from_pretrained(
7 "mapo80/DeQA-Doc-Overall",
8 trust_remote_code=True,
9 torch_dtype=torch.float16,
10 device_map="auto",
11)
12
13# Score an image
14image = Image.open("document.jpg").convert("RGB")
15score = model.score([image])
16print(f"Overall Quality Score: {score.item():.2f} / 5.0")
1images = [
2 Image.open("doc1.jpg").convert("RGB"),
3 Image.open("doc2.jpg").convert("RGB"),
4 Image.open("doc3.jpg").convert("RGB"),
5]
6
7scores = model.score(images)
8for i, score in enumerate(scores):
9 print(f"Document {i+1}: {score.item():.2f} / 5.0")
1model = AutoModelForCausalLM.from_pretrained(
2 "mapo80/DeQA-Doc-Overall",
3 trust_remote_code=True,
4 torch_dtype=torch.float16,
5 device_map="auto",
6)
1model = AutoModelForCausalLM.from_pretrained(
2 "mapo80/DeQA-Doc-Overall",
3 trust_remote_code=True,
4 torch_dtype=torch.float16,
5 device_map="auto",
6 offload_folder="/tmp/offload",
7)
1import torch
2from transformers import AutoModelForCausalLM
3from PIL import Image
4from pathlib import Path
5
6model = AutoModelForCausalLM.from_pretrained(
7 "mapo80/DeQA-Doc-Overall",
8 trust_remote_code=True,
9 torch_dtype=torch.float16,
10 device_map="auto",
11)
12
13# Filter documents by quality
14def filter_by_quality(image_paths, min_score=3.0):
15 good_docs = []
16 bad_docs = []
17
18 for path in image_paths:
19 img = Image.open(path).convert("RGB")
20 score = model.score([img]).item()
21
22 if score >= min_score:
23 good_docs.append((path, score))
24 else:
25 bad_docs.append((path, score))
26
27 return good_docs, bad_docs
28
29# Usage
30docs = list(Path("documents/").glob("*.jpg"))
31good, bad = filter_by_quality(docs, min_score=3.5)
32
33print(f"Good quality: {len(good)} documents")
34print(f"Need review: {len(bad)} documents")
All credit for the research, training methodology, and model architecture goes to the original authors.
1@inproceedings{deqadoc,
2 title={{DeQA-Doc}: Adapting {DeQA-Score} to Document Image Quality Assessment},
3 author={Gao, Junjie and Liu, Runze and Peng, Yingzhe and Yang, Shujian and Zhang, Jin and Yang, Kai and You, Zhiyuan},
4 booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision Workshop},
5 year={2025},
6}