yomitoku 0.5.3__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. {yomitoku-0.5.3 → yomitoku-0.6.0}/.github/workflows/lint-and-test.yml +1 -1
  2. {yomitoku-0.5.3 → yomitoku-0.6.0}/.gitignore +3 -1
  3. yomitoku-0.6.0/.python-version +1 -0
  4. {yomitoku-0.5.3 → yomitoku-0.6.0}/PKG-INFO +12 -7
  5. {yomitoku-0.5.3 → yomitoku-0.6.0}/README.md +7 -5
  6. {yomitoku-0.5.3 → yomitoku-0.6.0}/README_EN.md +2 -1
  7. yomitoku-0.6.0/configs/table_structure_recognitizer.yaml +67 -0
  8. yomitoku-0.6.0/configs/text_recognizer.yaml +32 -0
  9. {yomitoku-0.5.3 → yomitoku-0.6.0}/docs/installation.en.md +1 -1
  10. {yomitoku-0.5.3 → yomitoku-0.6.0}/docs/installation.ja.md +1 -1
  11. {yomitoku-0.5.3 → yomitoku-0.6.0}/docs/usage.en.md +1 -0
  12. {yomitoku-0.5.3 → yomitoku-0.6.0}/docs/usage.ja.md +1 -0
  13. {yomitoku-0.5.3 → yomitoku-0.6.0}/pyproject.toml +5 -2
  14. {yomitoku-0.5.3 → yomitoku-0.6.0}/scripts/register_hugging_face_hub.py +1 -1
  15. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/cli/main.py +15 -0
  16. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/configs/__init__.py +2 -0
  17. yomitoku-0.6.0/src/yomitoku/configs/cfg_text_recognizer_parseq_small.py +51 -0
  18. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/layout_parser.py +53 -3
  19. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/layers/rtdetr_backbone.py +5 -15
  20. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/layers/rtdetr_hybrid_encoder.py +6 -18
  21. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/layers/rtdetrv2_decoder.py +17 -42
  22. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/parseq.py +9 -9
  23. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/postprocessor/rtdetr_postprocessor.py +4 -13
  24. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/table_structure_recognizer.py +57 -4
  25. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/text_detector.py +49 -4
  26. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/text_recognizer.py +58 -9
  27. yomitoku-0.6.0/tests/data/invalid.pdf +0 -0
  28. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/test_cli.py +3 -0
  29. {yomitoku-0.5.3 → yomitoku-0.6.0}/uv.lock +160 -240
  30. yomitoku-0.5.3/.python-version +0 -1
  31. yomitoku-0.5.3/configs/table_structure_recognitizer.yaml +0 -2
  32. yomitoku-0.5.3/configs/text_recognizer.yaml +0 -14
  33. {yomitoku-0.5.3 → yomitoku-0.6.0}/.github/release-drafter.yml +0 -0
  34. {yomitoku-0.5.3 → yomitoku-0.6.0}/.github/workflows/build-and-publish-docs.yaml +0 -0
  35. {yomitoku-0.5.3 → yomitoku-0.6.0}/.github/workflows/build-and-publish.yml +0 -0
  36. {yomitoku-0.5.3 → yomitoku-0.6.0}/.github/workflows/create-release.yml +0 -0
  37. {yomitoku-0.5.3 → yomitoku-0.6.0}/.pre-commit-config.yaml +0 -0
  38. {yomitoku-0.5.3 → yomitoku-0.6.0}/configs/layout_parser_rtdetrv2.yaml +0 -0
  39. {yomitoku-0.5.3 → yomitoku-0.6.0}/configs/text_detector.yaml +0 -0
  40. {yomitoku-0.5.3 → yomitoku-0.6.0}/demo/sample.pdf +0 -0
  41. {yomitoku-0.5.3 → yomitoku-0.6.0}/demo/setting_document_anaysis.py +0 -0
  42. {yomitoku-0.5.3 → yomitoku-0.6.0}/demo/simple_document_analysis.py +0 -0
  43. {yomitoku-0.5.3 → yomitoku-0.6.0}/demo/simple_layout.py +0 -0
  44. {yomitoku-0.5.3 → yomitoku-0.6.0}/demo/simple_ocr.py +0 -0
  45. {yomitoku-0.5.3 → yomitoku-0.6.0}/demo/text_detector.yaml +0 -0
  46. {yomitoku-0.5.3 → yomitoku-0.6.0}/dockerfile +0 -0
  47. {yomitoku-0.5.3 → yomitoku-0.6.0}/docs/assets/logo.svg +0 -0
  48. {yomitoku-0.5.3 → yomitoku-0.6.0}/docs/index.en.md +0 -0
  49. {yomitoku-0.5.3 → yomitoku-0.6.0}/docs/index.ja.md +0 -0
  50. {yomitoku-0.5.3 → yomitoku-0.6.0}/gallery.md +0 -0
  51. {yomitoku-0.5.3 → yomitoku-0.6.0}/mkdocs.yml +0 -0
  52. {yomitoku-0.5.3 → yomitoku-0.6.0}/pytest.ini +0 -0
  53. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/__init__.py +0 -0
  54. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/base.py +0 -0
  55. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/cli/__init__.py +0 -0
  56. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/configs/cfg_layout_parser_rtdtrv2.py +0 -0
  57. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/configs/cfg_table_structure_recognizer_rtdtrv2.py +0 -0
  58. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/configs/cfg_text_detector_dbnet.py +0 -0
  59. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/configs/cfg_text_recognizer_parseq.py +0 -0
  60. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/constants.py +0 -0
  61. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/data/__init__.py +0 -0
  62. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/data/dataset.py +0 -0
  63. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/data/functions.py +0 -0
  64. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/document_analyzer.py +0 -0
  65. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/export/__init__.py +0 -0
  66. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/export/export_csv.py +0 -0
  67. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/export/export_html.py +0 -0
  68. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/export/export_json.py +0 -0
  69. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/export/export_markdown.py +0 -0
  70. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/layout_analyzer.py +0 -0
  71. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/__init__.py +0 -0
  72. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/dbnet_plus.py +0 -0
  73. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/layers/__init__.py +0 -0
  74. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/layers/activate.py +0 -0
  75. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/layers/dbnet_feature_attention.py +0 -0
  76. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/layers/parseq_transformer.py +0 -0
  77. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/models/rtdetr.py +0 -0
  78. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/ocr.py +0 -0
  79. /yomitoku-0.5.3/src/yomitoku/utils/__init__.py → /yomitoku-0.6.0/src/yomitoku/onnx/.gitkeep +0 -0
  80. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/postprocessor/__init__.py +0 -0
  81. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/postprocessor/dbnet_postporcessor.py +0 -0
  82. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/postprocessor/parseq_tokenizer.py +0 -0
  83. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/reading_order.py +0 -0
  84. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/resource/MPLUS1p-Medium.ttf +0 -0
  85. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/resource/charset.txt +0 -0
  86. /yomitoku-0.5.3/tests/data/invalid.jpg → /yomitoku-0.6.0/src/yomitoku/utils/__init__.py +0 -0
  87. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/utils/graph.py +0 -0
  88. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/utils/logger.py +0 -0
  89. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/utils/misc.py +0 -0
  90. {yomitoku-0.5.3 → yomitoku-0.6.0}/src/yomitoku/utils/visualizer.py +0 -0
  91. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/in/demo.jpg +0 -0
  92. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/in/gallery1.jpg +0 -0
  93. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/in/gallery2.jpg +0 -0
  94. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/in/gallery3.jpg +0 -0
  95. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/in/gallery4.jpg +0 -0
  96. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/in/gallery5.jpg +0 -0
  97. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/in/gallery6.jpg +0 -0
  98. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/logo/horizontal.png +0 -0
  99. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/demo_html.png +0 -0
  100. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_demo_p1_figure_0.png +0 -0
  101. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_0.png +0 -0
  102. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_1.png +0 -0
  103. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_10.png +0 -0
  104. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_2.png +0 -0
  105. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_3.png +0 -0
  106. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_4.png +0 -0
  107. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_5.png +0 -0
  108. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_6.png +0 -0
  109. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_7.png +0 -0
  110. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_8.png +0 -0
  111. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery1_p1_figure_9.png +0 -0
  112. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery3_p1_figure_0.png +0 -0
  113. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery3_p1_figure_1.png +0 -0
  114. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery5_p1_figure_0.png +0 -0
  115. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery5_p1_figure_1.png +0 -0
  116. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery6_p1_figure_0.png +0 -0
  117. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/figures/in_gallery6_p1_figure_1.png +0 -0
  118. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_demo_p1.html +0 -0
  119. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_demo_p1.md +0 -0
  120. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_demo_p1_layout.jpg +0 -0
  121. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_demo_p1_ocr.jpg +0 -0
  122. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery1_p1.html +0 -0
  123. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery1_p1.md +0 -0
  124. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery1_p1_layout.jpg +0 -0
  125. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery1_p1_ocr.jpg +0 -0
  126. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery2_p1.html +0 -0
  127. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery2_p1.md +0 -0
  128. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery2_p1_layout.jpg +0 -0
  129. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery2_p1_ocr.jpg +0 -0
  130. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery3_p1.html +0 -0
  131. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery3_p1.md +0 -0
  132. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery3_p1_layout.jpg +0 -0
  133. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery3_p1_ocr.jpg +0 -0
  134. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery4_p1.html +0 -0
  135. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery4_p1.md +0 -0
  136. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery4_p1_layout.jpg +0 -0
  137. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery4_p1_ocr.jpg +0 -0
  138. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery5_p1.html +0 -0
  139. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery5_p1.md +0 -0
  140. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery5_p1_layout.jpg +0 -0
  141. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery5_p1_ocr.jpg +0 -0
  142. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery6_p1.html +0 -0
  143. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery6_p1.md +0 -0
  144. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery6_p1_layout.jpg +0 -0
  145. {yomitoku-0.5.3 → yomitoku-0.6.0}/static/out/in_gallery6_p1_ocr.jpg +0 -0
  146. /yomitoku-0.5.3/tests/data/invalid.pdf → /yomitoku-0.6.0/tests/data/invalid.jpg +0 -0
  147. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/rgba.png +0 -0
  148. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/small.jpg +0 -0
  149. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/subdir/test.jpg +0 -0
  150. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/test.bmp +0 -0
  151. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/test.jpg +0 -0
  152. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/test.pdf +0 -0
  153. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/test.png +0 -0
  154. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/test.tiff +0 -0
  155. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/test.txt +0 -0
  156. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/data/test_gray.jpg +0 -0
  157. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/test_base.py +0 -0
  158. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/test_data.py +0 -0
  159. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/test_document_analyzer.py +0 -0
  160. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/test_export.py +0 -0
  161. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/test_layout_analyzer.py +0 -0
  162. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/test_ocr.py +0 -0
  163. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/yaml/layout_parser.yaml +0 -0
  164. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/yaml/table_structure_recognizer.yaml +0 -0
  165. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/yaml/text_detector.yaml +0 -0
  166. {yomitoku-0.5.3 → yomitoku-0.6.0}/tests/yaml/text_recognizer.yaml +0 -0
