mnhkahn commited on
Commit
cf29823
·
1 Parent(s): c1aede6

feat(seal): 新增小篆整字与局部检索接口

Browse files

1. 提供固定三条整字候选和两条局部字形线索
2. 纳入可部署的小篆索引、候选字图与构建脚本
3. 补充接口和部署所需文档

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitignore +7 -0
  2. README.md +103 -0
  3. app.py +69 -2
  4. data/seal_glyph_index/char_counts.json +647 -0
  5. data/seal_glyph_index/component_features_hog.npy +3 -0
  6. data/seal_glyph_index/component_manifest.json +13 -0
  7. data/seal_glyph_index/component_valid.npy +3 -0
  8. data/seal_glyph_index/features_local_resnet50.json +10 -0
  9. data/seal_glyph_index/features_local_resnet50.npy +3 -0
  10. data/seal_glyph_index/glyphs/000fd501a764b9d442ba5e9e6cadaf6cccd8c5e4.png +0 -0
  11. data/seal_glyph_index/glyphs/004716899208a13645957764089463ed9ddcb106.png +0 -0
  12. data/seal_glyph_index/glyphs/008d89e33501899e38956f250bc5741b6a25eb12.png +0 -0
  13. data/seal_glyph_index/glyphs/015a0edf3abfb955661e56b3b9ab631f228b8827.png +0 -0
  14. data/seal_glyph_index/glyphs/015baaeed912f36fb8543099e5d949a76d1f153a.png +0 -0
  15. data/seal_glyph_index/glyphs/0194c724c965cbbc9b38e9a6fa3e3bfdd7cf163e.png +0 -0
  16. data/seal_glyph_index/glyphs/01adf2296c8a2f0784f5d9631bbd13f7ba414bf5.png +0 -0
  17. data/seal_glyph_index/glyphs/025402e2a774301a6faa2da1fd8ba6bddec5ad85.png +0 -0
  18. data/seal_glyph_index/glyphs/02918009845389252db1e630d62b3d0c907e9f74.png +0 -0
  19. data/seal_glyph_index/glyphs/032f0721c110f781e52130a4db05a458a05ec87e.png +0 -0
  20. data/seal_glyph_index/glyphs/03412bd3401f8bc5bf3cc6e0d7298250aaa40bed.png +0 -0
  21. data/seal_glyph_index/glyphs/035404f1d065c9325a1eabbdc793b96b4b820cb7.png +0 -0
  22. data/seal_glyph_index/glyphs/03c099067199f7f21e65610b5567396f5bc2c017.png +0 -0
  23. data/seal_glyph_index/glyphs/03c538e5c93e448b0daedd471f6a25eb4e877404.png +0 -0
  24. data/seal_glyph_index/glyphs/03ea6a39420d4ad7f3b1cd045a9c419382fae31f.png +0 -0
  25. data/seal_glyph_index/glyphs/0429aba8dc35c7f1b40d780173e69c8d60ff5380.png +0 -0
  26. data/seal_glyph_index/glyphs/044af22e0d46d8dd4fa4267298dc3a240c44550a.png +0 -0
  27. data/seal_glyph_index/glyphs/0497302b1e7f05f8fd5f2d34ea68a83a27640366.png +0 -0
  28. data/seal_glyph_index/glyphs/04bb44fee3be8c44dee9186c9e651edfe8086764.png +0 -0
  29. data/seal_glyph_index/glyphs/05b79322f37bba527f13c0d163f4f7c707370099.png +0 -0
  30. data/seal_glyph_index/glyphs/05c9b121f49560466fecfef63183d779c86d50c9.png +0 -0
  31. data/seal_glyph_index/glyphs/05ca0ec208110dd6b42049102f9527a8b0492d86.png +0 -0
  32. data/seal_glyph_index/glyphs/0609104dcce2eb66a5dd30f6c4626ff7f866d3cf.png +0 -0
  33. data/seal_glyph_index/glyphs/065d2199c4db5391ec4861385ce40c292975e897.png +0 -0
  34. data/seal_glyph_index/glyphs/067b4570fdc5dd05d3b473aadf0f4d26caf19f65.png +0 -0
  35. data/seal_glyph_index/glyphs/068697ae9f656f8b79081612a42c27a79c61aeb1.png +0 -0
  36. data/seal_glyph_index/glyphs/06e53420a2cc673a81dd14728fd6d103794df057.png +0 -0
  37. data/seal_glyph_index/glyphs/07c4cfc19b267536d694f055e228ad4c32e0fe53.png +0 -0
  38. data/seal_glyph_index/glyphs/07c76a9f83eeaa57ecade83cbdde7c600fc08a80.png +0 -0
  39. data/seal_glyph_index/glyphs/085b14f8c3c93d9e184fb7a47d9737632908d7f6.png +0 -0
  40. data/seal_glyph_index/glyphs/089b2a4fda7e1cce50f801f50b631aa6bc75c426.png +0 -0
  41. data/seal_glyph_index/glyphs/093e3708f0aea50fc35659cbc8c65590563a496f.png +0 -0
  42. data/seal_glyph_index/glyphs/09575e263ae2f77a9bbff0af0173471a6ee9fa70.png +0 -0
  43. data/seal_glyph_index/glyphs/0a183d5d54f4d02f7c4bff164c7e1e53b2474f82.png +0 -0
  44. data/seal_glyph_index/glyphs/0a78ab56ecd2449b84181c01efde6c9bdcff1359.png +0 -0
  45. data/seal_glyph_index/glyphs/0b46b9ab66e8414adc2526140fa3898e7be7241d.png +0 -0
  46. data/seal_glyph_index/glyphs/0b5c5abb076058b4f72ce0713e733d0703f04e58.png +0 -0
  47. data/seal_glyph_index/glyphs/0b893f4707e6d6305599f0ddaf0034047c51ab1a.png +0 -0
  48. data/seal_glyph_index/glyphs/0b96e6e28e15aaac8b66ba275d14937e1ae84996.png +0 -0
  49. data/seal_glyph_index/glyphs/0d3ba263bab90848b219b5e1ecd38c7e7e0054b4.png +0 -0
  50. data/seal_glyph_index/glyphs/0d48cf87341d20d7a20002d6aeff5508a5ec098a.png +0 -0
