Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Default to PaddleOCR with automatic recognition disabled for new users https://github.com/siyuan-note/siyuan/issues/19984

Danielee1ca76767b0
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy
index 3b6c22a9f4..0fd22bc67e 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy
@@ -6,7 +6,7 @@
"id": "20200924100744-br924ar",
"title": "Assets",
"type": "doc",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -967,7 +967,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20230117003636-epvk98g",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -1022,12 +1022,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261001000112-e9wid3h",
- "updated": "20261001000112"
+ "updated": "20261002231520"
},
"Children": [
{
"Type": "NodeText",
- "Data": "PaddleOCR includes PP-OCRv6 Tiny and Small models, available offline without downloading. Tiny uses fewer resources; Small offers higher accuracy. To import another compatible PP-OCRv6 model, select its detection and recognition ONNX files and the corresponding inference.yml files. Imported models sync with the workspace; the provider and selected model are saved per device."
+ "Data": "PaddleOCR includes PP-OCRv6 Tiny and Small models, available offline without downloading. Tiny uses fewer resources; Small offers higher accuracy. To import another compatible PP-OCRv6 model, select its detection and recognition ONNX files and the corresponding inference.yml files. Imported models sync with the workspace; the provider and selected model are saved per device. New users default to PaddleOCR with Small on desktop and Tiny on mobile; automatic OCR is disabled by default. Existing users retain their OCR configuration; upgrading from a version without OCR provider settings keeps Tesseract."
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy
index 9154a44514..04e2e787a1 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy
@@ -6,7 +6,7 @@
"id": "20200915214115-42b8zma",
"title": "资源文件",
"type": "doc",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -979,7 +979,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20230117002036-vmc0mx4",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -1034,12 +1034,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261001000112-4enj18s",
- "updated": "20261001000112"
+ "updated": "20261002231520"
},
"Children": [
{
"Type": "NodeText",
- "Data": "PaddleOCR 内置 PP-OCRv6 Tiny 和 Small 模型,无需下载即可离线使用。Tiny 占用资源更少,Small 识别精度更高。导入其他兼容的 PP-OCRv6 模型时,分别选择检测、识别 ONNX 文件及对应的 inference.yml。导入模型随工作空间同步,提供商和当前模型的选择按设备保存。"
+ "Data": "PaddleOCR 内置 PP-OCRv6 Tiny 和 Small 模型,无需下载即可离线使用。Tiny 占用资源更少,Small 识别精度更高。导入其他兼容的 PP-OCRv6 模型时,分别选择检测、识别 ONNX 文件及对应的 inference.yml。导入模型随工作空间同步,提供商和当前模型的选择按设备保存。新用户默认使用 PaddleOCR,桌面端使用 Small,移动端使用 Tiny,自动 OCR 默认关闭。已有用户保留原 OCR 配置;从尚无 OCR 提供商设置的版本升级时,继续使用 Tesseract。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy
index 8d58ccb34e..d5ca892378 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy
@@ -6,7 +6,7 @@
"id": "20211226123038-4umgpxy",
"title": "資料文件",
"type": "doc",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -965,7 +965,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20230117003901-ze4mbzz",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -1020,12 +1020,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261001000112-w0zyvyj",
- "updated": "20261001000112"
+ "updated": "20261002231520"
},
"Children": [
{
"Type": "NodeText",
- "Data": "PaddleOCR 內建 PP-OCRv6 Tiny 和 Small 模型,無需下載即可離線使用。Tiny 占用資源較少,Small 辨識精確度較高。匯入其他相容的 PP-OCRv6 模型時,分別選取偵測、辨識 ONNX 檔案及對應的 inference.yml。匯入模型隨工作空間同步,提供者和目前模型的選擇依裝置儲存。"
+ "Data": "PaddleOCR 內建 PP-OCRv6 Tiny 和 Small 模型,無需下載即可離線使用。Tiny 占用資源較少,Small 辨識精確度較高。匯入其他相容的 PP-OCRv6 模型時,分別選取偵測、辨識 ONNX 檔案及對應的 inference.yml。匯入模型隨工作空間同步,提供者和目前模型的選擇依裝置儲存。新使用者預設使用 PaddleOCR,桌面端使用 Small,行動端使用 Tiny,自動 OCR 預設關閉。既有使用者保留原 OCR 設定;從尚無 OCR 提供者設定的版本升級時,繼續使用 Tesseract。"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy
index 9d8e77a65d..6826284b54 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy
@@ -7,7 +7,7 @@
"id": "20240530101000-1m5un7l",
"title": "アセット",
"type": "doc",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -1005,7 +1005,7 @@
"Properties": {
"ID": "20240530101000-5bix8t1",
"id": "20240530101000-9evyuhr",
- "updated": "20261001013550"
+ "updated": "20261002231520"
},
"Children": [
{
@@ -1057,12 +1057,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261001000112-ooz689o",
- "updated": "20261001000112"
+ "updated": "20261002231520"
},
"Children": [
{
"Type": "NodeText",
- "Data": "PaddleOCR には PP-OCRv6 Tiny と Small が内蔵され、ダウンロードせずにオフラインで使用できます。Tiny はリソース消費が少なく、Small は認識精度が高いモデルです。ほかの互換 PP-OCRv6 モデルをインポートする場合は、検出と認識の ONNX ファイルと各 inference.yml を選択します。インポートしたモデルはワークスペースと同期され、プロバイダーと使用モデルの選択は端末ごとに保存されます。"
+ "Data": "PaddleOCR には PP-OCRv6 Tiny と Small が内蔵され、ダウンロードせずにオフラインで使用できます。Tiny はリソース消費が少なく、Small は認識精度が高いモデルです。ほかの互換 PP-OCRv6 モデルをインポートする場合は、検出と認識の ONNX ファイルと各 inference.yml を選択します。インポートしたモデルはワークスペースと同期され、プロバイダーと使用モデルの選択は端末ごとに保存されます。新規ユーザーはデフォルトで PaddleOCR を使用し、デスクトップでは Small、モバイルでは Tiny が選択されます。自動 OCR はデフォルトで無効です。既存ユーザーの OCR 設定は保持され、OCR プロバイダー設定のないバージョンからの更新では Tesseract を引き続き使用します。"
}
]
},
diff --git a/kernel/conf/ocr.go b/kernel/conf/ocr.go
index bd4f4bfb32..75c6fa994b 100644
--- a/kernel/conf/ocr.go
+++ b/kernel/conf/ocr.go
@@ -12,5 +12,5 @@ func NewOCR(mobile bool) *OCR {
if mobile {
model = "tiny"
}
- return &OCR{Provider: "tesseract", Model: model, Auto: true}
+ return &OCR{Provider: "paddleocr", Model: model, Auto: false}
}
diff --git a/kernel/conf/ocr_test.go b/kernel/conf/ocr_test.go
index b8bee5136f..4e47a5a8ac 100644
--- a/kernel/conf/ocr_test.go
+++ b/kernel/conf/ocr_test.go
@@ -3,10 +3,10 @@ package conf
import "testing"
func TestOCRDeviceDefaults(t *testing.T) {
- if desktop := NewOCR(false); desktop.Provider != "tesseract" || desktop.Model != "small" || !desktop.Auto {
+ if desktop := NewOCR(false); desktop.Provider != "paddleocr" || desktop.Model != "small" || desktop.Auto {
t.Fatalf("desktop defaults: %+v", desktop)
}
- if mobile := NewOCR(true); mobile.Model != "tiny" || !mobile.Auto {
+ if mobile := NewOCR(true); mobile.Provider != "paddleocr" || mobile.Model != "tiny" || mobile.Auto {
t.Fatalf("mobile defaults: %+v", mobile)
}
}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 5cb5a83af2..1e56700d84 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -786,9 +786,7 @@ func InitConf() {
}()
}
- if nil == Conf.OCR {
- Conf.OCR = conf.NewOCR(util.IsMobileContainer())
- }
+ Conf.OCR = normalizeOCRConfig(Conf.OCR, confFileExists, util.IsMobileContainer())
if nil == Conf.AI {
Conf.AI = conf.NewAI()
} else {
diff --git a/kernel/model/ocr.go b/kernel/model/ocr.go
index 709ee593a5..8d35bcbc94 100644
--- a/kernel/model/ocr.go
+++ b/kernel/model/ocr.go
@@ -26,6 +26,19 @@ var ocrRegistry = ocr.NewRegistry()
var ocrInit sync.Once
var nativePaddle = &ocr.PaddleProvider{Config: currentPaddleConfig}
+// 新设备使用内置 PaddleOCR 并关闭自动识别,已有设备缺少 OCR 配置时保留 Tesseract 自动识别。
+func normalizeOCRConfig(value *conf.OCR, confFileExists, mobile bool) *conf.OCR {
+ if value != nil {
+ return value
+ }
+ value = conf.NewOCR(mobile)
+ if confFileExists {
+ value.Provider = string(ocr.Tesseract)
+ value.Auto = true
+ }
+ return value
+}
+
func InitOCR() {
ocrInit.Do(func() {
if err := ocrRegistry.Register(ocr.Tesseract, util.TesseractProvider{}); err != nil {
diff --git a/kernel/model/ocr_conf_test.go b/kernel/model/ocr_conf_test.go
new file mode 100644
index 0000000000..c04e350f0e
--- /dev/null
+++ b/kernel/model/ocr_conf_test.go
@@ -0,0 +1,51 @@
+package model
+
+import (
+ "testing"
+
+ "github.com/siyuan-note/siyuan/kernel/conf"
+)
+
+func TestNormalizeOCRConfig(t *testing.T) {
+ for _, test := range []struct {
+ name string
+ value *conf.OCR
+ confFileExists bool
+ mobile bool
+ want conf.OCR
+ }{
+ {name: "new desktop", want: conf.OCR{Provider: "paddleocr", Model: "small", Auto: false}},
+ {name: "new mobile", mobile: true, want: conf.OCR{Provider: "paddleocr", Model: "tiny", Auto: false}},
+ {name: "legacy desktop", confFileExists: true, want: conf.OCR{Provider: "tesseract", Model: "small", Auto: true}},
+ {name: "legacy mobile", confFileExists: true, mobile: true, want: conf.OCR{Provider: "tesseract", Model: "tiny", Auto: true}},
+ {
+ name: "saved PaddleOCR with auto enabled",
+ value: &conf.OCR{Provider: "paddleocr", Model: "small", Auto: true},
+ confFileExists: true,
+ want: conf.OCR{Provider: "paddleocr", Model: "small", Auto: true},
+ },
+ {
+ name: "saved Tesseract with auto disabled",
+ value: &conf.OCR{Provider: "tesseract", Model: "tiny", Auto: false},
+ confFileExists: true,
+ want: conf.OCR{Provider: "tesseract", Model: "tiny", Auto: false},
+ },
+ {
+ name: "saved PaddleOCR with imported model",
+ value: &conf.OCR{Provider: "paddleocr", Model: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", Auto: false},
+ confFileExists: true,
+ mobile: true,
+ want: conf.OCR{Provider: "paddleocr", Model: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", Auto: false},
+ },
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ got := normalizeOCRConfig(test.value, test.confFileExists, test.mobile)
+ if *got != test.want {
+ t.Fatalf("OCR config: got %+v, want %+v", *got, test.want)
+ }
+ if test.value != nil && got != test.value {
+ t.Fatal("saved OCR config should be retained")
+ }
+ })
+ }
+}