@@ -37,4 +37,4 @@ jobs:
37
37
  - name: Run linter
38
38
  run: tox -e lint
39
39
  - name: Run tests
40
- run: tox -p -e py39,py310,py311,py312
40
+ run: tox -p -e py310,py311,py312
@@ -20,4 +20,6 @@ dataset/
20
20
  weights/
21
21
  results/
22
22
 
23
- .coverage*
23
+ .coverage*
24
+
25
+ *.onnx
@@ -0,0 +1 @@
1
+ 3.10
@@ -1,14 +1,17 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: yomitoku
3
- Version: 0.5.3
3
+ Version: 0.6.0
4
4
  Summary: Yomitoku is an AI-powered document image analysis package designed specifically for the Japanese language.
5
5
  Author-email: Kotaro Kinoshita <kotaro.kinoshita@mlism.com>
6
6
  License: CC BY-NC-SA 4.0
7
7
  Keywords: Deep Learning,Japanese,OCR
8
- Requires-Python: <3.13,>=3.9
8
+ Requires-Python: <3.13,>=3.10
9
9
  Requires-Dist: huggingface-hub>=0.26.1
10
10
  Requires-Dist: lxml>=5.3.0
11
11
  Requires-Dist: omegaconf>=2.3.0
12
+ Requires-Dist: onnx>=1.17.0
13
+ Requires-Dist: onnxruntime-gpu>=1.20.1
14
+ Requires-Dist: onnxruntime>=1.20.1
12
15
  Requires-Dist: opencv-python>=4.10.0.84
