DeepSeek.OCR2
0.2.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DeepSeek.OCR2 --version 0.2.0
NuGet\Install-Package DeepSeek.OCR2 -Version 0.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DeepSeek.OCR2" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DeepSeek.OCR2" Version="0.2.0" />
<PackageReference Include="DeepSeek.OCR2" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DeepSeek.OCR2 --version 0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DeepSeek.OCR2, 0.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DeepSeek.OCR2@0.2.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DeepSeek.OCR2&version=0.2.0
#tool nuget:?package=DeepSeek.OCR2&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DeepSeek.OCR2 (.NET / NuGet) 封装说明
这个 NuGet 包提供两层封装:
DeepSeekOcr2LocalServer:从包内释放一个轻量 Python HTTP Server 脚本并启动子进程(模型只加载一次,便于多次调用)。DeepSeekOcr2Client:通过 HTTP 调用POST /ocr执行 OCR 推理。
先决条件
- Windows:无需预装 Python。本包默认会在首次运行时自动下载便携版 Python(默认 3.10.11)并引导 pip/venv。
- Linux/macOS:建议预装 Python 3.10+(或手动指定
PythonExecutablePath)。 - 推理依赖(
torch/transformers等)默认会在首次运行时自动创建 venv 并安装(CPU 预设);也支持离线 wheels(见下文)。 - 如果希望更快推理,可按上游说明安装
flash-attn(否则服务端会自动降级)。
依赖“打包/自带”能做到什么
- 纯把
torch/ CUDA /flash-attn这类依赖“直接塞进 NuGet”在体积和平台适配上不现实(Windows/Linux、CPU/CUDA 版本差异、wheel 很大)。 - 这里提供的折中方案是:NuGet 内置 requirements 列表,启动时可选 自动创建 venv + pip 安装依赖(仍然需要你机器上有 Python;安装 torch 可能需要网络/指定镜像/指定 CUDA 轮子)。
许可证与归属
- 上游仓库 DeepSeek-OCR-2 的许可证为 Apache License 2.0(见仓库根目录 LICENSE.txt)。
- 本 NuGet 包仅做 .NET 调用封装与启动脚本分发,不包含模型权重;模型与其使用条款请以 deepseek-ai/DeepSeek-OCR-2(HuggingFace/上游仓库)为准。
- 本封装仓库地址:https://github.com/ichichchch/DeepSeekOCR2.NET
最小用法(启动本地服务 + 调用 OCR)
using DeepSeek.OCR2;
var result = await DeepSeekOcr2.RecognizeFileAsync(@"D:\test.jpg");
Console.WriteLine(result.Text);
如需复用同一个模型进程(多次调用更快):
using DeepSeek.OCR2;
await using var session = await DeepSeekOcr2.CreateSessionAsync();
var request = DeepSeekOcr2Request.FromFile(@"D:\test.jpg") with { Prompt = "<image>\nFree OCR." };
var result = await session.Client.RecognizeAsync(request);
Console.WriteLine(result.Text);
Torch 自动安装选项
TorchInstallPresetCpu:按 PyTorch 官方 CPU 索引安装(默认)None:不安装 torch(适合你自行管理 Python 环境)Cuda118:按 PyTorch 官方 cu118 索引安装(与本仓库 README 示例一致)
OfflineWheelDirectory:指定离线 wheel 目录(会传给 pip:--find-links <dir>)PreferOfflineWheels:为 true 时额外加--no-index(强制只从离线目录找)TorchVersion/TorchVisionVersion/TorchAudioVersion:默认2.6.0/0.21.0/2.6.0,可自行改
目标框架
- DeepSeek.OCR2:netstandard2.0 / net6.0 / net8.0 / net10.0
发布到 nuget.org(建议)
- Owners:nuget.org 的包所有者最终由你上传时使用的账号/组织决定;建议用你的组织账号作为 owner,并通过 nuget.org 后台添加/移除 owners。工程里的
Owners字段仅作为元数据展示用(不同站点可能忽略)。 - RepositoryBranch/Commit:本包在 CI(GitHub Actions)环境下会自动读取
GITHUB_REF_NAME/GITHUB_SHA并写入包元数据;也支持在打包命令里显式覆盖:dotnet pack -p:RepositoryBranch=main -p:RepositoryCommit=<commitSha>
- 自动发布(GitHub Actions):
- 在仓库 Secrets 添加
NUGET_API_KEY(nuget.org 生成的 API Key) - 推送 tag
v*(例如v0.1.7)会触发发布工作流nuget-publish
- 在仓库 Secrets 添加
本地打包/推送
- 打包:
pwsh .\pack.ps1(输出到dotnet/artifacts/) - 推送:
pwsh .\push.ps1 -ApiKey <key>(可用-Source指向私有 NuGet 源)
HTTP 协议
GET /health:健康检查(返回{ "ok": true })POST /ocr:JSON 请求体(关键字段)image_base64:图片内容(Base64)prompt:提示词(需要包含<image>)output_dir:可选,输出目录base_size/image_size/crop_mode/save_results:与官方model.infer参数一致
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- System.Text.Json (>= 8.0.5)
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.3.9 | 2,578 | 2/21/2026 |
| 0.3.8 | 167 | 2/20/2026 |
| 0.3.7 | 231 | 1/30/2026 |
| 0.3.6 | 164 | 1/30/2026 |
| 0.3.4 | 173 | 1/29/2026 |
| 0.3.3 | 169 | 1/29/2026 |
| 0.3.2 | 163 | 1/28/2026 |
| 0.3.1 | 172 | 1/28/2026 |
| 0.3.0 | 170 | 1/28/2026 |
| 0.2.2 | 190 | 1/28/2026 |
| 0.2.1 | 224 | 1/28/2026 |
| 0.2.0 | 100 | 1/28/2026 |
| 0.1.9 | 107 | 1/27/2026 |
| 0.1.8 | 99 | 1/28/2026 |
- Add one-click API (DeepSeekOcr2/DeepSeekOcr2Session)
- Add netstandard2.0 target framework
- Add Windows auto Python+pIP bootstrap (portable python download)
- Add config template as contentFiles with copy-to-output