1import torch
2from transformers import AutoModelForCausalLM
3from PIL import Image
4
5# Load the model
6model = AutoModelForCausalLM.from_pretrained(
7 "mapo80/DeQA-Doc-Color",
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"Color 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} Color Score: {score.item():.2f} / 5.0")
1import torch
2from transformers import AutoModelForCausalLM
3from PIL import Image
4
5model = AutoModelForCausalLM.from_pretrained(
6 "mapo80/DeQA-Doc-Color",
7 trust_remote_code=True,
8 torch_dtype=torch.float16,
9 device_map="auto",
10)
11
12def diagnose_color_quality(image_path):
13 img = Image.open(image_path).convert("RGB")
14 score = model.score([img]).item()
15
16 if score >= 4.5:
17 diagnosis = "Excellent color quality"
18 elif score >= 3.5:
19 diagnosis = "Good - minor color issues"
20 elif score >= 2.5:
21 diagnosis = "Fair - consider color correction"
22 elif score >= 1.5:
23 diagnosis = "Poor - needs color correction or rescan"
24 else:
25 diagnosis = "Bad - severe color problems, rescan required"
26
27 return score, diagnosis
28
29score, diagnosis = diagnose_color_quality("scanned_document.jpg")
30print(f"Score: {score:.2f}/5.0 - {diagnosis}")
1import torch
2from transformers import AutoModelForCausalLM
3from PIL import Image
4
5# Load all three models
6models = {
7 "overall": AutoModelForCausalLM.from_pretrained(
8 "mapo80/DeQA-Doc-Overall", trust_remote_code=True,
9 torch_dtype=torch.float16, device_map="auto"
10 ),
11 "color": AutoModelForCausalLM.from_pretrained(
12 "mapo80/DeQA-Doc-Color", trust_remote_code=True,
13 torch_dtype=torch.float16, device_map="auto"
14 ),
15 "sharpness": AutoModelForCausalLM.from_pretrained(
16 "mapo80/DeQA-Doc-Sharpness", trust_remote_code=True,
17 torch_dtype=torch.float16, device_map="auto"
18 ),
19}
20
21def full_quality_report(image_path):
22 img = Image.open(image_path).convert("RGB")
23
24 scores = {}
25 for name, model in models.items():
26 scores[name] = model.score([img]).item()
27
28 return scores
29
30report = full_quality_report("document.jpg")
31print(f"Overall: {report['overall']:.2f}/5.0")
32print(f"Color: {report['color']:.2f}/5.0")
33print(f"Sharpness: {report['sharpness']:.2f}/5.0")
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}