{"id":50913175,"url":"https://github.com/p4suta/deepseek-ocr-v2","last_synced_at":"2026-06-16T12:02:20.511Z","repository":{"id":362823180,"uuid":"1260937576","full_name":"P4suta/deepseek-ocr-v2","owner":"P4suta","description":"Run DeepSeek-OCR-2 locally (Windows / 6GB GPU) and turn PDFs into clean Markdown","archived":false,"fork":false,"pushed_at":"2026-06-06T03:50:13.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-06T05:22:47.913Z","etag":null,"topics":["deepseek-ocr","japanese","ocr","pdf-to-markdown","python","uv","vertical-text","vision-language-model"],"latest_commit_sha":null,"homepage":"https://p4suta.github.io/deepseek-ocr-v2/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/P4suta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-06T03:37:35.000Z","updated_at":"2026-06-06T03:50:15.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/P4suta/deepseek-ocr-v2","commit_stats":null,"previous_names":["p4suta/deepseek-ocr-v2"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/P4suta/deepseek-ocr-v2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4suta%2Fdeepseek-ocr-v2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4suta%2Fdeepseek-ocr-v2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4suta%2Fdeepseek-ocr-v2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4suta%2Fdeepseek-ocr-v2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/P4suta","download_url":"https://codeload.github.com/P4suta/deepseek-ocr-v2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P4suta%2Fdeepseek-ocr-v2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34404748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deepseek-ocr","japanese","ocr","pdf-to-markdown","python","uv","vertical-text","vision-language-model"],"created_at":"2026-06-16T12:02:19.316Z","updated_at":"2026-06-16T12:02:20.501Z","avatar_url":"https://github.com/P4suta.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deepseek-ocr-v2\n\n[![CI](https://github.com/P4suta/deepseek-ocr-v2/actions/workflows/ci.yml/badge.svg)](https://github.com/P4suta/deepseek-ocr-v2/actions/workflows/ci.yml)\n[![Docs](https://github.com/P4suta/deepseek-ocr-v2/actions/workflows/docs.yml/badge.svg)](https://P4suta.github.io/deepseek-ocr-v2/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n\n[DeepSeek-OCR-2](https://huggingface.co/deepseek-ai/DeepSeek-OCR-2)（3B, DeepEncoder V2）をローカル（Windows / RTX 3060 6GB クラス）で動かすための最小構成。\n\n📖 **ドキュメント: \u003chttps://P4suta.github.io/deepseek-ocr-v2/\u003e**\n\n## 特徴 / 前提\n\n- **flash-attn 不要**。`_attn_implementation=\"eager\"` で起動する（Windows でのビルド地獄を回避）。\n- モデル本体は bf16 で約 6.3GB。専用 VRAM 6GB は少し超えるが、NVIDIA の **CUDA Sysmem Fallback**（標準 ON）で共有メモリへ自動退避するためロード・実行は可能。ただし退避分は低速。\n- **実用速度の本命は 4bit 量子化**（重み約 2GB が専用 VRAM に収まる）。\n\n## セットアップ\n\n```powershell\nuv sync\n```\n\n`torch` / `torchvision` は PyPI の CPU 版ではなく PyTorch の CUDA (cu124) index から取得する設定（`pyproject.toml` の `[tool.uv.sources]`）。\n\n## 使い方\n\n```powershell\n# ロード確認だけ（推論せず終了。初回はモデル約6.3GBをDL）\nuv run python main.py --smoke\n\n# 検証用サンプル画像を生成\nuv run python make_sample.py\n\n# bf16 GPU で実行（公式どおり・遅め）\nuv run python main.py --image sample.png\n\n# 実用速度の本命: 4bit 量子化\nuv run python main.py --image sample.png --quant 4bit\n\n# 最終手段: CPU 実行\nuv run python main.py --image sample.png --device cpu --mode tiny\n```\n\n結果は `--out`（既定 `./out`）に Markdown とグラウンディング可視化画像で保存される。\n\n### 主なオプション\n\n| オプション | 既定 | 説明 |\n|---|---|---|\n| `--image` | （必須） | OCR 対象の画像パス |\n| `--prompt` | `\u003cimage\u003e\\n\u003c\\|grounding\\|\u003eConvert the document to markdown.` | プロンプト |\n| `--device` | `gpu` | `gpu` / `cpu` |\n| `--quant` | `none` | `none`(bf16) / `4bit` |\n| `--mode` | `small` | `small`(768) / `base`(1024) / `gundam`(動的) ※v2 は 768/1024 のみ対応 |\n| `--out` | `./out` | 結果の保存先 |\n| `--smoke` | - | ロード確認だけして終了 |\n\n## PDF を丸ごと OCR（`ocr_pdf.py`）\n\n```powershell\nuv run python ocr_pdf.py --pdf \"C:/path/to/book.pdf\"\nuv run python ocr_pdf.py --pdf \"...book.pdf\" --max-pages 5   # 先頭5ページだけ試す\n```\n\n- モデルを一度だけロードし、ページをループ。結果は `out_pdf/\u003cbook\u003e/\u003cbook\u003e.md` に逐次追記（途中終了でも部分結果が残る）。\n- 既定は **`--source native`**（PDF 埋め込み画像をネイティブ解像度で抽出）＋ **`--mode gundam`**＋ **bf16**。\n- 見開き(横長)の本は左右2ページに分割し、縦書きは右→左の順で処理。`--start N` でレジューム。\n- 密なページ（縦書きなど）は低解像度だと反復崩壊するため、高解像度をタイル分割で渡す。反復は `repetition.py` が生成中に停止する。\n\n## OCR結果のクリーンアップ（`cleanup.py`）\n\nOCRした結合md（`out_pdf/\u003cbook\u003e/\u003cbook\u003e.md`）を、構造を保った **Markdown** に機械的に整える汎用後処理（特定の本に依存しない）。\n\n```powershell\nPYTHONUTF8=1 uv run python cleanup.py --book \"\u003cbook-name\u003e\"\n# → out_pdf/\u003cbook\u003e/\u003cbook\u003e.clean.md\n```\n\nやること（汎用ロジック）:\n- **ノンブル・余白の行番号・柱（ランニングヘッダ）を除去**。純数字行、行内ノンブル、繰り返す短い見出しの重複（柱）を機械的に判定。\n- **空行ブロック単位で分類**し、短い非文末行を `##` 見出しに、本文はページを跨いでリフロー＝段落化。\n- **節番号「2」`[14]` は脚注参照 `[^14]` として保持**し、その位置で段落を分割。\n- **反復残渣を圧縮**（句の即時反復＋隣接重複文）。\n- **崩壊/幻覚の疑いページを検出**して印＋末尾に一覧（自動削除はしない）。\n\n設計メモ:\n- 固有名（章タイトル等）はハードコードせず、「ページ跨ぎで繰り返す短い行＝柱」「初出のみ見出し、重複は柱として破棄」で汎用化。\n- 見出し推定はヒューリスティック（短い誤OCR断片や柱の誤字を拾うことがある）。真の段落境界（字下げ）はOCR出力に残らないため、見出し＋節番号での粗い段落化に留まる。文字レベルのOCR誤りは対象外。\n- 表・リストは入力にあれば Markdown 化するが、`Free OCR` 出力には無いため通常は付かない（実構造が要るなら Markdown プロンプトで再OCR）。`--min-chars` で崩壊検出の閾値を調整可能。\n\n## 開発\n\n```powershell\nuv run ruff check .    # lint\nuv run ruff format .   # format\nuv run ty check .      # 型チェック\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp4suta%2Fdeepseek-ocr-v2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp4suta%2Fdeepseek-ocr-v2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp4suta%2Fdeepseek-ocr-v2/lists"}