.gitignore CHANGED
@@ -7,6 +7,13 @@ __pycache__/
7
  venv*
8
  env/
9
  ENV/
 
 
 
 
 
 
 
10
  *.wav
11
  test_*.py
12
  .DS_Store
 
7
  venv*
8
  env/
9
  ENV/
10
+ data/seal_glyph_index_*/
11
+ data/.hf_cache/
12
+ data/models/
13
+ data/seal_glyph_index/features.npy
14
+ data/seal_glyph_index/features_facebook_dinov2_small.npy
15
+ data/seal_glyph_index/features_facebook_dinov2_small.json
16
+ data/seal_glyph_index/evaluation*.json
17
  *.wav
18
  test_*.py
19
  .DS_Store
README.md CHANGED
@@ -9,3 +9,106 @@ license: apache-2.0
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
12
+
13
+ ## 小篆字形检索库(不训练分类模型)
14
+
15
+ 现有 `best_model.pth` 是固定 6766 类的分类模型。对于只有一张或少量
16
+ 样本的篆书字,本项目提供独立的字形检索基线:从已标注的 `chars.json`
17
+ 裁出单字,建立 HOG 特征索引,并以余弦相似度返回候选字形与出处。
18
+
19
+ 先只检查可用标注和数据规模:
20
+
21
+ ```bash
22
+ python3 scripts/build_seal_glyph_index.py --dry-run
23
+ ```
24
+
25
+ 建立检索库(默认读取 `/Users/mnhkahn/code/wangxizhi`,输出到
26
+ `data/seal_glyph_index`):
27
+
28
+ ```bash
29
+ python3 scripts/build_seal_glyph_index.py
30
+ ```
31
+
32
+ 查询一个已切好的单字图:
33
+
34
+ ```bash
35
+ python3 scripts/query_seal_glyph_index.py path/to/glyph.png --top-k 10 --unique-chars
36
+ ```
37
+
38
+ 输出包含候选汉字、相似度、书家、作品、页图路径与标准化后的候选字图。
39
+ 相似度仅表示当前基线的图形接近程度,不是正确率或模型置信度;低相似度时
40
+ 应视为字库未覆盖或需要人工判断。
41
+
42
+ 可对已有索引运行留一法评测;该评测会排除查询图自身,并按候选汉字去重:
43
+
44
+ ```bash
45
+ python3 scripts/evaluate_seal_glyph_index.py --report data/seal_glyph_index/evaluation.json
46
+ python3 scripts/evaluate_seal_glyph_index.py --exclude-same-work \
47
+ --report data/seal_glyph_index/evaluation-cross-work.json
48
+ ```
49
+
50
+ 第二种模式还会排除同一部字帖的所有字形,衡量跨字帖检索能力。由于当前多数
51
+ 汉字只有一个样本,这个严格指标的可评测样本会很少;它用于发现数据覆盖不足,
52
+ 不能单独视为产品准确率。
53
+
54
+ HOG 是无训练的图形基线。若环境已经安装 PyTorch 与 Transformers,可用 DINOv2
55
+ 预训练视觉模型生成更强的检索向量,再用同一评测脚本比较效果:
56
+
57
+ ```bash
58
+ venv312/bin/python scripts/build_seal_visual_embeddings.py
59
+ venv312/bin/python scripts/evaluate_seal_glyph_index.py \
60
+ --features data/seal_glyph_index/features_facebook_dinov2_small.npy
61
+ ```
62
+
63
+ 网络不可用时,也可复用当前项目已经训练好的汉字 ResNet-50 的倒数第二层,
64
+ 无需下载任何模型:
65
+
66
+ ```bash
67
+ venv312/bin/python scripts/build_seal_visual_embeddings.py \
68
+ --local-checkpoint best_model.pth --batch-size 8
69
+ ```
70
+
71
+ 生成后可用 ResNet-50 向量实际查询单字:
72
+
73
+ ```bash
74
+ venv312/bin/python scripts/query_seal_visual_index.py path/to/glyph.png --top-k 10
75
+ ```
76
+
77
+ ## 部署用识别入口
78
+
79
+ 部署时使用 `scripts/recognize_seal_glyph.py`,它会自动裁掉上传图的留白、
80
+ 归一化为单字图,并返回唯一汉字的 Top-K 候选及出处:
81
+
82
+ ```bash
83
+ venv312/bin/python scripts/recognize_seal_glyph.py path/to/glyph.png --top-k 10
84
+ ```
85
+
86
+ Hugging Face Space 需要一同包含以下文件,不需要 `wangxizhi` 源项目:
87
+
88
+ ```text
89
+ best_model.pth
90
+ char_map.json
91
+ data/seal_glyph_index/metadata.jsonl
92
+ data/seal_glyph_index/glyphs/
93
+ data/seal_glyph_index/features_local_resnet50.npy
94
+ data/seal_glyph_index/features_local_resnet50.json
95
+ data/seal_glyph_index/component_features_hog.npy
96
+ data/seal_glyph_index/component_valid.npy
97
+ data/seal_glyph_index/component_manifest.json
98
+ scripts/recognize_seal_glyph.py
99
+ utils/seal_recognizer.py
100
+ utils/seal_components.py
101
+ ```
102
+
103
+ 服务端接口为 `POST /seal-search`,表单字段为 `file`。它固定返回 5 个候选:
104
+ 前 3 个 `match_type: whole` 是整字候选,后 2 个 `match_type: component`
105
+ 是局部字形候选,并会标注命中的图像区域。
106
+
107
+ 若只看字的一部分(例如右边的 `㐬`),可额外构建并部署部件索引:
108
+
109
+ ```bash
110
+ python3 scripts/build_seal_component_index.py
111
+ python3 scripts/search_seal_component.py path/to/glyph.png --part right --top-k 10
112
+ ```
113
+
114
+ 部件候选仅表示局部字形相近,不能当作完整汉字的识别结果。
app.py CHANGED
@@ -9,6 +9,7 @@ from typing import List, Dict
9
  from fastapi import FastAPI, File, UploadFile, HTTPException, Request, Body, Query
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from fastapi.responses import JSONResponse
 
