pyxllib 0.3.96__py3-none-any.whl → 0.3.200__py3-none-any.whl

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 (358) hide show
  1. pyxllib/__init__.py +21 -21
  2. pyxllib/algo/__init__.py +8 -8
  3. pyxllib/algo/disjoint.py +54 -54
  4. pyxllib/algo/geo.py +541 -529
  5. pyxllib/algo/intervals.py +964 -964
  6. pyxllib/algo/matcher.py +389 -311
  7. pyxllib/algo/newbie.py +166 -166
  8. pyxllib/algo/pupil.py +629 -461
  9. pyxllib/algo/shapelylib.py +67 -67
  10. pyxllib/algo/specialist.py +241 -240
  11. pyxllib/algo/stat.py +494 -458
  12. pyxllib/algo/treelib.py +149 -149
  13. pyxllib/algo/unitlib.py +66 -66
  14. {pyxlpr → pyxllib/autogui}/__init__.py +5 -5
  15. pyxllib/autogui/activewin.py +246 -0
  16. pyxllib/autogui/all.py +9 -0
  17. pyxllib/{ext/autogui → autogui}/autogui.py +852 -823
  18. pyxllib/autogui/uiautolib.py +362 -0
  19. pyxllib/{ext/autogui → autogui}/virtualkey.py +102 -102
  20. pyxllib/autogui/wechat.py +827 -0
  21. pyxllib/autogui/wechat_msg.py +421 -0
  22. pyxllib/autogui/wxautolib.py +84 -0
  23. pyxllib/cv/__init__.py +5 -5
  24. pyxllib/cv/expert.py +267 -267
  25. pyxllib/cv/imfile.py +159 -159
  26. pyxllib/cv/imhash.py +39 -39
  27. pyxllib/cv/pupil.py +9 -9
  28. pyxllib/cv/rgbfmt.py +1525 -1525
  29. pyxllib/cv/slidercaptcha.py +137 -0
  30. pyxllib/cv/trackbartools.py +251 -251
  31. pyxllib/cv/xlcvlib.py +1040 -1040
  32. pyxllib/cv/xlpillib.py +423 -423
  33. pyxllib/data/echarts.py +240 -129
  34. pyxllib/data/jsonlib.py +89 -0
  35. pyxllib/data/oss.py +72 -72
  36. pyxllib/data/pglib.py +1127 -643
  37. pyxllib/data/sqlite.py +568 -341
  38. pyxllib/data/sqllib.py +297 -297
  39. pyxllib/ext/JLineViewer.py +505 -492
  40. pyxllib/ext/__init__.py +6 -6
  41. pyxllib/ext/demolib.py +246 -246
  42. pyxllib/ext/drissionlib.py +277 -0
  43. pyxllib/ext/kq5034lib.py +12 -1606
  44. pyxllib/ext/old.py +663 -663
  45. pyxllib/ext/qt.py +449 -449
  46. pyxllib/ext/robustprocfile.py +497 -0
  47. pyxllib/ext/seleniumlib.py +76 -76
  48. pyxllib/ext/tk.py +173 -173
  49. pyxllib/ext/unixlib.py +827 -826
  50. pyxllib/ext/utools.py +351 -338
  51. pyxllib/ext/webhook.py +124 -101
  52. pyxllib/ext/win32lib.py +40 -40
  53. pyxllib/ext/wjxlib.py +88 -0
  54. pyxllib/ext/wpsapi.py +124 -0
  55. pyxllib/ext/xlwork.py +9 -0
  56. pyxllib/ext/yuquelib.py +1105 -173
  57. pyxllib/file/__init__.py +17 -17
  58. pyxllib/file/docxlib.py +761 -761
  59. pyxllib/file/gitlib.py +309 -309
  60. pyxllib/file/libreoffice.py +165 -0
  61. pyxllib/file/movielib.py +148 -139
  62. pyxllib/file/newbie.py +10 -10
  63. pyxllib/file/onenotelib.py +1469 -1469
  64. pyxllib/file/packlib/__init__.py +330 -293
  65. pyxllib/file/packlib/zipfile.py +2441 -2441
  66. pyxllib/file/pdflib.py +426 -426
  67. pyxllib/file/pupil.py +185 -185
  68. pyxllib/file/specialist/__init__.py +685 -685
  69. pyxllib/file/specialist/dirlib.py +799 -799
  70. pyxllib/file/specialist/download.py +193 -186
  71. pyxllib/file/specialist/filelib.py +2829 -2618
  72. pyxllib/file/xlsxlib.py +3131 -2976
  73. pyxllib/file/xlsyncfile.py +341 -0
  74. pyxllib/prog/__init__.py +5 -5
  75. pyxllib/prog/cachetools.py +64 -0
  76. pyxllib/prog/deprecatedlib.py +233 -233
  77. pyxllib/prog/filelock.py +42 -0
  78. pyxllib/prog/ipyexec.py +253 -253
  79. pyxllib/prog/multiprogs.py +940 -0
  80. pyxllib/prog/newbie.py +451 -444
  81. pyxllib/prog/pupil.py +1197 -1128
  82. pyxllib/prog/sitepackages.py +33 -33
  83. pyxllib/prog/specialist/__init__.py +391 -217
  84. pyxllib/prog/specialist/bc.py +203 -200
  85. pyxllib/prog/specialist/browser.py +497 -488
  86. pyxllib/prog/specialist/common.py +347 -347
  87. pyxllib/prog/specialist/datetime.py +199 -131
  88. pyxllib/prog/specialist/tictoc.py +240 -241
  89. pyxllib/prog/specialist/xllog.py +180 -180
  90. pyxllib/prog/xlosenv.py +108 -101
  91. pyxllib/stdlib/__init__.py +17 -17
  92. pyxllib/stdlib/tablepyxl/__init__.py +10 -10
  93. pyxllib/stdlib/tablepyxl/style.py +303 -303
  94. pyxllib/stdlib/tablepyxl/tablepyxl.py +130 -130
  95. pyxllib/text/__init__.py +8 -8
  96. pyxllib/text/ahocorasick.py +39 -39
  97. pyxllib/text/airscript.js +744 -0
  98. pyxllib/text/charclasslib.py +121 -109
  99. pyxllib/text/jiebalib.py +267 -264
  100. pyxllib/text/jinjalib.py +32 -0
  101. pyxllib/text/jsa_ai_prompt.md +271 -0
  102. pyxllib/text/jscode.py +922 -767
  103. pyxllib/text/latex/__init__.py +158 -158
  104. pyxllib/text/levenshtein.py +303 -303
  105. pyxllib/text/nestenv.py +1215 -1215
  106. pyxllib/text/newbie.py +300 -288
  107. pyxllib/text/pupil/__init__.py +8 -8
  108. pyxllib/text/pupil/common.py +1121 -1095
  109. pyxllib/text/pupil/xlalign.py +326 -326
  110. pyxllib/text/pycode.py +47 -47
  111. pyxllib/text/specialist/__init__.py +8 -8
  112. pyxllib/text/specialist/common.py +112 -112
  113. pyxllib/text/specialist/ptag.py +186 -186
  114. pyxllib/text/spellchecker.py +172 -172
  115. pyxllib/text/templates/echart_base.html +11 -0
  116. pyxllib/text/templates/highlight_code.html +17 -0
  117. pyxllib/text/templates/latex_editor.html +103 -0
  118. pyxllib/text/vbacode.py +17 -17
  119. pyxllib/text/xmllib.py +747 -685
  120. pyxllib/xl.py +42 -38
  121. pyxllib/xlcv.py +17 -17
  122. pyxllib-0.3.200.dist-info/METADATA +48 -0
  123. pyxllib-0.3.200.dist-info/RECORD +126 -0
  124. {pyxllib-0.3.96.dist-info → pyxllib-0.3.200.dist-info}/WHEEL +1 -2
  125. {pyxllib-0.3.96.dist-info → pyxllib-0.3.200.dist-info/licenses}/LICENSE +190 -190
  126. pyxllib/ext/autogui/__init__.py +0 -8
  127. pyxllib-0.3.96.dist-info/METADATA +0 -51
  128. pyxllib-0.3.96.dist-info/RECORD +0 -333
  129. pyxllib-0.3.96.dist-info/top_level.txt +0 -2
  130. pyxlpr/ai/__init__.py +0 -5
  131. pyxlpr/ai/clientlib.py +0 -1281
  132. pyxlpr/ai/specialist.py +0 -286
  133. pyxlpr/ai/torch_app.py +0 -172
  134. pyxlpr/ai/xlpaddle.py +0 -655
  135. pyxlpr/ai/xltorch.py +0 -705
  136. pyxlpr/data/__init__.py +0 -11
  137. pyxlpr/data/coco.py +0 -1325
  138. pyxlpr/data/datacls.py +0 -365
  139. pyxlpr/data/datasets.py +0 -200
  140. pyxlpr/data/gptlib.py +0 -1291
  141. pyxlpr/data/icdar/__init__.py +0 -96
  142. pyxlpr/data/icdar/deteval.py +0 -377
  143. pyxlpr/data/icdar/icdar2013.py +0 -341
  144. pyxlpr/data/icdar/iou.py +0 -340
  145. pyxlpr/data/icdar/rrc_evaluation_funcs_1_1.py +0 -463
  146. pyxlpr/data/imtextline.py +0 -473
  147. pyxlpr/data/labelme.py +0 -866
  148. pyxlpr/data/removeline.py +0 -179
  149. pyxlpr/data/specialist.py +0 -57
  150. pyxlpr/eval/__init__.py +0 -85
  151. pyxlpr/paddleocr.py +0 -776
  152. pyxlpr/ppocr/__init__.py +0 -15
  153. pyxlpr/ppocr/configs/rec/multi_language/generate_multi_language_configs.py +0 -226
  154. pyxlpr/ppocr/data/__init__.py +0 -135
  155. pyxlpr/ppocr/data/imaug/ColorJitter.py +0 -26
  156. pyxlpr/ppocr/data/imaug/__init__.py +0 -67
  157. pyxlpr/ppocr/data/imaug/copy_paste.py +0 -170
  158. pyxlpr/ppocr/data/imaug/east_process.py +0 -437
  159. pyxlpr/ppocr/data/imaug/gen_table_mask.py +0 -244
  160. pyxlpr/ppocr/data/imaug/iaa_augment.py +0 -114
  161. pyxlpr/ppocr/data/imaug/label_ops.py +0 -789
  162. pyxlpr/ppocr/data/imaug/make_border_map.py +0 -184
  163. pyxlpr/ppocr/data/imaug/make_pse_gt.py +0 -106
  164. pyxlpr/ppocr/data/imaug/make_shrink_map.py +0 -126
  165. pyxlpr/ppocr/data/imaug/operators.py +0 -433
  166. pyxlpr/ppocr/data/imaug/pg_process.py +0 -906
  167. pyxlpr/ppocr/data/imaug/randaugment.py +0 -143
  168. pyxlpr/ppocr/data/imaug/random_crop_data.py +0 -239
  169. pyxlpr/ppocr/data/imaug/rec_img_aug.py +0 -533
  170. pyxlpr/ppocr/data/imaug/sast_process.py +0 -777
  171. pyxlpr/ppocr/data/imaug/text_image_aug/__init__.py +0 -17
  172. pyxlpr/ppocr/data/imaug/text_image_aug/augment.py +0 -120
  173. pyxlpr/ppocr/data/imaug/text_image_aug/warp_mls.py +0 -168
  174. pyxlpr/ppocr/data/lmdb_dataset.py +0 -115
  175. pyxlpr/ppocr/data/pgnet_dataset.py +0 -104
  176. pyxlpr/ppocr/data/pubtab_dataset.py +0 -107
  177. pyxlpr/ppocr/data/simple_dataset.py +0 -372
  178. pyxlpr/ppocr/losses/__init__.py +0 -61
  179. pyxlpr/ppocr/losses/ace_loss.py +0 -52
  180. pyxlpr/ppocr/losses/basic_loss.py +0 -135
  181. pyxlpr/ppocr/losses/center_loss.py +0 -88
  182. pyxlpr/ppocr/losses/cls_loss.py +0 -30
  183. pyxlpr/ppocr/losses/combined_loss.py +0 -67
  184. pyxlpr/ppocr/losses/det_basic_loss.py +0 -208
  185. pyxlpr/ppocr/losses/det_db_loss.py +0 -80
  186. pyxlpr/ppocr/losses/det_east_loss.py +0 -63
  187. pyxlpr/ppocr/losses/det_pse_loss.py +0 -149
  188. pyxlpr/ppocr/losses/det_sast_loss.py +0 -121
  189. pyxlpr/ppocr/losses/distillation_loss.py +0 -272
  190. pyxlpr/ppocr/losses/e2e_pg_loss.py +0 -140
  191. pyxlpr/ppocr/losses/kie_sdmgr_loss.py +0 -113
  192. pyxlpr/ppocr/losses/rec_aster_loss.py +0 -99
  193. pyxlpr/ppocr/losses/rec_att_loss.py +0 -39
  194. pyxlpr/ppocr/losses/rec_ctc_loss.py +0 -44
  195. pyxlpr/ppocr/losses/rec_enhanced_ctc_loss.py +0 -70
  196. pyxlpr/ppocr/losses/rec_nrtr_loss.py +0 -30
  197. pyxlpr/ppocr/losses/rec_sar_loss.py +0 -28
  198. pyxlpr/ppocr/losses/rec_srn_loss.py +0 -47
  199. pyxlpr/ppocr/losses/table_att_loss.py +0 -109
  200. pyxlpr/ppocr/metrics/__init__.py +0 -44
  201. pyxlpr/ppocr/metrics/cls_metric.py +0 -45
  202. pyxlpr/ppocr/metrics/det_metric.py +0 -82
  203. pyxlpr/ppocr/metrics/distillation_metric.py +0 -73
  204. pyxlpr/ppocr/metrics/e2e_metric.py +0 -86
  205. pyxlpr/ppocr/metrics/eval_det_iou.py +0 -274
  206. pyxlpr/ppocr/metrics/kie_metric.py +0 -70
  207. pyxlpr/ppocr/metrics/rec_metric.py +0 -75
  208. pyxlpr/ppocr/metrics/table_metric.py +0 -50
  209. pyxlpr/ppocr/modeling/architectures/__init__.py +0 -32
  210. pyxlpr/ppocr/modeling/architectures/base_model.py +0 -88
  211. pyxlpr/ppocr/modeling/architectures/distillation_model.py +0 -60
  212. pyxlpr/ppocr/modeling/backbones/__init__.py +0 -54
  213. pyxlpr/ppocr/modeling/backbones/det_mobilenet_v3.py +0 -268
  214. pyxlpr/ppocr/modeling/backbones/det_resnet_vd.py +0 -246
  215. pyxlpr/ppocr/modeling/backbones/det_resnet_vd_sast.py +0 -285
  216. pyxlpr/ppocr/modeling/backbones/e2e_resnet_vd_pg.py +0 -265
  217. pyxlpr/ppocr/modeling/backbones/kie_unet_sdmgr.py +0 -186
  218. pyxlpr/ppocr/modeling/backbones/rec_mobilenet_v3.py +0 -138
  219. pyxlpr/ppocr/modeling/backbones/rec_mv1_enhance.py +0 -258
  220. pyxlpr/ppocr/modeling/backbones/rec_nrtr_mtb.py +0 -48
  221. pyxlpr/ppocr/modeling/backbones/rec_resnet_31.py +0 -210
  222. pyxlpr/ppocr/modeling/backbones/rec_resnet_aster.py +0 -143
  223. pyxlpr/ppocr/modeling/backbones/rec_resnet_fpn.py +0 -307
  224. pyxlpr/ppocr/modeling/backbones/rec_resnet_vd.py +0 -286
  225. pyxlpr/ppocr/modeling/heads/__init__.py +0 -54
  226. pyxlpr/ppocr/modeling/heads/cls_head.py +0 -52
  227. pyxlpr/ppocr/modeling/heads/det_db_head.py +0 -118
  228. pyxlpr/ppocr/modeling/heads/det_east_head.py +0 -121
  229. pyxlpr/ppocr/modeling/heads/det_pse_head.py +0 -37
  230. pyxlpr/ppocr/modeling/heads/det_sast_head.py +0 -128
  231. pyxlpr/ppocr/modeling/heads/e2e_pg_head.py +0 -253
  232. pyxlpr/ppocr/modeling/heads/kie_sdmgr_head.py +0 -206
  233. pyxlpr/ppocr/modeling/heads/multiheadAttention.py +0 -163
  234. pyxlpr/ppocr/modeling/heads/rec_aster_head.py +0 -393
  235. pyxlpr/ppocr/modeling/heads/rec_att_head.py +0 -202
  236. pyxlpr/ppocr/modeling/heads/rec_ctc_head.py +0 -88
  237. pyxlpr/ppocr/modeling/heads/rec_nrtr_head.py +0 -826
  238. pyxlpr/ppocr/modeling/heads/rec_sar_head.py +0 -402
  239. pyxlpr/ppocr/modeling/heads/rec_srn_head.py +0 -280
  240. pyxlpr/ppocr/modeling/heads/self_attention.py +0 -406
  241. pyxlpr/ppocr/modeling/heads/table_att_head.py +0 -246
  242. pyxlpr/ppocr/modeling/necks/__init__.py +0 -32
  243. pyxlpr/ppocr/modeling/necks/db_fpn.py +0 -111
  244. pyxlpr/ppocr/modeling/necks/east_fpn.py +0 -188
  245. pyxlpr/ppocr/modeling/necks/fpn.py +0 -138
  246. pyxlpr/ppocr/modeling/necks/pg_fpn.py +0 -314
  247. pyxlpr/ppocr/modeling/necks/rnn.py +0 -92
  248. pyxlpr/ppocr/modeling/necks/sast_fpn.py +0 -284
  249. pyxlpr/ppocr/modeling/necks/table_fpn.py +0 -110
  250. pyxlpr/ppocr/modeling/transforms/__init__.py +0 -28
  251. pyxlpr/ppocr/modeling/transforms/stn.py +0 -135
  252. pyxlpr/ppocr/modeling/transforms/tps.py +0 -308
  253. pyxlpr/ppocr/modeling/transforms/tps_spatial_transformer.py +0 -156
  254. pyxlpr/ppocr/optimizer/__init__.py +0 -61
  255. pyxlpr/ppocr/optimizer/learning_rate.py +0 -228
  256. pyxlpr/ppocr/optimizer/lr_scheduler.py +0 -49
  257. pyxlpr/ppocr/optimizer/optimizer.py +0 -160
  258. pyxlpr/ppocr/optimizer/regularizer.py +0 -52
  259. pyxlpr/ppocr/postprocess/__init__.py +0 -55
  260. pyxlpr/ppocr/postprocess/cls_postprocess.py +0 -33
  261. pyxlpr/ppocr/postprocess/db_postprocess.py +0 -234
  262. pyxlpr/ppocr/postprocess/east_postprocess.py +0 -143
  263. pyxlpr/ppocr/postprocess/locality_aware_nms.py +0 -200
  264. pyxlpr/ppocr/postprocess/pg_postprocess.py +0 -52
  265. pyxlpr/ppocr/postprocess/pse_postprocess/__init__.py +0 -15
  266. pyxlpr/ppocr/postprocess/pse_postprocess/pse/__init__.py +0 -29
  267. pyxlpr/ppocr/postprocess/pse_postprocess/pse/setup.py +0 -14
  268. pyxlpr/ppocr/postprocess/pse_postprocess/pse_postprocess.py +0 -118
  269. pyxlpr/ppocr/postprocess/rec_postprocess.py +0 -654
  270. pyxlpr/ppocr/postprocess/sast_postprocess.py +0 -355
  271. pyxlpr/ppocr/tools/__init__.py +0 -14
  272. pyxlpr/ppocr/tools/eval.py +0 -83
  273. pyxlpr/ppocr/tools/export_center.py +0 -77
  274. pyxlpr/ppocr/tools/export_model.py +0 -129
  275. pyxlpr/ppocr/tools/infer/predict_cls.py +0 -151
  276. pyxlpr/ppocr/tools/infer/predict_det.py +0 -300
  277. pyxlpr/ppocr/tools/infer/predict_e2e.py +0 -169
  278. pyxlpr/ppocr/tools/infer/predict_rec.py +0 -414
  279. pyxlpr/ppocr/tools/infer/predict_system.py +0 -204
  280. pyxlpr/ppocr/tools/infer/utility.py +0 -629
  281. pyxlpr/ppocr/tools/infer_cls.py +0 -83
  282. pyxlpr/ppocr/tools/infer_det.py +0 -134
  283. pyxlpr/ppocr/tools/infer_e2e.py +0 -122
  284. pyxlpr/ppocr/tools/infer_kie.py +0 -153
  285. pyxlpr/ppocr/tools/infer_rec.py +0 -146
  286. pyxlpr/ppocr/tools/infer_table.py +0 -107
  287. pyxlpr/ppocr/tools/program.py +0 -596
  288. pyxlpr/ppocr/tools/test_hubserving.py +0 -117
  289. pyxlpr/ppocr/tools/train.py +0 -163
  290. pyxlpr/ppocr/tools/xlprog.py +0 -748
  291. pyxlpr/ppocr/utils/EN_symbol_dict.txt +0 -94
  292. pyxlpr/ppocr/utils/__init__.py +0 -24
  293. pyxlpr/ppocr/utils/dict/ar_dict.txt +0 -117
  294. pyxlpr/ppocr/utils/dict/arabic_dict.txt +0 -162
  295. pyxlpr/ppocr/utils/dict/be_dict.txt +0 -145
  296. pyxlpr/ppocr/utils/dict/bg_dict.txt +0 -140
  297. pyxlpr/ppocr/utils/dict/chinese_cht_dict.txt +0 -8421
  298. pyxlpr/ppocr/utils/dict/cyrillic_dict.txt +0 -163
  299. pyxlpr/ppocr/utils/dict/devanagari_dict.txt +0 -167
  300. pyxlpr/ppocr/utils/dict/en_dict.txt +0 -63
  301. pyxlpr/ppocr/utils/dict/fa_dict.txt +0 -136
  302. pyxlpr/ppocr/utils/dict/french_dict.txt +0 -136
  303. pyxlpr/ppocr/utils/dict/german_dict.txt +0 -143
  304. pyxlpr/ppocr/utils/dict/hi_dict.txt +0 -162
  305. pyxlpr/ppocr/utils/dict/it_dict.txt +0 -118
  306. pyxlpr/ppocr/utils/dict/japan_dict.txt +0 -4399
  307. pyxlpr/ppocr/utils/dict/ka_dict.txt +0 -153
  308. pyxlpr/ppocr/utils/dict/korean_dict.txt +0 -3688
  309. pyxlpr/ppocr/utils/dict/latin_dict.txt +0 -185
  310. pyxlpr/ppocr/utils/dict/mr_dict.txt +0 -153
  311. pyxlpr/ppocr/utils/dict/ne_dict.txt +0 -153
  312. pyxlpr/ppocr/utils/dict/oc_dict.txt +0 -96
  313. pyxlpr/ppocr/utils/dict/pu_dict.txt +0 -130
  314. pyxlpr/ppocr/utils/dict/rs_dict.txt +0 -91
  315. pyxlpr/ppocr/utils/dict/rsc_dict.txt +0 -134
  316. pyxlpr/ppocr/utils/dict/ru_dict.txt +0 -125
  317. pyxlpr/ppocr/utils/dict/ta_dict.txt +0 -128
  318. pyxlpr/ppocr/utils/dict/table_dict.txt +0 -277
  319. pyxlpr/ppocr/utils/dict/table_structure_dict.txt +0 -2759
  320. pyxlpr/ppocr/utils/dict/te_dict.txt +0 -151
  321. pyxlpr/ppocr/utils/dict/ug_dict.txt +0 -114
  322. pyxlpr/ppocr/utils/dict/uk_dict.txt +0 -142
  323. pyxlpr/ppocr/utils/dict/ur_dict.txt +0 -137
  324. pyxlpr/ppocr/utils/dict/xi_dict.txt +0 -110
  325. pyxlpr/ppocr/utils/dict90.txt +0 -90
  326. pyxlpr/ppocr/utils/e2e_metric/Deteval.py +0 -574
  327. pyxlpr/ppocr/utils/e2e_metric/polygon_fast.py +0 -83
  328. pyxlpr/ppocr/utils/e2e_utils/extract_batchsize.py +0 -87
  329. pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_fast.py +0 -457
  330. pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_slow.py +0 -592
  331. pyxlpr/ppocr/utils/e2e_utils/pgnet_pp_utils.py +0 -162
  332. pyxlpr/ppocr/utils/e2e_utils/visual.py +0 -162
  333. pyxlpr/ppocr/utils/en_dict.txt +0 -95
  334. pyxlpr/ppocr/utils/gen_label.py +0 -81
  335. pyxlpr/ppocr/utils/ic15_dict.txt +0 -36
  336. pyxlpr/ppocr/utils/iou.py +0 -54
  337. pyxlpr/ppocr/utils/logging.py +0 -69
  338. pyxlpr/ppocr/utils/network.py +0 -84
  339. pyxlpr/ppocr/utils/ppocr_keys_v1.txt +0 -6623
  340. pyxlpr/ppocr/utils/profiler.py +0 -110
  341. pyxlpr/ppocr/utils/save_load.py +0 -150
  342. pyxlpr/ppocr/utils/stats.py +0 -72
  343. pyxlpr/ppocr/utils/utility.py +0 -80
  344. pyxlpr/ppstructure/__init__.py +0 -13
  345. pyxlpr/ppstructure/predict_system.py +0 -187
  346. pyxlpr/ppstructure/table/__init__.py +0 -13
  347. pyxlpr/ppstructure/table/eval_table.py +0 -72
  348. pyxlpr/ppstructure/table/matcher.py +0 -192
  349. pyxlpr/ppstructure/table/predict_structure.py +0 -136
  350. pyxlpr/ppstructure/table/predict_table.py +0 -221
  351. pyxlpr/ppstructure/table/table_metric/__init__.py +0 -16
  352. pyxlpr/ppstructure/table/table_metric/parallel.py +0 -51
  353. pyxlpr/ppstructure/table/table_metric/table_metric.py +0 -247
  354. pyxlpr/ppstructure/table/tablepyxl/__init__.py +0 -13
  355. pyxlpr/ppstructure/table/tablepyxl/style.py +0 -283
  356. pyxlpr/ppstructure/table/tablepyxl/tablepyxl.py +0 -118
  357. pyxlpr/ppstructure/utility.py +0 -71
  358. pyxlpr/xlai.py +0 -10
