openocr-python 0.0.2__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.
- openocr/__init__.py +11 -0
- openocr/configs/det/dbnet/repvit_db.yml +173 -0
- openocr/configs/rec/abinet/resnet45_trans_abinet_lang.yml +94 -0
- openocr/configs/rec/abinet/resnet45_trans_abinet_wo_lang.yml +93 -0
- openocr/configs/rec/abinet/svtrv2_abinet_lang.yml +130 -0
- openocr/configs/rec/abinet/svtrv2_abinet_wo_lang.yml +128 -0
- openocr/configs/rec/aster/resnet31_lstm_aster_tps_on.yml +93 -0
- openocr/configs/rec/aster/svtrv2_aster.yml +127 -0
- openocr/configs/rec/aster/svtrv2_aster_tps_on.yml +102 -0
- openocr/configs/rec/autostr/autostr_lstm_aster_tps_on.yml +95 -0
- openocr/configs/rec/busnet/svtrv2_busnet.yml +135 -0
- openocr/configs/rec/busnet/svtrv2_busnet_pretraining.yml +134 -0
- openocr/configs/rec/busnet/vit_busnet.yml +104 -0
- openocr/configs/rec/busnet/vit_busnet_pretraining.yml +104 -0
- openocr/configs/rec/cam/convnextv2_cam_tps_on.yml +118 -0
- openocr/configs/rec/cam/convnextv2_tiny_cam_tps_on.yml +118 -0
- openocr/configs/rec/cam/svtrv2_cam_tps_on.yml +123 -0
- openocr/configs/rec/cdistnet/resnet45_trans_cdistnet.yml +93 -0
- openocr/configs/rec/cdistnet/svtrv2_cdistnet.yml +139 -0
- openocr/configs/rec/cppd/svtr_base_cppd.yml +123 -0
- openocr/configs/rec/cppd/svtr_base_cppd_ch.yml +126 -0
- openocr/configs/rec/cppd/svtr_base_cppd_h8.yml +123 -0
- openocr/configs/rec/cppd/svtr_base_cppd_syn.yml +124 -0
- openocr/configs/rec/cppd/svtrv2_cppd.yml +150 -0
- openocr/configs/rec/dan/resnet45_fpn_dan.yml +98 -0
- openocr/configs/rec/dan/svtrv2_dan.yml +130 -0
- openocr/configs/rec/focalsvtr/focalsvtr_ctc.yml +137 -0
- openocr/configs/rec/gtc/svtrv2_lnconv_nrtr_gtc.yml +168 -0
- openocr/configs/rec/gtc/svtrv2_lnconv_smtr_gtc_long_infer.yml +151 -0
- openocr/configs/rec/gtc/svtrv2_lnconv_smtr_gtc_smtr_long.yml +150 -0
- openocr/configs/rec/gtc/svtrv2_lnconv_smtr_gtc_stream.yml +152 -0
- openocr/configs/rec/igtr/svtr_base_ds_igtr.yml +157 -0
- openocr/configs/rec/lister/focalsvtr_lister_wo_fem_maxratio12.yml +133 -0
- openocr/configs/rec/lister/svtrv2_lister_wo_fem_maxratio12.yml +138 -0
- openocr/configs/rec/lpv/svtr_base_lpv.yml +124 -0
- openocr/configs/rec/lpv/svtr_base_lpv_wo_glrm.yml +123 -0
- openocr/configs/rec/lpv/svtrv2_lpv.yml +147 -0
- openocr/configs/rec/lpv/svtrv2_lpv_wo_glrm.yml +146 -0
- openocr/configs/rec/maerec/vit_nrtr.yml +116 -0
- openocr/configs/rec/matrn/resnet45_trans_matrn.yml +95 -0
- openocr/configs/rec/matrn/svtrv2_matrn.yml +130 -0
- openocr/configs/rec/mgpstr/svtrv2_mgpstr_only_char.yml +140 -0
- openocr/configs/rec/mgpstr/vit_base_mgpstr_only_char.yml +111 -0
- openocr/configs/rec/mgpstr/vit_large_mgpstr_only_char.yml +110 -0
- openocr/configs/rec/mgpstr/vit_mgpstr.yml +110 -0
- openocr/configs/rec/mgpstr/vit_mgpstr_only_char.yml +110 -0
- openocr/configs/rec/moran/resnet31_lstm_moran.yml +92 -0
- openocr/configs/rec/nrtr/focalsvtr_nrtr_maxraio12.yml +145 -0
- openocr/configs/rec/nrtr/nrtr.yml +107 -0
- openocr/configs/rec/nrtr/svtr_base_nrtr.yml +118 -0
- openocr/configs/rec/nrtr/svtr_base_nrtr_syn.yml +119 -0
- openocr/configs/rec/nrtr/svtrv2_nrtr.yml +146 -0
- openocr/configs/rec/ote/svtr_base_h8_ote.yml +117 -0
- openocr/configs/rec/ote/svtr_base_ote.yml +116 -0
- openocr/configs/rec/parseq/focalsvtr_parseq_maxratio12.yml +140 -0
- openocr/configs/rec/parseq/svrtv2_parseq.yml +136 -0
- openocr/configs/rec/parseq/vit_parseq.yml +100 -0
- openocr/configs/rec/robustscanner/resnet31_robustscanner.yml +102 -0
- openocr/configs/rec/robustscanner/svtrv2_robustscanner.yml +134 -0
- openocr/configs/rec/sar/resnet31_lstm_sar.yml +94 -0
- openocr/configs/rec/sar/svtrv2_sar.yml +128 -0
- openocr/configs/rec/seed/resnet31_lstm_seed_tps_on.yml +96 -0
- openocr/configs/rec/smtr/focalsvtr_smtr.yml +150 -0
- openocr/configs/rec/smtr/focalsvtr_smtr_long.yml +133 -0
- openocr/configs/rec/smtr/svtrv2_smtr.yml +150 -0
- openocr/configs/rec/smtr/svtrv2_smtr_bi.yml +136 -0
- openocr/configs/rec/srn/resnet50_fpn_srn.yml +97 -0
- openocr/configs/rec/srn/svtrv2_srn.yml +131 -0
- openocr/configs/rec/svtrs/convnextv2_ctc.yml +105 -0
- openocr/configs/rec/svtrs/convnextv2_h8_ctc.yml +105 -0
- openocr/configs/rec/svtrs/convnextv2_h8_rctc.yml +106 -0
- openocr/configs/rec/svtrs/convnextv2_rctc.yml +106 -0
- openocr/configs/rec/svtrs/convnextv2_tiny_h8_ctc.yml +105 -0
- openocr/configs/rec/svtrs/convnextv2_tiny_h8_rctc.yml +106 -0
- openocr/configs/rec/svtrs/crnn_ctc.yml +99 -0
- openocr/configs/rec/svtrs/crnn_ctc_long.yml +116 -0
- openocr/configs/rec/svtrs/focalnet_base_ctc.yml +108 -0
- openocr/configs/rec/svtrs/focalnet_base_rctc.yml +109 -0
- openocr/configs/rec/svtrs/focalsvtr_ctc.yml +106 -0
- openocr/configs/rec/svtrs/focalsvtr_rctc.yml +107 -0
- openocr/configs/rec/svtrs/resnet45_trans_ctc.yml +103 -0
- openocr/configs/rec/svtrs/resnet45_trans_rctc.yml +104 -0
- openocr/configs/rec/svtrs/svtr_base_ctc.yml +110 -0
- openocr/configs/rec/svtrs/svtr_base_rctc.yml +111 -0
- openocr/configs/rec/svtrs/svtrnet_ctc_syn.yml +111 -0
- openocr/configs/rec/svtrs/vit_ctc.yml +103 -0
- openocr/configs/rec/svtrs/vit_rctc.yml +103 -0
- openocr/configs/rec/svtrv2/repsvtr_ch.yml +121 -0
- openocr/configs/rec/svtrv2/svtrv2_ch.yml +133 -0
- openocr/configs/rec/svtrv2/svtrv2_ctc.yml +136 -0
- openocr/configs/rec/svtrv2/svtrv2_rctc.yml +135 -0
- openocr/configs/rec/svtrv2/svtrv2_small_rctc.yml +135 -0
- openocr/configs/rec/svtrv2/svtrv2_smtr_gtc_rctc.yml +162 -0
- openocr/configs/rec/svtrv2/svtrv2_smtr_gtc_rctc_ch.yml +153 -0
- openocr/configs/rec/svtrv2/svtrv2_tiny_rctc.yml +135 -0
- openocr/configs/rec/visionlan/resnet45_trans_visionlan_LA.yml +103 -0
- openocr/configs/rec/visionlan/resnet45_trans_visionlan_LF_1.yml +102 -0
- openocr/configs/rec/visionlan/resnet45_trans_visionlan_LF_2.yml +103 -0
- openocr/configs/rec/visionlan/svtrv2_visionlan_LA.yml +112 -0
- openocr/configs/rec/visionlan/svtrv2_visionlan_LF_1.yml +111 -0
- openocr/configs/rec/visionlan/svtrv2_visionlan_LF_2.yml +112 -0
- openocr/demo_gradio.py +128 -0
- openocr/opendet/modeling/__init__.py +11 -0
- openocr/opendet/modeling/backbones/__init__.py +14 -0
- openocr/opendet/modeling/backbones/repvit.py +340 -0
- openocr/opendet/modeling/base_detector.py +69 -0
- openocr/opendet/modeling/heads/__init__.py +14 -0
- openocr/opendet/modeling/heads/db_head.py +73 -0
- openocr/opendet/modeling/necks/__init__.py +14 -0
- openocr/opendet/modeling/necks/db_fpn.py +609 -0
- openocr/opendet/postprocess/__init__.py +18 -0
- openocr/opendet/postprocess/db_postprocess.py +273 -0
- openocr/opendet/preprocess/__init__.py +154 -0
- openocr/opendet/preprocess/crop_resize.py +121 -0
- openocr/opendet/preprocess/db_resize_for_test.py +135 -0
- openocr/openrec/losses/__init__.py +62 -0
- openocr/openrec/losses/abinet_loss.py +42 -0
- openocr/openrec/losses/ar_loss.py +23 -0
- openocr/openrec/losses/cam_loss.py +48 -0
- openocr/openrec/losses/cdistnet_loss.py +34 -0
- openocr/openrec/losses/ce_loss.py +68 -0
- openocr/openrec/losses/cppd_loss.py +77 -0
- openocr/openrec/losses/ctc_loss.py +33 -0
- openocr/openrec/losses/igtr_loss.py +12 -0
- openocr/openrec/losses/lister_loss.py +14 -0
- openocr/openrec/losses/lpv_loss.py +30 -0
- openocr/openrec/losses/mgp_loss.py +34 -0
- openocr/openrec/losses/parseq_loss.py +12 -0
- openocr/openrec/losses/robustscanner_loss.py +20 -0
- openocr/openrec/losses/seed_loss.py +46 -0
- openocr/openrec/losses/smtr_loss.py +12 -0
- openocr/openrec/losses/srn_loss.py +40 -0
- openocr/openrec/losses/visionlan_loss.py +58 -0
- openocr/openrec/metrics/__init__.py +19 -0
- openocr/openrec/metrics/rec_metric.py +270 -0
- openocr/openrec/metrics/rec_metric_gtc.py +58 -0
- openocr/openrec/metrics/rec_metric_long.py +142 -0
- openocr/openrec/metrics/rec_metric_mgp.py +93 -0
- openocr/openrec/modeling/__init__.py +11 -0
- openocr/openrec/modeling/base_recognizer.py +69 -0
- openocr/openrec/modeling/common.py +238 -0
- openocr/openrec/modeling/decoders/__init__.py +109 -0
- openocr/openrec/modeling/decoders/abinet_decoder.py +283 -0
- openocr/openrec/modeling/decoders/aster_decoder.py +170 -0
- openocr/openrec/modeling/decoders/bus_decoder.py +133 -0
- openocr/openrec/modeling/decoders/cam_decoder.py +43 -0
- openocr/openrec/modeling/decoders/cdistnet_decoder.py +334 -0
- openocr/openrec/modeling/decoders/cppd_decoder.py +393 -0
- openocr/openrec/modeling/decoders/ctc_decoder.py +203 -0
- openocr/openrec/modeling/decoders/dan_decoder.py +203 -0
- openocr/openrec/modeling/decoders/igtr_decoder.py +815 -0
- openocr/openrec/modeling/decoders/lister_decoder.py +535 -0
- openocr/openrec/modeling/decoders/lpv_decoder.py +119 -0
- openocr/openrec/modeling/decoders/matrn_decoder.py +236 -0
- openocr/openrec/modeling/decoders/mgp_decoder.py +99 -0
- openocr/openrec/modeling/decoders/nrtr_decoder.py +439 -0
- openocr/openrec/modeling/decoders/ote_decoder.py +205 -0
- openocr/openrec/modeling/decoders/parseq_decoder.py +504 -0
- openocr/openrec/modeling/decoders/rctc_decoder.py +70 -0
- openocr/openrec/modeling/decoders/robustscanner_decoder.py +749 -0
- openocr/openrec/modeling/decoders/sar_decoder.py +236 -0
- openocr/openrec/modeling/decoders/smtr_decoder.py +621 -0
- openocr/openrec/modeling/decoders/smtr_decoder_nattn.py +521 -0
- openocr/openrec/modeling/decoders/srn_decoder.py +283 -0
- openocr/openrec/modeling/decoders/visionlan_decoder.py +321 -0
- openocr/openrec/modeling/encoders/__init__.py +39 -0
- openocr/openrec/modeling/encoders/autostr_encoder.py +327 -0
- openocr/openrec/modeling/encoders/cam_encoder.py +760 -0
- openocr/openrec/modeling/encoders/convnextv2.py +213 -0
- openocr/openrec/modeling/encoders/focalsvtr.py +631 -0
- openocr/openrec/modeling/encoders/nrtr_encoder.py +28 -0
- openocr/openrec/modeling/encoders/rec_hgnet.py +346 -0
- openocr/openrec/modeling/encoders/rec_lcnetv3.py +488 -0
- openocr/openrec/modeling/encoders/rec_mobilenet_v3.py +132 -0
- openocr/openrec/modeling/encoders/rec_mv1_enhance.py +254 -0
- openocr/openrec/modeling/encoders/rec_nrtr_mtb.py +37 -0
- openocr/openrec/modeling/encoders/rec_resnet_31.py +213 -0
- openocr/openrec/modeling/encoders/rec_resnet_45.py +183 -0
- openocr/openrec/modeling/encoders/rec_resnet_fpn.py +216 -0
- openocr/openrec/modeling/encoders/rec_resnet_vd.py +252 -0
- openocr/openrec/modeling/encoders/repvit.py +338 -0
- openocr/openrec/modeling/encoders/resnet31_rnn.py +123 -0
- openocr/openrec/modeling/encoders/svtrnet.py +574 -0
- openocr/openrec/modeling/encoders/svtrnet2dpos.py +616 -0
- openocr/openrec/modeling/encoders/svtrv2.py +470 -0
- openocr/openrec/modeling/encoders/svtrv2_lnconv.py +503 -0
- openocr/openrec/modeling/encoders/svtrv2_lnconv_two33.py +517 -0
- openocr/openrec/modeling/encoders/vit.py +120 -0
- openocr/openrec/modeling/transforms/__init__.py +15 -0
- openocr/openrec/modeling/transforms/aster_tps.py +262 -0
- openocr/openrec/modeling/transforms/moran.py +136 -0
- openocr/openrec/modeling/transforms/tps.py +246 -0
- openocr/openrec/optimizer/__init__.py +73 -0
- openocr/openrec/optimizer/lr.py +227 -0
- openocr/openrec/postprocess/__init__.py +72 -0
- openocr/openrec/postprocess/abinet_postprocess.py +37 -0
- openocr/openrec/postprocess/ar_postprocess.py +63 -0
- openocr/openrec/postprocess/ce_postprocess.py +43 -0
- openocr/openrec/postprocess/char_postprocess.py +108 -0
- openocr/openrec/postprocess/cppd_postprocess.py +42 -0
- openocr/openrec/postprocess/ctc_postprocess.py +119 -0
- openocr/openrec/postprocess/igtr_postprocess.py +100 -0
- openocr/openrec/postprocess/lister_postprocess.py +59 -0
- openocr/openrec/postprocess/mgp_postprocess.py +143 -0
- openocr/openrec/postprocess/nrtr_postprocess.py +75 -0
- openocr/openrec/postprocess/smtr_postprocess.py +73 -0
- openocr/openrec/postprocess/srn_postprocess.py +80 -0
- openocr/openrec/postprocess/visionlan_postprocess.py +81 -0
- openocr/openrec/preprocess/__init__.py +173 -0
- openocr/openrec/preprocess/abinet_aug.py +473 -0
- openocr/openrec/preprocess/abinet_label_encode.py +36 -0
- openocr/openrec/preprocess/ar_label_encode.py +36 -0
- openocr/openrec/preprocess/auto_augment.py +1012 -0
- openocr/openrec/preprocess/cam_label_encode.py +141 -0
- openocr/openrec/preprocess/ce_label_encode.py +116 -0
- openocr/openrec/preprocess/char_label_encode.py +36 -0
- openocr/openrec/preprocess/cppd_label_encode.py +173 -0
- openocr/openrec/preprocess/ctc_label_encode.py +124 -0
- openocr/openrec/preprocess/ep_label_encode.py +38 -0
- openocr/openrec/preprocess/igtr_label_encode.py +360 -0
- openocr/openrec/preprocess/mgp_label_encode.py +95 -0
- openocr/openrec/preprocess/parseq_aug.py +150 -0
- openocr/openrec/preprocess/rec_aug.py +211 -0
- openocr/openrec/preprocess/resize.py +534 -0
- openocr/openrec/preprocess/smtr_label_encode.py +125 -0
- openocr/openrec/preprocess/srn_label_encode.py +37 -0
- openocr/openrec/preprocess/visionlan_label_encode.py +67 -0
- openocr/tools/create_lmdb_dataset.py +118 -0
- openocr/tools/data/__init__.py +94 -0
- openocr/tools/data/collate_fn.py +100 -0
- openocr/tools/data/lmdb_dataset.py +142 -0
- openocr/tools/data/lmdb_dataset_test.py +166 -0
- openocr/tools/data/multi_scale_sampler.py +177 -0
- openocr/tools/data/ratio_dataset.py +217 -0
- openocr/tools/data/ratio_dataset_test.py +273 -0
- openocr/tools/data/ratio_dataset_tvresize.py +213 -0
- openocr/tools/data/ratio_dataset_tvresize_test.py +276 -0
- openocr/tools/data/ratio_sampler.py +190 -0
- openocr/tools/data/simple_dataset.py +263 -0
- openocr/tools/data/strlmdb_dataset.py +143 -0
- openocr/tools/engine/__init__.py +5 -0
- openocr/tools/engine/config.py +158 -0
- openocr/tools/engine/trainer.py +621 -0
- openocr/tools/eval_rec.py +41 -0
- openocr/tools/eval_rec_all_ch.py +184 -0
- openocr/tools/eval_rec_all_en.py +206 -0
- openocr/tools/eval_rec_all_long.py +119 -0
- openocr/tools/eval_rec_all_long_simple.py +122 -0
- openocr/tools/export_rec.py +118 -0
- openocr/tools/infer/onnx_engine.py +65 -0
- openocr/tools/infer/predict_rec.py +140 -0
- openocr/tools/infer/utility.py +234 -0
- openocr/tools/infer_det.py +449 -0
- openocr/tools/infer_e2e.py +462 -0
- openocr/tools/infer_e2e_parallel.py +184 -0
- openocr/tools/infer_rec.py +371 -0
- openocr/tools/train_rec.py +37 -0
- openocr/tools/utility.py +45 -0
- openocr/tools/utils/EN_symbol_dict.txt +94 -0
- openocr/tools/utils/__init__.py +0 -0
- openocr/tools/utils/ckpt.py +87 -0
- openocr/tools/utils/dict/ar_dict.txt +117 -0
- openocr/tools/utils/dict/arabic_dict.txt +161 -0
- openocr/tools/utils/dict/be_dict.txt +145 -0
- openocr/tools/utils/dict/bg_dict.txt +140 -0
- openocr/tools/utils/dict/chinese_cht_dict.txt +8421 -0
- openocr/tools/utils/dict/cyrillic_dict.txt +163 -0
- openocr/tools/utils/dict/devanagari_dict.txt +167 -0
- openocr/tools/utils/dict/en_dict.txt +63 -0
- openocr/tools/utils/dict/fa_dict.txt +136 -0
- openocr/tools/utils/dict/french_dict.txt +136 -0
- openocr/tools/utils/dict/german_dict.txt +143 -0
- openocr/tools/utils/dict/hi_dict.txt +162 -0
- openocr/tools/utils/dict/it_dict.txt +118 -0
- openocr/tools/utils/dict/japan_dict.txt +4399 -0
- openocr/tools/utils/dict/ka_dict.txt +153 -0
- openocr/tools/utils/dict/kie_dict/xfund_class_list.txt +4 -0
- openocr/tools/utils/dict/korean_dict.txt +3688 -0
- openocr/tools/utils/dict/latex_symbol_dict.txt +111 -0
- openocr/tools/utils/dict/latin_dict.txt +185 -0
- openocr/tools/utils/dict/layout_dict/layout_cdla_dict.txt +10 -0
- openocr/tools/utils/dict/layout_dict/layout_publaynet_dict.txt +5 -0
- openocr/tools/utils/dict/layout_dict/layout_table_dict.txt +1 -0
- openocr/tools/utils/dict/mr_dict.txt +153 -0
- openocr/tools/utils/dict/ne_dict.txt +153 -0
- openocr/tools/utils/dict/oc_dict.txt +96 -0
- openocr/tools/utils/dict/pu_dict.txt +130 -0
- openocr/tools/utils/dict/rs_dict.txt +91 -0
- openocr/tools/utils/dict/rsc_dict.txt +134 -0
- openocr/tools/utils/dict/ru_dict.txt +125 -0
- openocr/tools/utils/dict/spin_dict.txt +68 -0
- openocr/tools/utils/dict/ta_dict.txt +128 -0
- openocr/tools/utils/dict/table_dict.txt +277 -0
- openocr/tools/utils/dict/table_master_structure_dict.txt +39 -0
- openocr/tools/utils/dict/table_structure_dict.txt +28 -0
- openocr/tools/utils/dict/table_structure_dict_ch.txt +48 -0
- openocr/tools/utils/dict/te_dict.txt +151 -0
- openocr/tools/utils/dict/ug_dict.txt +114 -0
- openocr/tools/utils/dict/uk_dict.txt +142 -0
- openocr/tools/utils/dict/ur_dict.txt +137 -0
- openocr/tools/utils/dict/xi_dict.txt +110 -0
- openocr/tools/utils/dict90.txt +90 -0
- openocr/tools/utils/e2e_metric/Deteval.py +802 -0
- openocr/tools/utils/e2e_metric/polygon_fast.py +70 -0
- openocr/tools/utils/e2e_utils/extract_batchsize.py +86 -0
- openocr/tools/utils/e2e_utils/extract_textpoint_fast.py +479 -0
- openocr/tools/utils/e2e_utils/extract_textpoint_slow.py +582 -0
- openocr/tools/utils/e2e_utils/pgnet_pp_utils.py +159 -0
- openocr/tools/utils/e2e_utils/visual.py +152 -0
- openocr/tools/utils/en_dict.txt +95 -0
- openocr/tools/utils/gen_label.py +68 -0
- openocr/tools/utils/ic15_dict.txt +36 -0
- openocr/tools/utils/logging.py +56 -0
- openocr/tools/utils/poly_nms.py +132 -0
- openocr/tools/utils/ppocr_keys_v1.txt +6623 -0
- openocr/tools/utils/stats.py +58 -0
- openocr/tools/utils/utility.py +165 -0
- openocr/tools/utils/visual.py +117 -0
- openocr_python-0.0.2.dist-info/LICENCE +201 -0
- openocr_python-0.0.2.dist-info/METADATA +98 -0
- openocr_python-0.0.2.dist-info/RECORD +323 -0
- openocr_python-0.0.2.dist-info/WHEEL +5 -0
- openocr_python-0.0.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import numpy as np
|
|
3
|
+
import datetime
|
|
4
|
+
|
|
5
|
+
__all__ = ["TrainingStats", "Time"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SmoothedValue(object):
|
|
9
|
+
"""Track a series of values and provide access to smoothed values over a
|
|
10
|
+
window or the global series average.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, window_size):
|
|
14
|
+
self.deque = collections.deque(maxlen=window_size)
|
|
15
|
+
|
|
16
|
+
def add_value(self, value):
|
|
17
|
+
self.deque.append(value)
|
|
18
|
+
|
|
19
|
+
def get_median_value(self):
|
|
20
|
+
return np.median(self.deque)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def Time():
|
|
24
|
+
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TrainingStats(object):
|
|
28
|
+
def __init__(self, window_size, stats_keys):
|
|
29
|
+
self.window_size = window_size
|
|
30
|
+
self.smoothed_losses_and_metrics = {
|
|
31
|
+
key: SmoothedValue(window_size)
|
|
32
|
+
for key in stats_keys
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
def update(self, stats):
|
|
36
|
+
for k, v in stats.items():
|
|
37
|
+
if k not in self.smoothed_losses_and_metrics:
|
|
38
|
+
self.smoothed_losses_and_metrics[k] = SmoothedValue(
|
|
39
|
+
self.window_size)
|
|
40
|
+
self.smoothed_losses_and_metrics[k].add_value(v)
|
|
41
|
+
|
|
42
|
+
def get(self, extras=None):
|
|
43
|
+
stats = collections.OrderedDict()
|
|
44
|
+
if extras:
|
|
45
|
+
for k, v in extras.items():
|
|
46
|
+
stats[k] = v
|
|
47
|
+
for k, v in self.smoothed_losses_and_metrics.items():
|
|
48
|
+
stats[k] = round(v.get_median_value(), 6)
|
|
49
|
+
|
|
50
|
+
return stats
|
|
51
|
+
|
|
52
|
+
def log(self, extras=None):
|
|
53
|
+
d = self.get(extras)
|
|
54
|
+
strs = []
|
|
55
|
+
for k, v in d.items():
|
|
56
|
+
strs.append("{}: {:x<6f}".format(k, v))
|
|
57
|
+
strs = ", ".join(strs)
|
|
58
|
+
return strs
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import cv2
|
|
4
|
+
import numpy as np
|
|
5
|
+
import importlib.util
|
|
6
|
+
import sys
|
|
7
|
+
import subprocess
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_check_global_params(mode):
|
|
11
|
+
check_params = [
|
|
12
|
+
"use_gpu",
|
|
13
|
+
"max_text_length",
|
|
14
|
+
"image_shape",
|
|
15
|
+
"image_shape",
|
|
16
|
+
"character_type",
|
|
17
|
+
"loss_type",
|
|
18
|
+
]
|
|
19
|
+
if mode == "train_eval":
|
|
20
|
+
check_params = check_params + [
|
|
21
|
+
"train_batch_size_per_card",
|
|
22
|
+
"test_batch_size_per_card",
|
|
23
|
+
]
|
|
24
|
+
elif mode == "test":
|
|
25
|
+
check_params = check_params + ["test_batch_size_per_card"]
|
|
26
|
+
return check_params
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _check_image_file(path):
|
|
30
|
+
img_end = {"jpg", "bmp", "png", "jpeg", "rgb", "tif", "tiff", "gif", "pdf"}
|
|
31
|
+
return any([path.lower().endswith(e) for e in img_end])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_image_file_list(img_file):
|
|
35
|
+
imgs_lists = []
|
|
36
|
+
if img_file is None or not os.path.exists(img_file):
|
|
37
|
+
raise Exception("not found any img file in {}".format(img_file))
|
|
38
|
+
|
|
39
|
+
if os.path.isfile(img_file) and _check_image_file(img_file):
|
|
40
|
+
imgs_lists.append(img_file)
|
|
41
|
+
elif os.path.isdir(img_file):
|
|
42
|
+
for single_file in os.listdir(img_file):
|
|
43
|
+
file_path = os.path.join(img_file, single_file)
|
|
44
|
+
if os.path.isfile(file_path) and _check_image_file(file_path):
|
|
45
|
+
imgs_lists.append(file_path)
|
|
46
|
+
if len(imgs_lists) == 0:
|
|
47
|
+
raise Exception("not found any img file in {}".format(img_file))
|
|
48
|
+
imgs_lists = sorted(imgs_lists)
|
|
49
|
+
return imgs_lists
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def binarize_img(img):
|
|
53
|
+
if len(img.shape) == 3 and img.shape[2] == 3:
|
|
54
|
+
gray = cv2.cvtColor(img,
|
|
55
|
+
cv2.COLOR_BGR2GRAY) # conversion to grayscale image
|
|
56
|
+
# use cv2 threshold binarization
|
|
57
|
+
_, gray = cv2.threshold(gray, 0, 255,
|
|
58
|
+
cv2.THRESH_BINARY + cv2.THRESH_OTSU)
|
|
59
|
+
img = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)
|
|
60
|
+
return img
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def alpha_to_color(img, alpha_color=(255, 255, 255)):
|
|
64
|
+
if len(img.shape) == 3 and img.shape[2] == 4:
|
|
65
|
+
B, G, R, A = cv2.split(img)
|
|
66
|
+
alpha = A / 255
|
|
67
|
+
|
|
68
|
+
R = (alpha_color[0] * (1 - alpha) + R * alpha).astype(np.uint8)
|
|
69
|
+
G = (alpha_color[1] * (1 - alpha) + G * alpha).astype(np.uint8)
|
|
70
|
+
B = (alpha_color[2] * (1 - alpha) + B * alpha).astype(np.uint8)
|
|
71
|
+
|
|
72
|
+
img = cv2.merge((B, G, R))
|
|
73
|
+
return img
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def check_and_read(img_path):
|
|
77
|
+
if os.path.basename(img_path)[-3:].lower() == "gif":
|
|
78
|
+
gif = cv2.VideoCapture(img_path)
|
|
79
|
+
ret, frame = gif.read()
|
|
80
|
+
if not ret:
|
|
81
|
+
logger = logging.getLogger("openrec")
|
|
82
|
+
logger.info("Cannot read {}. This gif image maybe corrupted.")
|
|
83
|
+
return None, False
|
|
84
|
+
if len(frame.shape) == 2 or frame.shape[-1] == 1:
|
|
85
|
+
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
|
|
86
|
+
imgvalue = frame[:, :, ::-1]
|
|
87
|
+
return imgvalue, True, False
|
|
88
|
+
elif os.path.basename(img_path)[-3:].lower() == "pdf":
|
|
89
|
+
import fitz
|
|
90
|
+
from PIL import Image
|
|
91
|
+
|
|
92
|
+
imgs = []
|
|
93
|
+
with fitz.open(img_path) as pdf:
|
|
94
|
+
for pg in range(0, pdf.page_count):
|
|
95
|
+
page = pdf[pg]
|
|
96
|
+
mat = fitz.Matrix(2, 2)
|
|
97
|
+
pm = page.get_pixmap(matrix=mat, alpha=False)
|
|
98
|
+
|
|
99
|
+
# if width or height > 2000 pixels, don't enlarge the image
|
|
100
|
+
if pm.width > 2000 or pm.height > 2000:
|
|
101
|
+
pm = page.get_pixmap(matrix=fitz.Matrix(1, 1), alpha=False)
|
|
102
|
+
|
|
103
|
+
img = Image.frombytes("RGB", [pm.width, pm.height], pm.samples)
|
|
104
|
+
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
|
105
|
+
imgs.append(img)
|
|
106
|
+
return imgs, False, True
|
|
107
|
+
return None, False, False
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def load_vqa_bio_label_maps(label_map_path):
|
|
111
|
+
with open(label_map_path, "r", encoding="utf-8") as fin:
|
|
112
|
+
lines = fin.readlines()
|
|
113
|
+
old_lines = [line.strip() for line in lines]
|
|
114
|
+
lines = ["O"]
|
|
115
|
+
for line in old_lines:
|
|
116
|
+
# "O" has already been in lines
|
|
117
|
+
if line.upper() in ["OTHER", "OTHERS", "IGNORE"]:
|
|
118
|
+
continue
|
|
119
|
+
lines.append(line)
|
|
120
|
+
labels = ["O"]
|
|
121
|
+
for line in lines[1:]:
|
|
122
|
+
labels.append("B-" + line)
|
|
123
|
+
labels.append("I-" + line)
|
|
124
|
+
label2id_map = {label.upper(): idx for idx, label in enumerate(labels)}
|
|
125
|
+
id2label_map = {idx: label.upper() for idx, label in enumerate(labels)}
|
|
126
|
+
return label2id_map, id2label_map
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def check_install(module_name, install_name):
|
|
130
|
+
spec = importlib.util.find_spec(module_name)
|
|
131
|
+
if spec is None:
|
|
132
|
+
print(f"Warnning! The {module_name} module is NOT installed")
|
|
133
|
+
print(
|
|
134
|
+
f"Try install {module_name} module automatically. You can also try to install manually by pip install {install_name}."
|
|
135
|
+
)
|
|
136
|
+
python = sys.executable
|
|
137
|
+
try:
|
|
138
|
+
subprocess.check_call(
|
|
139
|
+
[python, "-m", "pip", "install", install_name],
|
|
140
|
+
stdout=subprocess.DEVNULL, )
|
|
141
|
+
print(f"The {module_name} module is now installed")
|
|
142
|
+
except subprocess.CalledProcessError as exc:
|
|
143
|
+
raise Exception(
|
|
144
|
+
f"Install {module_name} failed, please install manually")
|
|
145
|
+
else:
|
|
146
|
+
print(f"{module_name} has been installed.")
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class AverageMeter:
|
|
150
|
+
def __init__(self):
|
|
151
|
+
self.reset()
|
|
152
|
+
|
|
153
|
+
def reset(self):
|
|
154
|
+
"""reset"""
|
|
155
|
+
self.val = 0
|
|
156
|
+
self.avg = 0
|
|
157
|
+
self.sum = 0
|
|
158
|
+
self.count = 0
|
|
159
|
+
|
|
160
|
+
def update(self, val, n=1):
|
|
161
|
+
"""update"""
|
|
162
|
+
self.val = val
|
|
163
|
+
self.sum += val * n
|
|
164
|
+
self.count += n
|
|
165
|
+
self.avg = self.sum / self.count
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import random
|
|
3
|
+
import math
|
|
4
|
+
import numpy as np
|
|
5
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
6
|
+
|
|
7
|
+
__all__ = ["draw_system", "draw_det"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def draw_det(dt_boxes, img):
|
|
11
|
+
for box in dt_boxes:
|
|
12
|
+
box = np.array(box).astype(np.int32).reshape(-1, 2)
|
|
13
|
+
cv2.polylines(img, [box], True, color=(255, 255, 0), thickness=2)
|
|
14
|
+
return img
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def draw_system(
|
|
18
|
+
image,
|
|
19
|
+
boxes,
|
|
20
|
+
txts=None,
|
|
21
|
+
scores=None,
|
|
22
|
+
drop_score=0.5,
|
|
23
|
+
font_path="./doc/fonts/simfang.ttf", ):
|
|
24
|
+
h, w = image.height, image.width
|
|
25
|
+
img_left = image.copy()
|
|
26
|
+
img_right = np.ones((h, w, 3), dtype=np.uint8) * 255
|
|
27
|
+
random.seed(0)
|
|
28
|
+
|
|
29
|
+
draw_left = ImageDraw.Draw(img_left)
|
|
30
|
+
if txts is None or len(txts) != len(boxes):
|
|
31
|
+
txts = [None] * len(boxes)
|
|
32
|
+
for idx, (box, txt) in enumerate(zip(boxes, txts)):
|
|
33
|
+
if scores is not None and scores[idx] < drop_score:
|
|
34
|
+
continue
|
|
35
|
+
color = (random.randint(0, 255), random.randint(0, 255),
|
|
36
|
+
random.randint(0, 255))
|
|
37
|
+
draw_left.polygon(box, fill=color)
|
|
38
|
+
img_right_text = draw_box_txt_fine((w, h), box, txt, font_path)
|
|
39
|
+
pts = np.array(box, np.int32).reshape((-1, 1, 2))
|
|
40
|
+
cv2.polylines(img_right_text, [pts], True, color, 1)
|
|
41
|
+
img_right = cv2.bitwise_and(img_right, img_right_text)
|
|
42
|
+
img_left = Image.blend(image, img_left, 0.5)
|
|
43
|
+
img_show = Image.new("RGB", (w * 2, h), (255, 255, 255))
|
|
44
|
+
img_show.paste(img_left, (0, 0, w, h))
|
|
45
|
+
img_show.paste(Image.fromarray(img_right), (w, 0, w * 2, h))
|
|
46
|
+
return np.array(img_show)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def draw_box_txt_fine(img_size, box, txt, font_path="./doc/fonts/simfang.ttf"):
|
|
50
|
+
box_height = int(
|
|
51
|
+
math.sqrt((box[0][0] - box[3][0])**2 + (box[0][1] - box[3][1])**2))
|
|
52
|
+
box_width = int(
|
|
53
|
+
math.sqrt((box[0][0] - box[1][0])**2 + (box[0][1] - box[1][1])**2))
|
|
54
|
+
|
|
55
|
+
if box_height > 2 * box_width and box_height > 30:
|
|
56
|
+
img_text = Image.new("RGB", (box_height, box_width), (255, 255, 255))
|
|
57
|
+
draw_text = ImageDraw.Draw(img_text)
|
|
58
|
+
if txt:
|
|
59
|
+
font = create_font(txt, (box_height, box_width), font_path)
|
|
60
|
+
draw_text.text([0, 0], txt, fill=(0, 0, 0), font=font)
|
|
61
|
+
img_text = img_text.transpose(Image.ROTATE_270)
|
|
62
|
+
else:
|
|
63
|
+
img_text = Image.new("RGB", (box_width, box_height), (255, 255, 255))
|
|
64
|
+
draw_text = ImageDraw.Draw(img_text)
|
|
65
|
+
if txt:
|
|
66
|
+
font = create_font(txt, (box_width, box_height), font_path)
|
|
67
|
+
draw_text.text([0, 0], txt, fill=(0, 0, 0), font=font)
|
|
68
|
+
|
|
69
|
+
pts1 = np.float32(
|
|
70
|
+
[[0, 0], [box_width, 0], [box_width, box_height], [0, box_height]])
|
|
71
|
+
pts2 = np.array(box, dtype=np.float32)
|
|
72
|
+
M = cv2.getPerspectiveTransform(pts1, pts2)
|
|
73
|
+
|
|
74
|
+
img_text = np.array(img_text, dtype=np.uint8)
|
|
75
|
+
img_right_text = cv2.warpPerspective(
|
|
76
|
+
img_text,
|
|
77
|
+
M,
|
|
78
|
+
img_size,
|
|
79
|
+
flags=cv2.INTER_NEAREST,
|
|
80
|
+
borderMode=cv2.BORDER_CONSTANT,
|
|
81
|
+
borderValue=(255, 255, 255), )
|
|
82
|
+
return img_right_text
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def create_font(txt, sz, font_path="./doc/fonts/simfang.ttf"):
|
|
86
|
+
font_size = int(sz[1] * 0.99)
|
|
87
|
+
font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
|
|
88
|
+
length = font.getlength(txt)
|
|
89
|
+
if length > sz[0]:
|
|
90
|
+
font_size = int(font_size * sz[0] / length)
|
|
91
|
+
font = ImageFont.truetype(font_path, font_size, encoding="utf-8")
|
|
92
|
+
return font
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def str_count(s):
|
|
96
|
+
"""
|
|
97
|
+
Count the number of Chinese characters,
|
|
98
|
+
a single English character and a single number
|
|
99
|
+
equal to half the length of Chinese characters.
|
|
100
|
+
args:
|
|
101
|
+
s(string): the input of string
|
|
102
|
+
return(int):
|
|
103
|
+
the number of Chinese characters
|
|
104
|
+
"""
|
|
105
|
+
import string
|
|
106
|
+
|
|
107
|
+
count_zh = count_pu = 0
|
|
108
|
+
s_len = len(s)
|
|
109
|
+
en_dg_count = 0
|
|
110
|
+
for c in s:
|
|
111
|
+
if c in string.ascii_letters or c.isdigit() or c.isspace():
|
|
112
|
+
en_dg_count += 1
|
|
113
|
+
elif c.isalpha():
|
|
114
|
+
count_zh += 1
|
|
115
|
+
else:
|
|
116
|
+
count_pu += 1
|
|
117
|
+
return s_len - math.ceil(en_dg_count / 2)
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: openocr-python
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: a python package for openocr, which is used to help developers quickly deploy OCR algorithms implemented in the openocr framework.
|
|
5
|
+
Home-page: https://github.com/Topdu/OpenOCR
|
|
6
|
+
Author: OpenOCR
|
|
7
|
+
Author-email: 784990967@qq.com
|
|
8
|
+
Project-URL: Source Code, https://github.com/Topdu/OpenOCR
|
|
9
|
+
Keywords: python,OCR,STR,OpenOCR,openocr
|
|
10
|
+
Classifier: Development Status :: 1 - Planning
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: Unix
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENCE
|
|
17
|
+
Requires-Dist: opencv-python<=4.6.0.66
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Requires-Dist: rapidfuzz
|
|
20
|
+
Requires-Dist: lmdb
|
|
21
|
+
Requires-Dist: imgaug
|
|
22
|
+
Requires-Dist: pyyaml
|
|
23
|
+
Requires-Dist: pyclipper
|
|
24
|
+
|
|
25
|
+
# OpenOCR: a general OCR system with accuracy and efficiency
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Dependencies:
|
|
30
|
+
|
|
31
|
+
- [PyTorch](http://pytorch.org/) version >= 1.13.0
|
|
32
|
+
- Python version >= 3.7
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
conda create -n openocr python==3.8
|
|
36
|
+
conda activate openocr
|
|
37
|
+
conda install pytorch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 pytorch-cuda=11.8 -c pytorch -c nvidia
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
After installing dependencies, the following two installation methods are available. Either one can be chosen.
|
|
41
|
+
|
|
42
|
+
### 1. Python Modules
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
pip install openocr-python
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Usage**:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from openocr import OpenOCR
|
|
52
|
+
|
|
53
|
+
engine = OpenOCR()
|
|
54
|
+
|
|
55
|
+
img_path = '/path/img_path or /path/img_file'
|
|
56
|
+
result, elapse = engine(img_path)
|
|
57
|
+
|
|
58
|
+
# Server mode
|
|
59
|
+
# engine = OpenOCR(mode='server')
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 2. Clone this repository:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
git clone https://github.com/Topdu/OpenOCR.git
|
|
66
|
+
cd OpenOCR
|
|
67
|
+
pip install -r requirements.txt
|
|
68
|
+
wget https://github.com/Topdu/OpenOCR/releases/download/develop0.0.1/openocr_det_repvit_ch.pth
|
|
69
|
+
wget https://github.com/Topdu/OpenOCR/releases/download/develop0.0.1/openocr_repsvtr_ch.pth
|
|
70
|
+
# Rec Server model
|
|
71
|
+
# wget https://github.com/Topdu/OpenOCR/releases/download/develop0.0.1/openocr_svtrv2_ch.pth
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Usage**:
|
|
75
|
+
|
|
76
|
+
```shell
|
|
77
|
+
# OpenOCR system: Det + Rec model
|
|
78
|
+
python tools/infer_e2e.py --img_path=/path/img_fold or /path/img_file
|
|
79
|
+
|
|
80
|
+
# Det model
|
|
81
|
+
python tools/infer_det.py --c ./configs/det/dbnet/repvit_db.yml --o Global.infer_img=/path/img_fold or /path/img_file
|
|
82
|
+
|
|
83
|
+
# Rec model
|
|
84
|
+
python tools/infer_rec.py --c ./configs/rec/svtrv2/repsvtr_ch.yml --o Global.infer_img=/path/img_fold or /path/img_file
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Demo
|
|
88
|
+
|
|
89
|
+
```shell
|
|
90
|
+
pip install gradio==4.20.0
|
|
91
|
+
wget https://github.com/Topdu/OpenOCR/releases/download/develop0.0.1/OCR_e2e_img.tar
|
|
92
|
+
tar xf OCR_e2e_img.tar
|
|
93
|
+
# start demo
|
|
94
|
+
python demo_gradio.py
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## More detail in [OpenOCR Documentation](https://github.com/Topdu/OpenOCR)
|