12
  import io
13
  import cv2
14
  import numpy as np
@@ -32,6 +33,7 @@ from utils.ocr import apply_ocr, save_csv
32
  from utils.title_scoring import score_article_titles
33
  from utils.summarization import summarize_text
34
  from utils.git import get_git_commit_message
 
35
 
36
 
37
  # 设置日志
@@ -41,6 +43,7 @@ logger = logging.getLogger(__name__)
41
  # --- 配置部分 ---
42
  MODEL_PATH = "best_model.pth"
43
  MAP_PATH = "char_map.json"
 
44
  hf_token = os.getenv("read_token")
45
  FEISHU_WEBHOOK_URL = os.getenv("FEISHU_WEBHOOK_URL")
46
  WEB_HOOK = os.getenv("WEB_HOOK")
@@ -276,6 +279,13 @@ app.add_middleware(
276
  allow_headers=["*"],
277
  )
278
 
 
 
 
 
 
 
 
279
  # 初始化识别器(全局单例)
280
  try:
281
  recognizer = Recognizer()
@@ -285,6 +295,17 @@ except Exception as e:
285
  logger.error(f"启动失败: {e}")
286
  recognizer = None
287
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
  # --- API 路由 ---
290
  @app.post("/upload", response_model=List[Dict[str, str]])
@@ -314,6 +335,54 @@ async def upload_image(request: Request, file: UploadFile = File(...)):
314
  raise HTTPException(status_code=500, detail=f"服务器内部错误: {e}")
315
 
316
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  # 调试接口
318
  @app.post("/debug_upload")
319
  async def debug_upload(request: Request, file: UploadFile = File(...)):
@@ -640,8 +709,6 @@ async def generate_summary(
640
  raise HTTPException(status_code=500, detail=f"服务器内部错误: {e}")
641
 
642
 
643
- from fastapi.staticfiles import StaticFiles
644
-
645
  app.mount("/", StaticFiles(directory="static", html=True), name="web")
646
 
647
 
 
9
  from fastapi import FastAPI, File, UploadFile, HTTPException, Request, Body, Query
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from fastapi.responses import JSONResponse
12
+ from fastapi.staticfiles import StaticFiles
13
  import io
14
  import cv2
15
  import numpy as np
 
33
  from utils.title_scoring import score_article_titles
34
  from utils.summarization import summarize_text
35
  from utils.git import get_git_commit_message
36
+ from utils.seal_recognizer import SealGlyphRecognizer
37
 
38
 
39
  # 设置日志
 
43
  # --- 配置部分 ---
44
  MODEL_PATH = "best_model.pth"
45
  MAP_PATH = "char_map.json"
46
+ SEAL_INDEX_PATH = "data/seal_glyph_index"
47
  hf_token = os.getenv("read_token")
48
  FEISHU_WEBHOOK_URL = os.getenv("FEISHU_WEBHOOK_URL")
49
  WEB_HOOK = os.getenv("WEB_HOOK")
 
279
  allow_headers=["*"],
280
  )
281
 
282
+ # Expose the indexed reference glyphs so API clients can render each candidate.
283
+ app.mount(
284
+ "/seal-glyphs",
285
+ StaticFiles(directory=os.path.join(SEAL_INDEX_PATH, "glyphs")),
286
+ name="seal-glyphs",
287
+ )
288
+
289
  # 初始化识别器(全局单例)
290
  try:
291
  recognizer = Recognizer()
 
295
  logger.error(f"启动失败: {e}")
296
  recognizer = None
297
 
298
+ try:
299
+ seal_recognizer = SealGlyphRecognizer(
300
+ index_dir=SEAL_INDEX_PATH,
301
+ checkpoint_path=MODEL_PATH,
302
+ char_map_path=MAP_PATH,
303
+ )
304
+ logger.info("小篆检索索引加载成功")
305
+ except Exception as e:
306
+ logger.warning(f"小篆检索索引未加载: {e}")
307
+ seal_recognizer = None
308
+
309
 
310
  # --- API 路由 ---
311
  @app.post("/upload", response_model=List[Dict[str, str]])
 
335
  raise HTTPException(status_code=500, detail=f"服务器内部错误: {e}")
336
 