@@ -1,654 +0,0 @@
1
- # copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- import numpy as np
15
- import string
16
- import paddle
17
- from paddle.nn import functional as F
18
- import re
19
-
20
-
21
- class BaseRecLabelDecode(object):
22
- """ Convert between text-label and text-index """
23
-
24
- def __init__(self, character_dict_path=None, use_space_char=False):
25
- self.beg_str = "sos"
26
- self.end_str = "eos"
27
-
28
- self.character_str = []
29
- if character_dict_path is None:
30
- self.character_str = "0123456789abcdefghijklmnopqrstuvwxyz"
31
- dict_character = list(self.character_str)
32
- else:
33
- with open(character_dict_path, "rb") as fin:
34
- lines = fin.readlines()
35
- for line in lines:
36
- line = line.decode('utf-8').strip("\n").strip("\r\n")
37
- self.character_str.append(line)
38
- if use_space_char:
39
- self.character_str.append(" ")
40
- dict_character = list(self.character_str)
41
-
42
- dict_character = self.add_special_char(dict_character)
43
- self.dict = {}
44
- for i, char in enumerate(dict_character):
45
- self.dict[char] = i
46
- self.character = dict_character
47
-
48
- def add_special_char(self, dict_character):
49
- return dict_character
50
-
51
- def decode(self, text_index, text_prob=None, is_remove_duplicate=False):
52
- """ convert text-index into text-label. """
53
- result_list = []
54
- ignored_tokens = self.get_ignored_tokens()
55
- batch_size = len(text_index)
56
- for batch_idx in range(batch_size):
57
- char_list = []
58
- conf_list = []
59
- for idx in range(len(text_index[batch_idx])):
60
- if text_index[batch_idx][idx] in ignored_tokens:
61
- continue
62
- if is_remove_duplicate:
63
- # only for predict
64
- if idx > 0 and text_index[batch_idx][idx - 1] == text_index[
65
- batch_idx][idx]:
66
- continue
67
- char_list.append(self.character[int(text_index[batch_idx][
68
- idx])])
69
- if text_prob is not None:
70
- conf_list.append(text_prob[batch_idx][idx])
71
- else:
72
- conf_list.append(1)
73
- text = ''.join(char_list)
74
- result_list.append((text, np.mean(conf_list)))
75
- return result_list
76
-
77
- def get_ignored_tokens(self):
78
- return [0] # for ctc blank
79
-
80
-
81
- class CTCLabelDecode(BaseRecLabelDecode):
82
- """ Convert between text-label and text-index """
83
-
84
- def __init__(self, character_dict_path=None, use_space_char=False,
85
- **kwargs):
86
- super(CTCLabelDecode, self).__init__(character_dict_path,
87
- use_space_char)
88
-
89
- def __call__(self, preds, label=None, *args, **kwargs):
90
- if isinstance(preds, tuple):
91
- preds = preds[-1]
92
- if isinstance(preds, paddle.Tensor):
93
- preds = preds.numpy()
94
- preds_idx = preds.argmax(axis=2)
95
- preds_prob = preds.max(axis=2)
96
- text = self.decode(preds_idx, preds_prob, is_remove_duplicate=True)
97
- if label is None:
98
- return text
99
- label = self.decode(label)
100
- return text, label
101
-
102
- def add_special_char(self, dict_character):
103
- dict_character = ['blank'] + dict_character
104
- return dict_character
105
-
106
-
107
- class DistillationCTCLabelDecode(CTCLabelDecode):
108
- """
109
- Convert
110
- Convert between text-label and text-index
111
- """
112
-
113
- def __init__(self,
114
- character_dict_path=None,
115
- use_space_char=False,
116
- model_name=["student"],
117
- key=None,
118
- **kwargs):
119
- super(DistillationCTCLabelDecode, self).__init__(character_dict_path,
120
- use_space_char)
121
- if not isinstance(model_name, list):
122
- model_name = [model_name]
123
- self.model_name = model_name
124
-
125
- self.key = key
126
-
127
- def __call__(self, preds, label=None, *args, **kwargs):
128
- output = dict()
129
- for name in self.model_name:
130
- pred = preds[name]
131
- if self.key is not None:
132
- pred = pred[self.key]
133
- output[name] = super().__call__(pred, label=label, *args, **kwargs)
134
- return output
135
-
136
-
137
- class NRTRLabelDecode(BaseRecLabelDecode):
138
- """ Convert between text-label and text-index """
139
-
140
- def __init__(self, character_dict_path=None, use_space_char=True, **kwargs):
141
- super(NRTRLabelDecode, self).__init__(character_dict_path,
142
- use_space_char)
143
-
144
- def __call__(self, preds, label=None, *args, **kwargs):
145
-
146
- if len(preds) == 2:
147
- preds_id = preds[0]
148
- preds_prob = preds[1]
149
- if isinstance(preds_id, paddle.Tensor):
150
- preds_id = preds_id.numpy()
151
- if isinstance(preds_prob, paddle.Tensor):
152
- preds_prob = preds_prob.numpy()
153
- if preds_id[0][0] == 2:
154
- preds_idx = preds_id[:, 1:]
155
- preds_prob = preds_prob[:, 1:]
156
- else:
157
- preds_idx = preds_id
158
- text = self.decode(preds_idx, preds_prob, is_remove_duplicate=False)
159
- if label is None:
160
- return text
161
- label = self.decode(label[:, 1:])
162
- else:
163
- if isinstance(preds, paddle.Tensor):
164
- preds = preds.numpy()
165
- preds_idx = preds.argmax(axis=2)
166
- preds_prob = preds.max(axis=2)
167
- text = self.decode(preds_idx, preds_prob, is_remove_duplicate=False)
168
- if label is None:
169
- return text
170
- label = self.decode(label[:, 1:])
171
- return text, label
172
-
173
- def add_special_char(self, dict_character):
174
- dict_character = ['blank', '<unk>', '<s>', '</s>'] + dict_character
175
- return dict_character
176
-
177
- def decode(self, text_index, text_prob=None, is_remove_duplicate=False):
178
- """ convert text-index into text-label. """
179
- result_list = []
180
- batch_size = len(text_index)
181
- for batch_idx in range(batch_size):
182
- char_list = []
183
- conf_list = []
184
- for idx in range(len(text_index[batch_idx])):
185
- if text_index[batch_idx][idx] == 3: # end
186
- break
187
- try:
188
- char_list.append(self.character[int(text_index[batch_idx][
189
- idx])])
190
- except:
191
- continue
192
- if text_prob is not None:
193
- conf_list.append(text_prob[batch_idx][idx])
194
- else:
195
- conf_list.append(1)
196
- text = ''.join(char_list)
197
- result_list.append((text.lower(), np.mean(conf_list)))
198
- return result_list
199
-
200
-
201
- class AttnLabelDecode(BaseRecLabelDecode):
202
- """ Convert between text-label and text-index """
203
-
204
- def __init__(self, character_dict_path=None, use_space_char=False,
205
- **kwargs):
206
- super(AttnLabelDecode, self).__init__(character_dict_path,
207
- use_space_char)
208
-
209
- def add_special_char(self, dict_character):
210
- self.beg_str = "sos"
211
- self.end_str = "eos"
212
- dict_character = dict_character
213
- dict_character = [self.beg_str] + dict_character + [self.end_str]
214
- return dict_character
215
-
216
- def decode(self, text_index, text_prob=None, is_remove_duplicate=False):
217
- """ convert text-index into text-label. """
218
- result_list = []
219
- ignored_tokens = self.get_ignored_tokens()
220
- [beg_idx, end_idx] = self.get_ignored_tokens()
221
- batch_size = len(text_index)
222
- for batch_idx in range(batch_size):
223
- char_list = []
224
- conf_list = []
225
- for idx in range(len(text_index[batch_idx])):
226
- if text_index[batch_idx][idx] in ignored_tokens:
227
- continue
228
- if int(text_index[batch_idx][idx]) == int(end_idx):
229
- break
230
- if is_remove_duplicate:
231
- # only for predict
232
- if idx > 0 and text_index[batch_idx][idx - 1] == text_index[
233
- batch_idx][idx]:
234
- continue
235
- char_list.append(self.character[int(text_index[batch_idx][
236
- idx])])
237
- if text_prob is not None:
238
- conf_list.append(text_prob[batch_idx][idx])
239
- else:
240
- conf_list.append(1)
241
- text = ''.join(char_list)
242
- result_list.append((text, np.mean(conf_list)))
243
- return result_list
244
-
245
- def __call__(self, preds, label=None, *args, **kwargs):
246
- """
247
- text = self.decode(text)
248
- if label is None:
249
- return text
250
- else:
251
- label = self.decode(label, is_remove_duplicate=False)
252
- return text, label
253
- """
254
- if isinstance(preds, paddle.Tensor):
255
- preds = preds.numpy()
256
-
257
- preds_idx = preds.argmax(axis=2)
258
- preds_prob = preds.max(axis=2)
259
- text = self.decode(preds_idx, preds_prob, is_remove_duplicate=False)
260
- if label is None:
261
- return text
262
- label = self.decode(label, is_remove_duplicate=False)
263
- return text, label
264
-
265
- def get_ignored_tokens(self):
266
- beg_idx = self.get_beg_end_flag_idx("beg")
267
- end_idx = self.get_beg_end_flag_idx("end")
268
- return [beg_idx, end_idx]
269
-
270
- def get_beg_end_flag_idx(self, beg_or_end):
271
- if beg_or_end == "beg":
272
- idx = np.array(self.dict[self.beg_str])
273
- elif beg_or_end == "end":
274
- idx = np.array(self.dict[self.end_str])
275
- else:
276
- assert False, "unsupport type %s in get_beg_end_flag_idx" \
277
- % beg_or_end
278
- return idx
279
-
280
-
281
- class SEEDLabelDecode(BaseRecLabelDecode):
282
- """ Convert between text-label and text-index """
283
-
284
- def __init__(self, character_dict_path=None, use_space_char=False,
285
- **kwargs):
286
- super(SEEDLabelDecode, self).__init__(character_dict_path,
287
- use_space_char)
288
-
289
- def add_special_char(self, dict_character):
290
- self.padding_str = "padding"
291
- self.end_str = "eos"
292
- self.unknown = "unknown"
293
- dict_character = dict_character + [
294
- self.end_str, self.padding_str, self.unknown
295
- ]
296
- return dict_character
297
-
298
- def get_ignored_tokens(self):
299
- end_idx = self.get_beg_end_flag_idx("eos")
300
- return [end_idx]
301
-
302
- def get_beg_end_flag_idx(self, beg_or_end):
303
- if beg_or_end == "sos":
304
- idx = np.array(self.dict[self.beg_str])
305
- elif beg_or_end == "eos":
306
- idx = np.array(self.dict[self.end_str])
307
- else:
308
- assert False, "unsupport type %s in get_beg_end_flag_idx" % beg_or_end
309
- return idx
310
-
311
- def decode(self, text_index, text_prob=None, is_remove_duplicate=False):
312
- """ convert text-index into text-label. """
313
- result_list = []
314
- [end_idx] = self.get_ignored_tokens()
315
- batch_size = len(text_index)
316
- for batch_idx in range(batch_size):
317
- char_list = []
318
- conf_list = []
319
- for idx in range(len(text_index[batch_idx])):
320
- if int(text_index[batch_idx][idx]) == int(end_idx):
321
- break
322
- if is_remove_duplicate:
323
- # only for predict
324
- if idx > 0 and text_index[batch_idx][idx - 1] == text_index[
325
- batch_idx][idx]:
326
- continue
327
- char_list.append(self.character[int(text_index[batch_idx][
328
- idx])])
329
- if text_prob is not None:
330
- conf_list.append(text_prob[batch_idx][idx])
331
- else:
332
- conf_list.append(1)
333
- text = ''.join(char_list)
334
- result_list.append((text, np.mean(conf_list)))
335
- return result_list
336
-
337
- def __call__(self, preds, label=None, *args, **kwargs):
338
- """
339
- text = self.decode(text)
340
- if label is None:
341
- return text
342
- else:
343
- label = self.decode(label, is_remove_duplicate=False)
344
- return text, label
345
- """
346
- preds_idx = preds["rec_pred"]
347
- if isinstance(preds_idx, paddle.Tensor):
348
- preds_idx = preds_idx.numpy()
349
- if "rec_pred_scores" in preds:
350
- preds_idx = preds["rec_pred"]
351
- preds_prob = preds["rec_pred_scores"]
352
- else:
353
- preds_idx = preds["rec_pred"].argmax(axis=2)
354
- preds_prob = preds["rec_pred"].max(axis=2)
355
- text = self.decode(preds_idx, preds_prob, is_remove_duplicate=False)
356
- if label is None:
357
- return text
358
- label = self.decode(label, is_remove_duplicate=False)
359
- return text, label
360
-
361
-
362
- class SRNLabelDecode(BaseRecLabelDecode):
363
- """ Convert between text-label and text-index """
364
-
365
- def __init__(self, character_dict_path=None, use_space_char=False,
366
- **kwargs):
367
- super(SRNLabelDecode, self).__init__(character_dict_path,
368
- use_space_char)
369
- self.max_text_length = kwargs.get('max_text_length', 25)
370
-
371
- def __call__(self, preds, label=None, *args, **kwargs):
372
- pred = preds['predict']
373
- char_num = len(self.character_str) + 2
374
- if isinstance(pred, paddle.Tensor):
375
- pred = pred.numpy()
376
- pred = np.reshape(pred, [-1, char_num])
377
-
378
- preds_idx = np.argmax(pred, axis=1)
379
- preds_prob = np.max(pred, axis=1)
380
-
381
- preds_idx = np.reshape(preds_idx, [-1, self.max_text_length])
382
-
383
- preds_prob = np.reshape(preds_prob, [-1, self.max_text_length])
384
-
385
- text = self.decode(preds_idx, preds_prob)
386
-
387
- if label is None:
388
- text = self.decode(preds_idx, preds_prob, is_remove_duplicate=False)
389
- return text
390
- label = self.decode(label)
391
- return text, label
392
-
393
- def decode(self, text_index, text_prob=None, is_remove_duplicate=False):
394
- """ convert text-index into text-label. """
395
- result_list = []
396
- ignored_tokens = self.get_ignored_tokens()
397
- batch_size = len(text_index)
398
-
399
- for batch_idx in range(batch_size):
400
- char_list = []
401
- conf_list = []
402
- for idx in range(len(text_index[batch_idx])):
403
- if text_index[batch_idx][idx] in ignored_tokens:
404
- continue
405
- if is_remove_duplicate:
406
- # only for predict
407
- if idx > 0 and text_index[batch_idx][idx - 1] == text_index[
408
- batch_idx][idx]:
409
- continue
410
- char_list.append(self.character[int(text_index[batch_idx][
411
- idx])])
412
- if text_prob is not None:
413
- conf_list.append(text_prob[batch_idx][idx])
414
- else:
415
- conf_list.append(1)
416
-
417
- text = ''.join(char_list)
418
- result_list.append((text, np.mean(conf_list)))
419
- return result_list
420
-
421
- def add_special_char(self, dict_character):
422
- dict_character = dict_character + [self.beg_str, self.end_str]
423
- return dict_character
424
-
425
- def get_ignored_tokens(self):
426
- beg_idx = self.get_beg_end_flag_idx("beg")
427
- end_idx = self.get_beg_end_flag_idx("end")
428
- return [beg_idx, end_idx]
429
-
430
- def get_beg_end_flag_idx(self, beg_or_end):
431
- if beg_or_end == "beg":
432
- idx = np.array(self.dict[self.beg_str])
433
- elif beg_or_end == "end":
434
- idx = np.array(self.dict[self.end_str])
435
- else:
436
- assert False, "unsupport type %s in get_beg_end_flag_idx" \
437
- % beg_or_end
438
- return idx
439
-
440
-
441
- class TableLabelDecode(object):
442
- """ """
443
-
444
- def __init__(self, character_dict_path, **kwargs):
445
- list_character, list_elem = self.load_char_elem_dict(
446
- character_dict_path)
447
- list_character = self.add_special_char(list_character)
448
- list_elem = self.add_special_char(list_elem)
449
- self.dict_character = {}
450
- self.dict_idx_character = {}
451
- for i, char in enumerate(list_character):
452
- self.dict_idx_character[i] = char
453
- self.dict_character[char] = i
454
- self.dict_elem = {}
455
- self.dict_idx_elem = {}
456
- for i, elem in enumerate(list_elem):
457
- self.dict_idx_elem[i] = elem
458
- self.dict_elem[elem] = i
459
-
460
- def load_char_elem_dict(self, character_dict_path):
461
- list_character = []
462
- list_elem = []
463
- with open(character_dict_path, "rb") as fin:
464
- lines = fin.readlines()
465
- substr = lines[0].decode('utf-8').strip("\n").strip("\r\n").split(
466
- "\t")
467
- character_num = int(substr[0])
468
- elem_num = int(substr[1])
469
- for cno in range(1, 1 + character_num):
470
- character = lines[cno].decode('utf-8').strip("\n").strip("\r\n")
471
- list_character.append(character)
472
- for eno in range(1 + character_num, 1 + character_num + elem_num):
473
- elem = lines[eno].decode('utf-8').strip("\n").strip("\r\n")
474
- list_elem.append(elem)
475
- return list_character, list_elem
476
-
477
- def add_special_char(self, list_character):
478
- self.beg_str = "sos"
479
- self.end_str = "eos"
480
- list_character = [self.beg_str] + list_character + [self.end_str]
481
- return list_character
482
-
483
- def __call__(self, preds):
484
- structure_probs = preds['structure_probs']
485
- loc_preds = preds['loc_preds']
486
- if isinstance(structure_probs, paddle.Tensor):
487
- structure_probs = structure_probs.numpy()
488
- if isinstance(loc_preds, paddle.Tensor):
489
- loc_preds = loc_preds.numpy()
490
- structure_idx = structure_probs.argmax(axis=2)
491
- structure_probs = structure_probs.max(axis=2)
492
- structure_str, structure_pos, result_score_list, result_elem_idx_list = self.decode(
493
- structure_idx, structure_probs, 'elem')
494
- res_html_code_list = []
495
- res_loc_list = []
496
- batch_num = len(structure_str)
497
- for bno in range(batch_num):
498
- res_loc = []
499
- for sno in range(len(structure_str[bno])):
500
- text = structure_str[bno][sno]
501
- if text in ['<td>', '<td']:
502
- pos = structure_pos[bno][sno]
503
- res_loc.append(loc_preds[bno, pos])
504
- res_html_code = ''.join(structure_str[bno])
505
- res_loc = np.array(res_loc)
506
- res_html_code_list.append(res_html_code)
507
- res_loc_list.append(res_loc)
508
- return {
509
- 'res_html_code': res_html_code_list,
510
- 'res_loc': res_loc_list,
511
- 'res_score_list': result_score_list,
512
- 'res_elem_idx_list': result_elem_idx_list,
513
- 'structure_str_list': structure_str
514
- }
515
-
516
- def decode(self, text_index, structure_probs, char_or_elem):
517
- """convert text-label into text-index.
518
- """
519
- if char_or_elem == "char":
520
- current_dict = self.dict_idx_character
521
- else:
522
- current_dict = self.dict_idx_elem
523
- ignored_tokens = self.get_ignored_tokens('elem')
524
- beg_idx, end_idx = ignored_tokens
525
-
526
- result_list = []
527
- result_pos_list = []
528
- result_score_list = []
529
- result_elem_idx_list = []
530
- batch_size = len(text_index)
531
- for batch_idx in range(batch_size):
532
- char_list = []
533
- elem_pos_list = []
534
- elem_idx_list = []
535
- score_list = []
536
- for idx in range(len(text_index[batch_idx])):
537
- tmp_elem_idx = int(text_index[batch_idx][idx])
538
- if idx > 0 and tmp_elem_idx == end_idx:
539
- break
540
- if tmp_elem_idx in ignored_tokens:
541
- continue
542
-
543
- char_list.append(current_dict[tmp_elem_idx])
544
- elem_pos_list.append(idx)
545
- score_list.append(structure_probs[batch_idx, idx])
546
- elem_idx_list.append(tmp_elem_idx)
547
- result_list.append(char_list)
548
- result_pos_list.append(elem_pos_list)
549
- result_score_list.append(score_list)
550
- result_elem_idx_list.append(elem_idx_list)
551
- return result_list, result_pos_list, result_score_list, result_elem_idx_list
552
-
553
- def get_ignored_tokens(self, char_or_elem):
554
- beg_idx = self.get_beg_end_flag_idx("beg", char_or_elem)
555
- end_idx = self.get_beg_end_flag_idx("end", char_or_elem)
556
- return [beg_idx, end_idx]
557
-
558
- def get_beg_end_flag_idx(self, beg_or_end, char_or_elem):
559
- if char_or_elem == "char":
560
- if beg_or_end == "beg":
561
- idx = self.dict_character[self.beg_str]
562
- elif beg_or_end == "end":
563
- idx = self.dict_character[self.end_str]
564
- else:
565
- assert False, "Unsupport type %s in get_beg_end_flag_idx of char" \
566
- % beg_or_end
567
- elif char_or_elem == "elem":
568
- if beg_or_end == "beg":
569
- idx = self.dict_elem[self.beg_str]
570
- elif beg_or_end == "end":
571
- idx = self.dict_elem[self.end_str]
572
- else:
573
- assert False, "Unsupport type %s in get_beg_end_flag_idx of elem" \
574
- % beg_or_end
575
- else:
576
- assert False, "Unsupport type %s in char_or_elem" \
577
- % char_or_elem
578
- return idx
579
-
580
-
581
- class SARLabelDecode(BaseRecLabelDecode):
582
- """ Convert between text-label and text-index """
583
-
584
- def __init__(self, character_dict_path=None, use_space_char=False,
585
- **kwargs):
586
- super(SARLabelDecode, self).__init__(character_dict_path,
587
- use_space_char)
588
-
589
- self.rm_symbol = kwargs.get('rm_symbol', False)
590
-
591
- def add_special_char(self, dict_character):
592
- beg_end_str = "<BOS/EOS>"
593
- unknown_str = "<UKN>"
594
- padding_str = "<PAD>"
595
- dict_character = dict_character + [unknown_str]
596
- self.unknown_idx = len(dict_character) - 1
597
- dict_character = dict_character + [beg_end_str]
598
- self.start_idx = len(dict_character) - 1
599
- self.end_idx = len(dict_character) - 1
600
- dict_character = dict_character + [padding_str]
601
- self.padding_idx = len(dict_character) - 1
602
- return dict_character
603
-
604
- def decode(self, text_index, text_prob=None, is_remove_duplicate=False):
605
- """ convert text-index into text-label. """
606
- result_list = []
607
- ignored_tokens = self.get_ignored_tokens()
608
-
609
- batch_size = len(text_index)
610
- for batch_idx in range(batch_size):
611
- char_list = []
612
- conf_list = []
613
- for idx in range(len(text_index[batch_idx])):
614
- if text_index[batch_idx][idx] in ignored_tokens:
615
- continue
616
- if int(text_index[batch_idx][idx]) == int(self.end_idx):
617
- if text_prob is None and idx == 0:
618
- continue
619
- else:
620
- break
621
- if is_remove_duplicate:
622
- # only for predict
623
- if idx > 0 and text_index[batch_idx][idx - 1] == text_index[
624
- batch_idx][idx]:
625
- continue
626
- char_list.append(self.character[int(text_index[batch_idx][
627
- idx])])
628
- if text_prob is not None:
629
- conf_list.append(text_prob[batch_idx][idx])
630
- else:
631
- conf_list.append(1)
632
- text = ''.join(char_list)
633
- if self.rm_symbol:
634
- comp = re.compile('[^A-Z^a-z^0-9^\u4e00-\u9fa5]')
635
- text = text.lower()
636
- text = comp.sub('', text)
637
- result_list.append((text, np.mean(conf_list)))
638
- return result_list
639
-
640
- def __call__(self, preds, label=None, *args, **kwargs):
641
- if isinstance(preds, paddle.Tensor):
642
- preds = preds.numpy()
643
- preds_idx = preds.argmax(axis=2)
644
- preds_prob = preds.max(axis=2)
645
-
646
- text = self.decode(preds_idx, preds_prob, is_remove_duplicate=False)
647
-
648
- if label is None:
649
- return text
650
- label = self.decode(label, is_remove_duplicate=False)
651
- return text, label
652
-
653
- def get_ignored_tokens(self):
654
- return [self.padding_idx]