13
16
  Requires-Dist: pyclipper>=1.3.0.post6
14
17
  Requires-Dist: pydantic>=2.9.2
@@ -23,7 +26,7 @@ Description-Content-Type: text/markdown
23
26
 
24
27
  <img src="static/logo/horizontal.png" width="800px">
25
28
 
26
- ![Python](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12-F9DC3E.svg?logo=python&logoColor=&style=flat)
29
+ ![Python](https://img.shields.io/badge/Python-3.10|3.11|3.12-F9DC3E.svg?logo=python&logoColor=&style=flat)
27
30
  ![Pytorch](https://img.shields.io/badge/Pytorch-2.5-EE4C2C.svg?logo=Pytorch&style=fla)
28
31
  ![CUDA](https://img.shields.io/badge/CUDA->=11.8-76B900.svg?logo=NVIDIA&style=fla)
29
32
  ![OS](https://img.shields.io/badge/OS-Linux|Mac|Win-1793D1.svg?&style=fla)
@@ -69,19 +72,20 @@ Markdown でエクスポートした結果は関してはリポジトリ内の[s
69
72
  pip install yomitoku
70
73
  ```
71
74
 
72
- - pytorch はご自身の CUDAのバージョンにあったものをインストールしてください。デフォルトではCUDA12.4以上に対応したものがインストールされます。
73
- - pytorch は2.5以上のバージョンに対応しています。その関係でCUDA11.8以上のバージョンが必要になります。対応できない場合は、リポジトリ内のDockerfileを利用してください。
75
+ - pytorch はご自身の CUDA のバージョンにあったものをインストールしてください。デフォルトでは CUDA12.4 以上に対応したものがインストールされます。
76
+ - pytorch は 2.5 以上のバージョンに対応しています。その関係で CUDA11.8 以上のバージョンが必要になります。対応できない場合は、リポジトリ内の Dockerfile を利用してください。
74
77
 
75
78
  ## 🚀 実行方法
76
79
 
77
80
  ```
78
- yomitoku ${path_data} -f md -o results -v --figure
81
+ yomitoku ${path_data} -f md -o results -v --figure --lite
79
82
  ```
80
83
 
81
84
  - `${path_data}` 解析対象の画像が含まれたディレクトリか画像ファイルのパスを直接して指定してください。ディレクトリを対象とした場合はディレクトリのサブディレクトリ内の画像も含めて処理を実行します。
82
85
  - `-f`, `--format` 出力形式のファイルフォーマットを指定します。(json, csv, html, md をサポート)
83
86
  - `-o`, `--outdir` 出力先のディレクトリ名を指定します。存在しない場合は新規で作成されます。
84
87
  - `-v`, `--vis` を指定すると解析結果を可視化した画像を出力します。
88
+ - `-l`, `--lite` を指定すると軽量モデルで推論を実行します。通常より高速に推論できますが、若干、精度が低下する可能性があります。
85
89
  - `-d`, `--device` モデルを実行するためのデバイスを指定します。gpu が利用できない場合は cpu で推論が実行されます。(デフォルト: cuda)
86
90
  - `--ignore_line_break` 画像の改行位置を無視して、段落内の文章を連結して返します。(デフォルト:画像通りの改行位置位置で改行します。)
87
91
  - `--figure_letter` 検出した図表に含まれる文字も出力ファイルにエクスポートします。
@@ -94,6 +98,7 @@ yomitoku --help
94
98
  ```
95
99
 
96
100
  **NOTE**
101
+
97
102
  - GPU での実行を推奨します。CPU を用いての推論向けに最適化されておらず、処理時間が長くなります。
98
103
  - 活字のみ識別をサポートしております。手書き文字に関しては、読み取れる場合もありますが、公式にはサポートしておりません。
99
104
  - Yomitoku は文書 OCR 向けに最適化されており、情景 OCR(看板など紙以外にプリントされた文字の読み取り)向けには最適化されていません。
@@ -107,6 +112,6 @@ yomitoku --help
107
112
 
108
113
  本リポジトリ内に格納されているソースコードおよび本プロジェクトに関連する HuggingFaceHub 上のモデルの重みファイルのライセンスは CC BY-NC-SA 4.0 に従います。
109
114
  非商用での個人利用、研究目的での利用はご自由にお使いください。
110
- 商用目的での利用に関しては、別途、商用ライセンスを提供しますので、開発者にお問い合わせください。
115
+ 商用目的での利用に関しては、別途、商用ライセンスを提供しますので、https://www.mlism.com/ にお問い合わせください。
111
116
 
112
117
  YomiToku © 2024 by Kotaro Kinoshita is licensed under CC BY-NC-SA 4.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/4.0/
@@ -2,7 +2,7 @@
2
2
 
3
3
  <img src="static/logo/horizontal.png" width="800px">
4
4
 
5
- ![Python](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12-F9DC3E.svg?logo=python&logoColor=&style=flat)
5
+ ![Python](https://img.shields.io/badge/Python-3.10|3.11|3.12-F9DC3E.svg?logo=python&logoColor=&style=flat)
6
6
  ![Pytorch](https://img.shields.io/badge/Pytorch-2.5-EE4C2C.svg?logo=Pytorch&style=fla)
7
7
  ![CUDA](https://img.shields.io/badge/CUDA->=11.8-76B900.svg?logo=NVIDIA&style=fla)
8
8
  ![OS](https://img.shields.io/badge/OS-Linux|Mac|Win-1793D1.svg?&style=fla)
@@ -48,19 +48,20 @@ Markdown でエクスポートした結果は関してはリポジトリ内の[s
48
48
  pip install yomitoku
49
49
  ```
50
50
 
51
- - pytorch はご自身の CUDAのバージョンにあったものをインストールしてください。デフォルトではCUDA12.4以上に対応したものがインストールされます。
52
- - pytorch は2.5以上のバージョンに対応しています。その関係でCUDA11.8以上のバージョンが必要になります。対応できない場合は、リポジトリ内のDockerfileを利用してください。
51
+ - pytorch はご自身の CUDA のバージョンにあったものをインストールしてください。デフォルトでは CUDA12.4 以上に対応したものがインストールされます。
52
+ - pytorch は 2.5 以上のバージョンに対応しています。その関係で CUDA11.8 以上のバージョンが必要になります。対応できない場合は、リポジトリ内の Dockerfile を利用してください。
53
53
 
54
54
  ## 🚀 実行方法
55
55
 
56
56
  ```
57
- yomitoku ${path_data} -f md -o results -v --figure
57
+ yomitoku ${path_data} -f md -o results -v --figure --lite
58
58
  ```
59
59
 
60
60
  - `${path_data}` 解析対象の画像が含まれたディレクトリか画像ファイルのパスを直接して指定してください。ディレクトリを対象とした場合はディレクトリのサブディレクトリ内の画像も含めて処理を実行します。
61
61
  - `-f`, `--format` 出力形式のファイルフォーマットを指定します。(json, csv, html, md をサポート)
62
62
  - `-o`, `--outdir` 出力先のディレクトリ名を指定します。存在しない場合は新規で作成されます。
63
63
  - `-v`, `--vis` を指定すると解析結果を可視化した画像を出力します。
64
+ - `-l`, `--lite` を指定すると軽量モデルで推論を実行します。通常より高速に推論できますが、若干、精度が低下する可能性があります。
64
65
  - `-d`, `--device` モデルを実行するためのデバイスを指定します。gpu が利用できない場合は cpu で推論が実行されます。(デフォルト: cuda)
65
66
  - `--ignore_line_break` 画像の改行位置を無視して、段落内の文章を連結して返します。(デフォルト:画像通りの改行位置位置で改行します。)
66
67
  - `--figure_letter` 検出した図表に含まれる文字も出力ファイルにエクスポートします。
@@ -73,6 +74,7 @@ yomitoku --help
73
74
  ```
74
75
 
75
76
  **NOTE**
77
+
76
78
  - GPU での実行を推奨します。CPU を用いての推論向けに最適化されておらず、処理時間が長くなります。
77
79
  - 活字のみ識別をサポートしております。手書き文字に関しては、読み取れる場合もありますが、公式にはサポートしておりません。
78
80
  - Yomitoku は文書 OCR 向けに最適化されており、情景 OCR(看板など紙以外にプリントされた文字の読み取り)向けには最適化されていません。
@@ -86,6 +88,6 @@ yomitoku --help
86
88
 
87
89
  本リポジトリ内に格納されているソースコードおよび本プロジェクトに関連する HuggingFaceHub 上のモデルの重みファイルのライセンスは CC BY-NC-SA 4.0 に従います。
88
90
  非商用での個人利用、研究目的での利用はご自由にお使いください。
89
- 商用目的での利用に関しては、別途、商用ライセンスを提供しますので、開発者にお問い合わせください。
91
+ 商用目的での利用に関しては、別途、商用ライセンスを提供しますので、https://www.mlism.com/ にお問い合わせください。
90
92
 
91
93
  YomiToku © 2024 by Kotaro Kinoshita is licensed under CC BY-NC-SA 4.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/4.0/
@@ -2,7 +2,7 @@
2
2
 
3
3
  <img src="static/logo/horizontal.png" width="800px">
4
4
 
5
- ![Python](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12-F9DC3E.svg?logo=python&logoColor=&style=flat)
5
+ ![Python](https://img.shields.io/badge/Python-3.10|3.11|3.12-F9DC3E.svg?logo=python&logoColor=&style=flat)
6
6
  ![Pytorch](https://img.shields.io/badge/Pytorch-2.5-EE4C2C.svg?logo=Pytorch&style=fla)
7
7
  ![CUDA](https://img.shields.io/badge/CUDA->=11.8-76B900.svg?logo=NVIDIA&style=fla)
8
8
  ![OS](https://img.shields.io/badge/OS-Linux|Mac|Win-1793D1.svg?&style=fla)
@@ -63,6 +63,7 @@ yomitoku ${path_data} -f md -o results -v --figure
63
63
  - `-f`, `--format`: Specify the output file format. Supported formats are json, csv, html, and md.
64
64
  - `-o`, `--outdir`: Specify the name of the output directory. If it does not exist, it will be created.
65
65
  - `-v`, `--vis`: If specified, outputs visualized images of the analysis results.
66
+ - `-l`, `--lite`: inference is performed using a lightweight model. This enables fast inference even on a CPU.
66
67
  - `-d`, `--device`: Specify the device for running the model. If a GPU is unavailable, inference will be executed on the CPU. (Default: cuda)
67
68
  - `--ignore_line_break`: Ignores line breaks in the image and concatenates sentences within a paragraph. (Default: respects line breaks as they appear in the image.)
68
69
  - `--figure_letter`: Exports characters contained within detected figures and tables to the output file.
@@ -0,0 +1,67 @@
1
+ hf_hub_repo: KotaroKinoshita/yomitoku-table-structure-recognizer-rtdtrv2-open-beta
2
+ thresh_score: 0.4
3
+ data:
4
+ img_size:
5
+ - 640
6
+ - 640
7
+ PResNet:
8
+ depth: 50
9
+ variant: d
10
+ freeze_at: 0
11
+ return_idx:
12
+ - 1
13
+ - 2
14
+ - 3
15
+ num_stages: 4
16
+ freeze_norm: true
17
+ HybridEncoder:
18
+ in_channels:
19
+ - 512
20
+ - 1024
21
+ - 2048
22
+ feat_strides:
23
+ - 8
24
+ - 16
25
+ - 32
26
+ hidden_dim: 256
27
+ use_encoder_idx:
28
+ - 2
29
+ num_encoder_layers: 1
30
+ nhead: 8
31
+ dim_feedforward: 1024
32
+ dropout: 0.0
33
+ enc_act: gelu
34
+ expansion: 1.0
35
+ depth_mult: 1
36
+ act: silu
37
+ RTDETRTransformerv2:
38
+ num_classes: 3
39
+ feat_channels:
40
+ - 256
41
+ - 256
42
+ - 256
43
+ feat_strides:
44
+ - 8
45
+ - 16
46
+ - 32
47
+ hidden_dim: 256
48
+ num_levels: 3
49
+ num_layers: 6
50
+ num_queries: 300
51
+ num_denoising: 100
52
+ label_noise_ratio: 0.5
53
+ box_noise_scale: 1.0
54
+ eval_spatial_size:
55
+ - 640
56
+ - 640
57
+ eval_idx: -1
58
+ num_points:
59
+ - 4
60
+ - 4
61
+ - 4
62
+ cross_attn_method: default
63
+ query_select_method: default
64
+ category:
65
+ - row
66
+ - col
67
+ - span
@@ -0,0 +1,32 @@
1
+ hf_hub_repo: KotaroKinoshita/yomitoku-text-recognizer-parseq-open-beta
2
+ charset: /home/kinoshita/Projects/know-how/yomitoku/src/yomitoku/resource/charset.txt
3
+ num_tokens: 7312
4
+ max_label_length: 100
5
+ decode_ar: 1
6
+ refine_iters: 1
7
+ data:
8
+ num_workers: 4
9
+ batch_size: 128
10
+ img_size:
11
+ - 32
12
+ - 800
13
+ encoder:
14
+ patch_size:
15
+ - 8
16
+ - 8
17
+ num_heads: 8
18
+ embed_dim: 512
19
+ mlp_ratio: 4
20
+ depth: 12
21
+ decoder:
22
+ embed_dim: 512
23
+ num_heads: 8
24
+ mlp_ratio: 4
25
+ depth: 1
26
+ visualize:
27
+ font: /home/kinoshita/Projects/know-how/yomitoku/src/yomitoku/resource/MPLUS1p-Medium.ttf
28
+ color:
29
+ - 0
30
+ - 0
31
+ - 255
32
+ font_size: 18
@@ -1,7 +1,7 @@
1
1
  # Installation
2
2
 
3
3
 
4
- This package requires Python 3.9 or later and PyTorch 2.5 or later for execution. PyTorch must be installed according to your CUDA version. A GPU with more than 8GB of VRAM is recommended. While it can run on a CPU, please note that the processing is not currently optimized for CPUs, which may result in longer execution times.
4
+ This package requires Python 3.10 or later and PyTorch 2.5 or later for execution. PyTorch must be installed according to your CUDA version. A GPU with more than 8GB of VRAM is recommended. While it can run on a CPU, please note that the processing is not currently optimized for CPUs, which may result in longer execution times.
5
5
 
6
6
  ## from PYPI
7
7
 
@@ -1,6 +1,6 @@
1
1
  # Installation
2
2
 
3
- 本パッケージは Python3.9+, Pytorch が実行に必要です。Pytorch はご自身の環境に合わせて、インストールが必要です。計算機は GPU(> VRAM 8G)を推奨しています。CPU でも動作しますが、現在、CPU 向けに処理が最適化されておらず、実行に時間がかかりますのでご注意ください。
3
+ 本パッケージは Python3.10+, Pytorch が実行に必要です。Pytorch はご自身の環境に合わせて、インストールが必要です。計算機は GPU(> VRAM 8G)を推奨しています。CPU でも動作しますが、現在、CPU 向けに処理が最適化されておらず、実行に時間がかかりますのでご注意ください。
4
4
 
5
5
  ## PYPI からインストール
6
6
 
@@ -12,6 +12,7 @@ yomitoku ${path_data} -f md -o results -v
12
12
  - `-f`, `--format`: Specify the output file format. Supported formats are json, csv, html, and md.
13
13
  - `-o`, `--outdir`: Specify the name of the output directory. If it does not exist, it will be created.
14
14
  - `-v`, `--vis`: If specified, outputs visualized images of the analysis results.
15
+ - `-l`, `--lite`: inference is performed using a lightweight model. This enables fast inference even on a CPU.
15
16
  - `-d`, `--device`: Specify the device for running the model. If a GPU is unavailable, inference will be executed on the CPU. (Default: cuda)
16
17
  - `--ignore_line_break`: Ignores line breaks in the image and concatenates sentences within a paragraph. (Default: respects line breaks as they appear in the image.)
17
18
  - `--figure_letter`: Exports characters contained within detected figures and tables to the output file.
@@ -10,6 +10,7 @@ yomitoku ${path_data} -f md -o results -v
10
10
 
11
11
  - `${path_data}` 解析対象の画像が含まれたディレクトリか画像ファイルのパスを直接して指定してください。かディレクトリを対象とした場合はディレクトリのサブディレクトリ内の画像も含めて処理を実行します。入力をサポートしているファイル形式は jpeg, png, bmp, tiff, pdf です。
12
12
  - `-f` 出力形式のファイルフォーマットを指定します。(json, csv, html, md をサポート)
13
+ - `-l` 指定すると軽量モデルで推論を実行します。CPUでも高速に推論可能です。
13
14
  - `-o` 出力先のディレクトリ名を指定します。存在しない場合は新規で作成されます。
14
15
  - `-v` を指定すると解析結果を可視化した画像を出力します。
15
16
  - `-d` モデルを実行するためのデバイスを指定します。gpu が利用できない場合は cpu で推論が実行されます。(デフォルト: cuda)
@@ -12,7 +12,7 @@ authors = [{name = "Kotaro Kinoshita", email = "kotaro.kinoshita@mlism.com"}]
12
12
  description = "Yomitoku is an AI-powered document image analysis package designed specifically for the Japanese language."
13
13
  readme = "README.md"
14
14
  license = {text = "CC BY-NC-SA 4.0"}
15
- requires-python = ">=3.9,<3.13"
15
+ requires-python = ">=3.10,<3.13"
16
16
  keywords = ["Japanese", "OCR", "Deep Learning"]
17
17
  dependencies = [
18
18
  "huggingface-hub>=0.26.1",
@@ -26,6 +26,9 @@ dependencies = [
26
26
  "torchvision>=0.20.0",
27
27
  "torch>=2.5.0",
28
28
  "pypdfium2>=4.30.0",
29
+ "onnx>=1.17.0",
30
+ "onnxruntime>=1.20.1",
31
+ "onnxruntime-gpu>=1.20.1",
29
32
  ]
30
33
 
31
34
  [tool.uv-dynamic-versioning]
@@ -71,7 +74,7 @@ yomitoku = "yomitoku.cli.main:main"
71
74
  [tool.tox]
72
75
  legacy_tox_ini = """
73
76
  [tox]
74
- envlist = lint, py39, py310, py311, py312, docs
77
+ envlist = lint, py310, py311, py312, docs
75
78
 
76
79
  [testenv]
77
80
  deps = pytest
@@ -14,7 +14,7 @@ def get_module(module_name):
14
14
  return module
15
15
 
16
16
  elif module_name == "text_recognizer":
17
- module = TextRecognizer(from_pretrained=False)
17
+ module = TextRecognizer(from_pretrained=False, model_name="parseq-small")
18
18
  return module
19
19
 
20
20
  elif module_name == "layout_parser":
@@ -104,6 +104,12 @@ def main():
104
104
  default="results",
105
105
  help="output directory",
106
106
  )
107
+ parser.add_argument(
108
+ "-l",
109
+ "--lite",
110
+ action="store_true",
111
+ help="if set, use lite model",
112
+ )
107
113
  parser.add_argument(
108
114
  "-d",
109
115
  "--device",
@@ -197,6 +203,15 @@ def main():
197
203
  },
198
204
  }
199
205
 
206
+ if args.lite:
207
+ configs["ocr"]["text_recognizer"]["model_name"] = "parseq-small"
208
+ configs["ocr"]["text_detector"]["infer_onnx"] = True
209
+
210
+ # Note: Text Detector以外はONNX推論よりもPyTorch推論の方が速いため、ONNX推論は行わない
211
+ # configs["ocr"]["text_recognizer"]["infer_onnx"] = True
212
+ # configs["layout_analyzer"]["table_structure_recognizer"]["infer_onnx"] = True
213
+ # configs["layout_analyzer"]["layout_parser"]["infer_onnx"] = True
214
+
200
215
  analyzer = DocumentAnalyzer(
201
216
  configs=configs,
202
217
  visualize=args.vis,
@@ -4,10 +4,12 @@ from .cfg_table_structure_recognizer_rtdtrv2 import (
4
4
  )
5
5
  from .cfg_text_detector_dbnet import TextDetectorDBNetConfig
6
6
  from .cfg_text_recognizer_parseq import TextRecognizerPARSeqConfig
7
+ from .cfg_text_recognizer_parseq_small import TextRecognizerPARSeqSmallConfig
7
8
 
8
9
  __all__ = [
9
10
  "TextDetectorDBNetConfig",
10
11
  "TextRecognizerPARSeqConfig",
11
12
  "LayoutParserRTDETRv2Config",
12
13
  "TableStructureRecognizerRTDETRv2Config",
14
+ "TextRecognizerPARSeqSmallConfig",
13
15
  ]
@@ -0,0 +1,51 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import List
3
+
4
+ from ..constants import ROOT_DIR
5
+
6
+
7
+ @dataclass
8
+ class Data:
9
+ num_workers: int = 4
10
+ batch_size: int = 128
11
+ img_size: List[int] = field(default_factory=lambda: [32, 800])
12
+
13
+
14
+ @dataclass
15
+ class Encoder:
16
+ patch_size: List[int] = field(default_factory=lambda: [16, 16])
17
+ num_heads: int = 8
18
+ embed_dim: int = 384
19
+ mlp_ratio: int = 4
20
+ depth: int = 9
21
+
22
+
23
+ @dataclass
24
+ class Decoder:
25
+ embed_dim: int = 384
26
+ num_heads: int = 8
27
+ mlp_ratio: int = 4
28
+ depth: int = 1
29
+
30
+
31
+ @dataclass
32
+ class Visualize:
33
+ font: str = str(ROOT_DIR + "/resource/MPLUS1p-Medium.ttf")
34
+ color: List[int] = field(default_factory=lambda: [0, 0, 255]) # RGB
35
+ font_size: int = 18
36
+
37
+
38
+ @dataclass
39
+ class TextRecognizerPARSeqSmallConfig:
40
+ hf_hub_repo: str = "KotaroKinoshita/yomitoku-text-recognizer-parseq-small-open-beta"
41
+ charset: str = str(ROOT_DIR + "/resource/charset.txt")
42
+ num_tokens: int = 7312
43
+ max_label_length: int = 100
44
+ decode_ar: int = 1
45
+ refine_iters: int = 1
46
+
47
+ data: Data = field(default_factory=Data)
48
+ encoder: Encoder = field(default_factory=Encoder)
49
+ decoder: Decoder = field(default_factory=Decoder)
50
+
51
+ visualize: Visualize = field(default_factory=Visualize)
@@ -1,11 +1,16 @@
1
1
  from typing import List, Union
2
2
 
3
3
  import cv2
4
+ import os
5
+ import onnx
6
+ import onnxruntime
4
7
  import torch
5
8
  import torchvision.transforms as T
6
9
  from PIL import Image
7
10
  from pydantic import conlist
8
11
 
12
+ from .constants import ROOT_DIR
13
+
9
14
  from .base import BaseModelCatalog, BaseModule, BaseSchema
10
15
  from .configs import LayoutParserRTDETRv2Config
11
16
  from .models import RTDETRv2
@@ -91,6 +96,7 @@ class LayoutParser(BaseModule):
91
96
  device="cuda",
92
97
  visualize=False,
93
98
  from_pretrained=True,
99
+ infer_onnx=False,
94
100
  ):
95
101
  super().__init__()
96
102
  self.load_model(model_name, path_cfg, from_pretrained)
@@ -119,11 +125,44 @@ class LayoutParser(BaseModule):
119
125
  }
120
126
 
121
127
  self.role = self._cfg.role
128
+ self.infer_onnx = infer_onnx
129
+ if infer_onnx:
130
+ name = self._cfg.hf_hub_repo.split("/")[-1]
131
+ path_onnx = f"{ROOT_DIR}/onnx/{name}.onnx"
132
+ if not os.path.exists(path_onnx):
133
+ self.convert_onnx(path_onnx)
134
+
135
+ model = onnx.load(path_onnx)
136
+ if torch.cuda.is_available() and device == "cuda":
137
+ self.sess = onnxruntime.InferenceSession(
138
+ model.SerializeToString(), providers=["CUDAExecutionProvider"]
139
+ )
140
+ else:
141
+ self.sess = onnxruntime.InferenceSession(model.SerializeToString())
142
+
143
+ def convert_onnx(self, path_onnx):
144
+ dynamic_axes = {
145
+ "input": {0: "batch_size"},
146
+ "output": {0: "batch_size"},
147
+ }
148
+
149
+ img_size = self._cfg.data.img_size
150
+ dummy_input = torch.randn(1, 3, *img_size, requires_grad=True)
151
+
152
+ torch.onnx.export(
153
+ self.model,
154
+ dummy_input,
155
+ path_onnx,
156
+ opset_version=16,
157
+ input_names=["input"],
158
+ output_names=["pred_logits", "pred_boxes"],
159
+ dynamic_axes=dynamic_axes,
160
+ )
122
161
 
123
162
  def preprocess(self, img):
124
163
  cv_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
125
164
  img = Image.fromarray(cv_img)
126
- img_tensor = self.transforms(img)[None].to(self.device)
165
+ img_tensor = self.transforms(img)[None]
127
166
  return img_tensor
128
167
 
129
168
  def postprocess(self, preds, image_size):
@@ -175,8 +214,19 @@ class LayoutParser(BaseModule):
175
214
  ori_h, ori_w = img.shape[:2]
176
215
  img_tensor = self.preprocess(img)
177
216
 
178
- with torch.inference_mode():
179
- preds = self.model(img_tensor)
217
+ if self.infer_onnx:
218
+ input = img_tensor.numpy()
219
+ results = self.sess.run(None, {"input": input})
220
+ preds = {
221
+ "pred_logits": torch.tensor(results[0]).to(self.device),
222
+ "pred_boxes": torch.tensor(results[1]).to(self.device),
223
+ }
224
+
225
+ else:
226
+ with torch.inference_mode():
227
+ img_tensor = img_tensor.to(self.device)
228
+ preds = self.model(img_tensor)
229
+
180
230
  results = self.postprocess(preds, (ori_h, ori_w))
181
231
 
182
232
  vis = None
@@ -59,9 +59,7 @@ class ConvNormLayer(nn.Module):
59
59
  class BasicBlock(nn.Module):
60
60
  expansion = 1
61
61
 
62
- def __init__(
63
- self, ch_in, ch_out, stride, shortcut, act="relu", variant="b"
64
- ):
62
+ def __init__(self, ch_in, ch_out, stride, shortcut, act="relu", variant="b"):
65
63
  super().__init__()
66
64
 
67
65
  self.shortcut = shortcut
@@ -100,9 +98,7 @@ class BasicBlock(nn.Module):
100
98
  class BottleNeck(nn.Module):
101
99
  expansion = 4
102
100
 
103
- def __init__(
104
- self, ch_in, ch_out, stride, shortcut, act="relu", variant="b"
105
- ):
101
+ def __init__(self, ch_in, ch_out, stride, shortcut, act="relu", variant="b"):
106
102
  super().__init__()
107
103
 
108
104
  if variant == "a":
@@ -125,17 +121,13 @@ class BottleNeck(nn.Module):
125
121
  ("pool", nn.AvgPool2d(2, 2, 0, ceil_mode=True)),
126
122
  (
127
123
  "conv",
128
- ConvNormLayer(
129
- ch_in, ch_out * self.expansion, 1, 1
130
- ),
124
+ ConvNormLayer(ch_in, ch_out * self.expansion, 1, 1),
131
125
  ),
132
126
  ]
133
127
  )
134
128
  )
135
129
  else:
136
- self.short = ConvNormLayer(
137
- ch_in, ch_out * self.expansion, 1, stride
138
- )
130
+ self.short = ConvNormLayer(ch_in, ch_out * self.expansion, 1, stride)
139
131
 
140
132
  self.act = nn.Identity() if act is None else get_activation(act)
141
133
 
@@ -156,9 +148,7 @@ class BottleNeck(nn.Module):
156
148
 
157
149
 
158
150
  class Blocks(nn.Module):
159
- def __init__(
160
- self, block, ch_in, ch_out, count, stage_num, act="relu", variant="b"
161
- ):
151
+ def __init__(self, block, ch_in, ch_out, count, stage_num, act="relu", variant="b"):
162
152
  super().__init__()
163
153
 
164
154
  self.blocks = nn.ModuleList()
@@ -252,9 +252,7 @@ class HybridEncoder(nn.Module):
252
252
  for in_channel in in_channels:
253
253
  if version == "v1":
254
254
  proj = nn.Sequential(
255
- nn.Conv2d(
256
- in_channel, hidden_dim, kernel_size=1, bias=False
257
- ),
255
+ nn.Conv2d(in_channel, hidden_dim, kernel_size=1, bias=False),
258
256
  nn.BatchNorm2d(hidden_dim),
259
257
  )
260
258
  elif version == "v2":
@@ -290,9 +288,7 @@ class HybridEncoder(nn.Module):
290
288
 
291
289
  self.encoder = nn.ModuleList(
292
290
  [
293
- TransformerEncoder(
294
- copy.deepcopy(encoder_layer), num_encoder_layers
295
- )
291
+ TransformerEncoder(copy.deepcopy(encoder_layer), num_encoder_layers)
296
292
  for _ in range(len(use_encoder_idx))
297
293
  ]
298
294
  )
@@ -347,9 +343,7 @@ class HybridEncoder(nn.Module):
347
343
  # self.register_buffer(f'pos_embed{idx}', pos_embed)
348
344
 
349
345
  @staticmethod
350
- def build_2d_sincos_position_embedding(
351
- w, h, embed_dim=256, temperature=10000.0
352
- ):
346
+ def build_2d_sincos_position_embedding(w, h, embed_dim=256, temperature=10000.0):
353
347
  """ """
354
348
  grid_w = torch.arange(int(w), dtype=torch.float32)
355
349
  grid_h = torch.arange(int(h), dtype=torch.float32)
@@ -387,9 +381,7 @@ class HybridEncoder(nn.Module):
387
381
  src_flatten.device
388
382
  )
389
383
 
390
- memory: torch.Tensor = self.encoder[i](
391
- src_flatten, pos_embed=pos_embed
392
- )
384
+ memory: torch.Tensor = self.encoder[i](src_flatten, pos_embed=pos_embed)
393
385
  proj_feats[enc_ind] = (
394
386
  memory.permute(0, 2, 1)
395
387
  .reshape(-1, self.hidden_dim, h, w)
@@ -401,13 +393,9 @@ class HybridEncoder(nn.Module):
401
393
  for idx in range(len(self.in_channels) - 1, 0, -1):
402
394
  feat_heigh = inner_outs[0]
403
395
  feat_low = proj_feats[idx - 1]
404
- feat_heigh = self.lateral_convs[len(self.in_channels) - 1 - idx](
405
- feat_heigh
406
- )
396
+ feat_heigh = self.lateral_convs[len(self.in_channels) - 1 - idx](feat_heigh)
407
397
  inner_outs[0] = feat_heigh
408
- upsample_feat = F.interpolate(
409
- feat_heigh, scale_factor=2.0, mode="nearest"
410
- )
398
+ upsample_feat = F.interpolate(feat_heigh, scale_factor=2.0, mode="nearest")
411
399
  inner_out = self.fpn_blocks[len(self.in_channels) - 1 - idx](
412
400
  torch.concat([upsample_feat, feat_low], dim=1)
413
401
  )