337
 
338
+ def _seal_match_response(item: Dict, match_type: str) -> Dict:
339
+ """Keep the public API stable and avoid returning server-local source paths."""
340
+ response = {
341
+ "char": item["char"],
342
+ "match_type": match_type,
343
+ "author": item.get("author", ""),
344
+ "work": item.get("work", ""),
345
+ "page": item.get("page", ""),
346
+ "glyph_image": f"/seal-glyphs/{os.path.basename(item.get('glyph_image', ''))}",
347
+ }
348
+ if match_type == "whole":
349
+ response["similarity"] = item["similarity"]
350
+ else:
351
+ response["similarity"] = item["component_similarity"]
352
+ response["component"] = item.get("component", "")
353
+ return response
354
+
355
+
356
+ @app.post("/seal-search")
357
+ async def seal_search(file: UploadFile = File(...)):
358
+ """Return three whole-glyph and two component-level small-seal candidates."""
359
+ if not seal_recognizer:
360
+ raise HTTPException(status_code=503, detail="小篆检索索引尚未部署或加载失败。")
361
+ if not file.content_type or not file.content_type.startswith("image/"):
362
+ raise HTTPException(status_code=400, detail="上传文件必须是图片格式。")
363
+ try:
364
+ image_bytes = await file.read()
365
+ with Image.open(io.BytesIO(image_bytes)) as uploaded:
366
+ image = uploaded.convert("RGB")
367
+ whole_matches = seal_recognizer.recognize(image, top_k=3)
368
+ component_matches = seal_recognizer.recognize_components(
369
+ image,
370
+ top_k=2,
371
+ exclude_characters={item["char"] for item in whole_matches},
372
+ )
373
+ return {
374
+ "matches": [
375
+ *[_seal_match_response(item, "whole") for item in whole_matches],
376
+ *[_seal_match_response(item, "component") for item in component_matches],
377
+ ]
378
+ }
379
+ except ValueError as exc:
380
+ raise HTTPException(status_code=400, detail=str(exc))
381
+ except Exception as exc:
382
+ logger.exception("小篆检索失败")
383
+ raise HTTPException(status_code=500, detail=f"小篆检索失败: {exc}")
384
+
385
+
386
  # 调试接口
387
  @app.post("/debug_upload")
388
  async def debug_upload(request: Request, file: UploadFile = File(...)):
 
709
  raise HTTPException(status_code=500, detail=f"服务器内部错误: {e}")
710
 
711
 
 
 
712
  app.mount("/", StaticFiles(directory="static", html=True), name="web")
713
 
714
 
