Downloads · 30 days
17
15% of all-time downloads
takumi123xxx/deepseek-ocr-calendar-finetuned
deepseek-ocr-calendar-finetuned is a image-text-to-text model from takumi123xxx. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as mit.
カレンダー画像から丸印のついた日付を抽出するために特化したDeepSeek-OCR 3BモデルのLoRAファインチューニング版です。
Downloads · 30 days
17
15% of all-time downloads
All-time downloads
116
Public
Repo size
7.9 MB
Likes
0
Public
Click a slice to open those files.
.json10.1 MB · 56%
From the Hugging Face model README
カレンダー画像から丸印のついた日付を抽出するために特化したDeepSeek-OCR 3BモデルのLoRAファインチューニング版です。
このモデルは、カレンダー形式の画像(グリッド状に配置された数字)から、丸印で囲まれた日付を正確に抽出するようにファインチューニングされています。
最も簡単な方法です。
import requests
import base64
# 画像をBase64エンコード
with open("calendar.png", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
# Inference Endpointへリクエスト
url = "https://YOUR_ENDPOINT.endpoints.huggingface.cloud"
headers = {
"Authorization": "Bearer YOUR_HF_TOKEN",
"Content-Type": "application/json"
}
payload = {
"inputs": image_b64,
"prompt": "カレンダーで丸印がついている日付を全て抽出してください。数字のみをカンマ区切りで出力してください。"
}
response = requests.post(url, headers=headers, json=payload)
result = response.json()
print(result[0]["generated_text"])
# 出力例: "5, 12, 20"
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
from PIL import Image
import torch
# ベースモデル(DeepSeek-OCR 3B)をロード
base_model_name = "deepseek-ai/DeepSeek-OCR"
tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_name,
trust_remote_code=True,
torch_dtype=torch.float16
).cuda()
# LoRAアダプターを適用
model = PeftModel.from_pretrained(
base_model,
"takumi123xxx/deepseek-ocr-calendar-finetuned",
torch_dtype=torch.float16
)
model.eval()
# 画像を読み込み
image = Image.open("calendar.png").convert("RGB")
# プロンプトを準備
conversation = [
{
"role": "User",
"content": "<image>\nカレンダーで丸印がついている日付を全て抽出してください。数字のみをカンマ区切りで出力してください。",
"images": [image]
},
{"role": "Assistant", "content": ""}
]
# 推論実行
prepare_inputs = model.prepare_inputs_for_generation(conversation, tokenizer=tokenizer)
with torch.no_grad():
outputs = model.generate(
**prepare_inputs,
max_new_tokens=512,
temperature=0.1,
do_sample=False
)
# 結果をデコード
answer = tokenizer.decode(
outputs[0][len(prepare_inputs["input_ids"][0]):],
skip_special_tokens=True
)
print(answer.strip())
pip install transformers>=4.40.0 peft>=0.17.0 torch>=2.0.0 Pillow>=10.0.0
training_args = {
"num_train_epochs": 20, # 実際は9エポックで収束
"per_device_train_batch_size": 1,
"gradient_accumulation_steps": 4,
"learning_rate": 1e-4,
"warmup_steps": 100,
"logging_steps": 10,
"save_strategy": "epoch",
"fp16": True, # 混合精度学習
}
lora_config = {
"r": 16, # LoRAランク
"lora_alpha": 32, # LoRAアルファ
"lora_dropout": 0.1, # ドロップアウト
"target_modules": ["q_proj", "v_proj"], # ターゲットモジュール
}
| エポック | Loss |
|---|---|
| 1 | 2.4567 |
| 2 | 0.8234 |
| 3 | 0.2156 |
| 4 | 0.0567 |
| 5 | 0.0123 |
| 6 | 0.0034 |
| 7 | 0.0009 |
| 8 | 0.0002 |
| 9 | 0.0000 |
MIT License
@misc{deepseek-ocr-calendar-finetuned,
title={DeepSeek-OCR Calendar Fine-tuned},
author={Takumi Endo},
year={2025},
publisher={Hugging Face},
howpublished={\url{https://huggingface.co/takumi123xxx/deepseek-ocr-calendar-finetuned}}
}
このモデルは、DeepSeek-AIのDeepSeek-OCRをベースにしています。
問題や質問がある場合は、Issuesでお知らせください。