data/seal_glyph_index/char_counts.json ADDED
@@ -0,0 +1,647 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "皇": 3,
3
+ "帝": 4,
4
+ "立": 2,
5
+ "國": 1,
6
+ "維": 1,
7
+ "初": 2,
8
+ "在": 2,
9
+ "昔": 1,
10
+ "嗣": 1,
11
+ "世": 4,
12
+ "稱": 1,
13
+ "王": 2,
14
+ "討": 1,
15
+ "伐": 2,
16
+ "亂": 2,
17
+ "逆": 1,
18
+ "威": 1,
19
+ "動": 1,
20
+ "四": 2,
21
+ "極": 1,
22
+ "武": 2,
23
+ "義": 1,
24
+ "直": 1,
25
+ "方": 2,
26
+ "戎": 2,
27
+ "臣": 4,
28
+ "奉": 2,
29
+ "詔": 1,
30
+ "經": 1,
31
+ "時": 2,
32
+ "不": 6,
33
+ "久": 2,
34
+ "滅": 2,
35
+ "六": 2,
36
+ "暴": 1,
37
+ "強": 1,
38
+ "廿": 1,
39
+ "有": 3,
40
+ "年": 1,
41
+ "上": 4,
42
+ "薦": 1,
43
+ "高": 3,
44
+ "號": 1,
45
+ "孝": 2,
46
+ "道": 2,
47
+ "顯": 1,
48
+ "明": 2,
49
+ "既": 2,
50
+ "獻": 1,
51
+ "泰": 2,
52
+ "成": 1,
53
+ "乃": 2,
54
+ "降": 1,
55
+ "尃": 1,
56
+ "惠": 2,
57
+ "寴": 1,
58
+ "𨊩": 1,
59
+ "遠": 1,
60
+ "登": 2,
61
+ "於": 2,
62
+ "繹": 1,
63
+ "山": 1,
64
+ "羣": 2,
65
+ "從": 1,
66
+ "者": 1,
67
+ "咸": 2,
68
+ "思": 2,
69
+ "攸": 1,
70
+ "長": 2,
71
+ "追": 1,
72
+ "念": 2,
73
+ "分": 2,
74
+ "土": 1,
75
+ "建": 2,
76
+ "邦": 1,
77
+ "以": 2,
78
+ "開": 1,
79
+ "爭": 1,
80
+ "理": 1,
81
+ "功": 2,
82
+ "戰": 1,
83
+ "日": 3,
84
+ "作": 2,
85
+ "流": 2,
86
+ "血": 1,
87
+ "野": 2,
88
+ "自": 2,
89
+ "古": 2,
90
+ "始": 2,
91
+ "無": 1,
92
+ "萬": 1,
93
+ "數": 1,
94
+ "陀": 1,
95
+ "及": 1,
96
+ "五": 1,
97
+ "莫": 2,
98
+ "能": 2,
99
+ "禁": 1,
100
+ "止": 2,
101
+ "廼": 1,
102
+ "今": 1,
103
+ "壹": 1,
104
+ "家": 2,
105
+ "天": 2,
106
+ "下": 4,
107
+ "兵": 2,
108
+ "復": 1,
109
+ "起": 1,
110
+ "災": 1,
111
+ "害": 1,
112
+ "除": 1,
113
+ "黔": 1,
114
+ "首": 2,
115
+ "康": 1,
116
+ "定": 2,
117
+ "利": 1,
118
+ "澤": 1,
119
+ "誦": 1,
120
+ "千": 2,
121
+ "字": 2,
122
+ "文": 2,
123
+ "地": 2,
124
+ "玄": 1,
125
+ "黄": 1,
126
+ "宇": 1,
127
+ "宙": 1,
128
+ "洪": 1,
129
+ "荒": 1,
130
+ "月": 2,
131
+ "盈": 1,
132
+ "昃": 1,
133
+ "律": 1,
134
+ "吕": 1,
135
+ "调": 1,
136
+ "阳": 1,
137
+ "云": 2,
138
+ "腾": 1,
139
+ "致": 1,
140
+ "雨": 1,
141
+ "露": 1,
142
+ "结": 1,
143
+ "为": 1,
144
+ "霜": 1,
145
+ "金": 1,
146
+ "生": 1,
147
+ "丽": 1,
148
+ "水": 1,
149
+ "菜": 1,
150
+ "重": 1,
151
+ "芥": 1,
152
+ "姜": 1,
153
+ "海": 1,
154
+ "河": 1,
155
+ "淡": 1,
156
+ "鳞": 1,
157
+ "潜": 1,
158
+ "羽": 1,
159
+ "翔": 1,
160
+ "龙": 1,
161
+ "师": 1,
162
+ "火": 1,
163
+ "虞": 1,
164
+ "陶": 1,
165
+ "唐": 1,
166
+ "吊": 1,
167
+ "民": 1,
168
+ "罪": 1,
169
+ "周": 1,
170
+ "发": 1,
171
+ "殷": 1,
172
+ "汤": 1,
173
+ "坐": 1,
174
+ "朝": 1,
175
+ "问": 1,
176
+ "得": 1,
177
+ "忘": 1,
178
+ "罔": 1,
179
+ "谈": 1,
180
+ "彼": 1,
181
+ "短": 1,
182
+ "靡": 1,
183
+ "恃": 1,
184
+ "己": 1,
185
+ "长": 1,
186
+ "信": 1,
187
+ "使": 1,
188
+ "可": 1,
189
+ "覆": 2,
190
+ "鸟": 1,
191
+ "官": 1,
192
+ "人": 2,
193
+ "制": 1,
194
+ "服": 1,
195
+ "衣": 1,
196
+ "裳": 1,
197
+ "推": 1,
198
+ "位": 1,
199
+ "让": 1,
200
+ "国": 1,
201
+ "垂": 1,
202
+ "拱": 1,
203
+ "平": 1,
204
+ "章": 1,
205
+ "爱": 1,
206
+ "育": 1,
207
+ "黎": 1,
208
+ "伏": 1,
209
+ "羌": 1,
210
+ "遐": 1,
211
+ "迩": 1,
212
+ "一": 2,
213
+ "体": 1,
214
+ "率": 1,
215
+ "宾": 1,
216
+ "归": 1,
217
+ "鸣": 1,
218
+ "凤": 1,
219
+ "竹": 1,
220
+ "白": 1,
221
+ "驹": 1,
222
+ "食": 1,
223
+ "场": 1,
224
+ "化": 1,
225
+ "被": 1,
226
+ "草": 2,
227
+ "木": 2,
228
+ "寸": 1,
229
+ "阴": 1,
230
+ "是": 1,
231
+ "竞": 1,
232
+ "资": 1,
233
+ "父": 1,
234
+ "事": 1,
235
+ "君": 1,
236
+ "曰": 1,
237
+ "严": 1,
238
+ "与": 1,
239
+ "敬": 1,
240
+ "当": 1,
241
+ "竭": 1,
242
+ "力": 1,
243
+ "忠": 1,
244
+ "则": 1,
245
+ "尽": 1,
246
+ "命": 1,
247
+ "临": 1,
248
+ "深": 1,
249
+ "履": 1,
250
+ "薄": 1,
251
+ "夙": 1,
252
+ "兴": 1,
253
+ "温": 1,
254
+ "凊": 1,
255
+ "似": 1,
256
+ "兰": 1,
257
+ "斯": 1,
258
+ "馨": 1,
259
+ "言": 1,
260
+ "辞": 1,
261
+ "安": 1,
262
+ "笃": 1,
263
+ "诚": 1,
264
+ "美": 1,
265
+ "慎": 1,
266
+ "终": 1,
267
+ "宜": 1,
268
+ "令": 1,
269
+ "荣": 1,
270
+ "业": 1,
271
+ "所": 1,
272
+ "基": 1,
273
+ "如": 4,
274
+ "松": 3,
275
+ "之": 1,
276
+ "盛": 1,
277
+ "川": 1,
278
+ "息": 1,
279
+ "渊": 1,
280
+ "澄": 1,
281
+ "取": 1,
282
+ "映": 1,
283
+ "容": 1,
284
+ "若": 1,
285
+ "籍": 1,
286
+ "甚": 1,
287
+ "无": 1,
288
+ "竟": 1,
289
+ "学": 1,
290
+ "优": 1,
291
+ "仕": 1,
292
+ "摄": 1,
293
+ "职": 1,
294
+ "从": 1,
295
+ "政": 1,
296
+ "存": 1,
297
+ "甘": 1,
298
+ "棠": 1,
299
+ "去": 2,
300
+ "而": 2,
301
+ "益": 2,
302
+ "咏": 2,
303
+ "乐": 2,
304
+ "殊": 2,
305
+ "贵": 2,
306
+ "贱": 2,
307
+ "礼": 2,
308
+ "别": 2,
309
+ "尊": 2,
310
+ "卑": 2,
311
+ "和": 2,
312
+ "睦": 2,
313
+ "克": 1,
314
+ "圣": 1,
315
+ "德": 1,
316
+ "名": 2,
317
+ "形": 1,
318
+ "端": 1,
319
+ "表": 1,
320
+ "正": 1,
321
+ "空": 2,
322
+ "谷": 1,
323
+ "传": 1,
324
+ "声": 1,
325
+ "虚": 1,
326
+ "堂": 1,
327
+ "习": 1,
328
+ "听": 1,
329
+ "祸": 1,
330
+ "因": 1,
331
+ "恶": 1,
332
+ "积": 1,
333
+ "福": 1,
334
+ "缘": 1,
335
+ "善": 1,
336
+ "庆": 1,
337
+ "尺": 2,
338
+ "璧": 1,
339
+ "非": 1,
340
+ "宝": 1,
341
+ "器": 1,
342
+ "欲": 1,
343
+ "难": 1,
344
+ "量": 1,
345
+ "墨": 1,
346
+ "悲": 1,
347
+ "丝": 1,
348
+ "染": 1,
349
+ "诗": 1,
350
+ "赞": 1,
351
+ "羔": 1,
352
+ "羊": 1,
353
+ "景": 1,
354
+ "行": 1,
355
+ "维": 1,
356
+ "贤": 1,
357
+ "逐": 1,
358
+ "物": 1,
359
+ "意": 1,
360
+ "移": 1,
361
+ "坚": 1,
362
+ "持": 1,
363
+ "雅": 1,
364
+ "操": 1,
365
+ "好": 1,
366
+ "爵": 1,
367
+ "縻": 1,
368
+ "都": 1,
369
+ "邑": 1,
370
+ "华": 1,
371
+ "夏": 1,
372
+ "切": 2,
373
+ "磨": 2,
374
+ "箴": 2,
375
+ "规": 2,
376
+ "仁": 1,
377
+ "慈": 1,
378
+ "隐": 1,
379
+ "恻": 1,
380
+ "造": 1,
381
+ "次": 1,
382
+ "弗": 1,
383
+ "离": 1,
384
+ "节": 1,
385
+ "义": 1,
386
+ "廉": 1,
387
+ "退": 1,
388
+ "亦": 1,
389
+ "聚": 1,
390
+ "群": 1,
391
+ "英": 1,
392
+ "杜": 1,
393
+ "稿": 1,
394
+ "钟": 1,
395
+ "隶": 1,
396
+ "漆": 1,
397
+ "书": 1,
398
+ "壁": 1,
399
+ "经": 1,
400
+ "府": 1,
401
+ "罗": 1,
402
+ "将": 1,
403
+ "相": 1,
404
+ "甲": 1,
405
+ "帐": 1,
406
+ "对": 1,
407
+ "楹": 1,
408
+ "肆": 1,
409
+ "筵": 1,
410
+ "设": 1,
411
+ "席": 1,
412
+ "鼓": 1,
413
+ "瑟": 1,
414
+ "吹": 1,
415
+ "笙": 1,
416
+ "升": 1,
417
+ "阶": 1,
418
+ "纳": 1,
419
+ "陛": 1,
420
+ "楼": 1,
421
+ "观": 1,
422
+ "飞": 1,
423
+ "惊": 1,
424
+ "图": 1,
425
+ "写": 1,
426
+ "禽": 1,
427
+ "兽": 1,
428
+ "画": 1,
429
+ "彩": 1,
430
+ "仙": 1,
431
+ "灵": 1,
432
+ "丙": 1,
433
+ "舍": 1,
434
+ "傍": 1,
435
+ "启": 1,
436
+ "颠": 1,
437
+ "沛": 1,
438
+ "匪": 1,
439
+ "亏": 1,
440
+ "性": 1,
441
+ "静": 1,
442
+ "情": 1,
443
+ "逸": 1,
444
+ "心": 1,
445
+ "动": 1,
446
+ "神": 1,
447
+ "疲": 1,
448
+ "守": 1,
449
+ "真": 1,
450
+ "志": 1,
451
+ "满": 1,
452
+ "孔": 1,
453
+ "怀": 1,
454
+ "兄": 1,
455
+ "弟": 1,
456
+ "同": 1,
457
+ "气": 1,
458
+ "连": 1,
459
+ "枝": 2,
460
+ "交": 1,
461
+ "友": 1,
462
+ "投": 1,
463
+ "夫": 1,
464
+ "唱": 1,
465
+ "妇": 1,
466
+ "随": 1,
467
+ "外": 1,
468
+ "受": 1,
469
+ "傅": 1,
470
+ "训": 1,
471
+ "入": 1,
472
+ "母": 1,
473
+ "仪": 1,
474
+ "诸": 1,
475
+ "姑": 1,
476
+ "伯": 1,
477
+ "叔": 1,
478
+ "弁": 1,
479
+ "转": 1,
480
+ "疑": 1,
481
+ "星": 1,
482
+ "右": 1,
483
+ "通": 1,
484
+ "广": 1,
485
+ "内": 1,
486
+ "左": 1,
487
+ "达": 1,
488
+ "承": 2,
489
+ "集": 1,
490
+ "坟": 1,
491
+ "典": 1,
492
+ "东": 1,
493
+ "西": 1,
494
+ "二": 1,
495
+ "京": 1,
496
+ "背": 1,
497
+ "邙": 1,
498
+ "面": 1,
499
+ "洛": 1,
500
+ "浮": 1,
501
+ "渭": 1,
502
+ "据": 1,
503
+ "泾": 1,
504
+ "宫": 1,
505
+ "殿": 1,
506
+ "盘": 1,
507
+ "郁": 1,
508
+ "说": 1,
509
+ "感": 1,
510
+ "丁": 1,
511
+ "俊": 1,
512
+ "乂": 1,
513
+ "密": 1,
514
+ "勿": 1,
515
+ "多": 2,
516
+ "士": 1,
517
+ "实": 2,
518
+ "宁": 1,
519
+ "晋": 1,
520
+ "楚": 1,
521
+ "更": 1,
522
+ "霸": 1,
523
+ "路": 1,
524
+ "侠": 1,
525
+ "槐": 1,
526
+ "卿": 1,
527
+ "户": 1,
528
+ "封": 1,
529
+ "八": 1,
530
+ "县": 1,
531
+ "给": 1,
532
+ "冠": 1,
533
+ "陪": 1,
534
+ "辇": 1,
535
+ "微": 1,
536
+ "旦": 1,
537
+ "孰": 1,
538
+ "营": 1,
539
+ "桓": 1,
540
+ "公": 1,
541
+ "匡": 1,
542
+ "合": 1,
543
+ "济": 1,
544
+ "弱": 1,
545
+ "扶": 1,
546
+ "倾": 1,
547
+ "绮": 1,
548
+ "回": 1,
549
+ "汉": 1,
550
+ "驱": 1,
551
+ "毂": 1,
552
+ "振": 1,
553
+ "缨": 1,
554
+ "禄": 1,
555
+ "侈": 1,
556
+ "富": 1,
557
+ "车": 1,
558
+ "驾": 1,
559
+ "肥": 1,
560
+ "轻": 1,
561
+ "策": 1,
562
+ "茂": 1,
563
+ "禅": 1,
564
+ "主": 1,
565
+ "亭": 1,
566
+ "雁": 1,
567
+ "门": 1,
568
+ "紫": 1,
569
+ "塞": 1,
570
+ "鸡": 1,
571
+ "田": 1,
572
+ "赤": 1,
573
+ "城": 1,
574
+ "昆": 1,
575
+ "池": 1,
576
+ "碣": 1,
577
+ "石": 3,
578
+ "钜": 1,
579
+ "洞": 1,
580
+ "庭": 1,
581
+ "旷": 1,
582
+ "远": 1,
583
+ "绵": 1,
584
+ "邈": 1,
585
+ "岩": 1,
586
+ "岫": 1,
587
+ "杳": 1,
588
+ "冥": 1,
589
+ "治": 1,
590
+ "本": 1,
591
+ "于": 1,
592
+ "农": 1,
593
+ "澗": 2,
594
+ "夾": 1,
595
+ "南": 1,
596
+ "抵": 1,
597
+ "老": 1,
598
+ "杉": 1,
599
+ "大": 1,
600
+ "僅": 1,
601
+ "十": 1,
602
+ "圍": 1,
603
+ "知": 2,
604
+ "幾": 1,
605
+ "百": 1,
606
+ "修": 1,
607
+ "柯": 1,
608
+ "戛": 1,
609
+ "雲": 1,
610
+ "低": 1,
611
+ "拂": 1,
612
+ "潭": 1,
613
+ "幢": 1,
614
+ "樹": 1,
615
+ "蓋": 2,
616
+ "張": 1,
617
+ "龍": 1,
618
+ "蛇": 1,
619
+ "走": 1,
620
+ "灌": 1,
621
+ "叢": 1,
622
+ "蘿": 1,
623
+ "蔦": 1,
624
+ "葉": 1,
625
+ "蔓": 1,
626
+ "駢": 1,
627
+ "織": 1,
628
+ "翳": 1,
629
+ "光": 1,
630
+ "到": 1,
631
+ "北": 1,
632
+ "據": 1,
633
+ "層": 1,
634
+ "巖": 1,
635
+ "積": 1,
636
+ "嵌": 1,
637
+ "奇": 1,
638
+ "異": 1,
639
+ "其": 2,
640
+ "綠": 1,
641
+ "陰": 1,
642
+ "蒙": 1,
643
+ "朱": 1,
644
+ "實": 1,
645
+ "離": 1,
646
+ "色": 1
647
+ }
data/seal_glyph_index/component_features_hog.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:15c0b2b8ec390edc343531f017e8d28b0cb734ce3d75163bdb3ae347bce31446
3
+ size 27059888
data/seal_glyph_index/component_manifest.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format": "seal-component-index/v1",
3
+ "feature": "HOG cosine similarity",
4
+ "parts": [
5
+ "left",
6
+ "right",
7
+ "top",
8
+ "bottom",
9
+ "center"
10
+ ],
11
+ "glyph_count": 767,
12
+ "feature_dimension": 1764
13
+ }
data/seal_glyph_index/component_valid.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7dfd4429079759bfd56fd5008546ddae372f979bcdc54b0a7a5134fc11ab0c7
3
+ size 3963
data/seal_glyph_index/features_local_resnet50.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format": "seal-glyph-embeddings/v1",
3
+ "backend": "local-resnet50",
4
+ "model": "best_model.pth",
5
+ "device": "cpu",
6
+ "image_size": 128,
7
+ "glyph_count": 767,
8
+ "embedding_dimension": 2048,
9
+ "features_file": "features_local_resnet50.npy"
10
+ }
data/seal_glyph_index/features_local_resnet50.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5de2b998d661c55b7d64ee177e49b5a25fb0c2677e7c6e38bc8457e9f44a5bb
3
+ size 6283392
data/seal_glyph_index/glyphs/000fd501a764b9d442ba5e9e6cadaf6cccd8c5e4.png ADDED
data/seal_glyph_index/glyphs/004716899208a13645957764089463ed9ddcb106.png ADDED
data/seal_glyph_index/glyphs/008d89e33501899e38956f250bc5741b6a25eb12.png ADDED
data/seal_glyph_index/glyphs/015a0edf3abfb955661e56b3b9ab631f228b8827.png ADDED
data/seal_glyph_index/glyphs/015baaeed912f36fb8543099e5d949a76d1f153a.png ADDED
data/seal_glyph_index/glyphs/0194c724c965cbbc9b38e9a6fa3e3bfdd7cf163e.png ADDED
data/seal_glyph_index/glyphs/01adf2296c8a2f0784f5d9631bbd13f7ba414bf5.png ADDED
data/seal_glyph_index/glyphs/025402e2a774301a6faa2da1fd8ba6bddec5ad85.png ADDED
data/seal_glyph_index/glyphs/02918009845389252db1e630d62b3d0c907e9f74.png ADDED
data/seal_glyph_index/glyphs/032f0721c110f781e52130a4db05a458a05ec87e.png ADDED
data/seal_glyph_index/glyphs/03412bd3401f8bc5bf3cc6e0d7298250aaa40bed.png ADDED
data/seal_glyph_index/glyphs/035404f1d065c9325a1eabbdc793b96b4b820cb7.png ADDED
data/seal_glyph_index/glyphs/03c099067199f7f21e65610b5567396f5bc2c017.png ADDED
data/seal_glyph_index/glyphs/03c538e5c93e448b0daedd471f6a25eb4e877404.png ADDED
data/seal_glyph_index/glyphs/03ea6a39420d4ad7f3b1cd045a9c419382fae31f.png ADDED
data/seal_glyph_index/glyphs/0429aba8dc35c7f1b40d780173e69c8d60ff5380.png ADDED
data/seal_glyph_index/glyphs/044af22e0d46d8dd4fa4267298dc3a240c44550a.png ADDED
data/seal_glyph_index/glyphs/0497302b1e7f05f8fd5f2d34ea68a83a27640366.png ADDED
data/seal_glyph_index/glyphs/04bb44fee3be8c44dee9186c9e651edfe8086764.png ADDED
data/seal_glyph_index/glyphs/05b79322f37bba527f13c0d163f4f7c707370099.png ADDED
data/seal_glyph_index/glyphs/05c9b121f49560466fecfef63183d779c86d50c9.png ADDED
data/seal_glyph_index/glyphs/05ca0ec208110dd6b42049102f9527a8b0492d86.png ADDED
data/seal_glyph_index/glyphs/0609104dcce2eb66a5dd30f6c4626ff7f866d3cf.png ADDED
data/seal_glyph_index/glyphs/065d2199c4db5391ec4861385ce40c292975e897.png ADDED
data/seal_glyph_index/glyphs/067b4570fdc5dd05d3b473aadf0f4d26caf19f65.png ADDED
data/seal_glyph_index/glyphs/068697ae9f656f8b79081612a42c27a79c61aeb1.png ADDED
data/seal_glyph_index/glyphs/06e53420a2cc673a81dd14728fd6d103794df057.png ADDED
data/seal_glyph_index/glyphs/07c4cfc19b267536d694f055e228ad4c32e0fe53.png ADDED
data/seal_glyph_index/glyphs/07c76a9f83eeaa57ecade83cbdde7c600fc08a80.png ADDED
data/seal_glyph_index/glyphs/085b14f8c3c93d9e184fb7a47d9737632908d7f6.png ADDED
data/seal_glyph_index/glyphs/089b2a4fda7e1cce50f801f50b631aa6bc75c426.png ADDED
data/seal_glyph_index/glyphs/093e3708f0aea50fc35659cbc8c65590563a496f.png ADDED
data/seal_glyph_index/glyphs/09575e263ae2f77a9bbff0af0173471a6ee9fa70.png ADDED
data/seal_glyph_index/glyphs/0a183d5d54f4d02f7c4bff164c7e1e53b2474f82.png ADDED
data/seal_glyph_index/glyphs/0a78ab56ecd2449b84181c01efde6c9bdcff1359.png ADDED
data/seal_glyph_index/glyphs/0b46b9ab66e8414adc2526140fa3898e7be7241d.png ADDED
data/seal_glyph_index/glyphs/0b5c5abb076058b4f72ce0713e733d0703f04e58.png ADDED
data/seal_glyph_index/glyphs/0b893f4707e6d6305599f0ddaf0034047c51ab1a.png ADDED
data/seal_glyph_index/glyphs/0b96e6e28e15aaac8b66ba275d14937e1ae84996.png ADDED
data/seal_glyph_index/glyphs/0d3ba263bab90848b219b5e1ecd38c7e7e0054b4.png ADDED
data/seal_glyph_index/glyphs/0d48cf87341d20d7a20002d6aeff5508a5ec098a.png ADDED