Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
refactor(model): update OCR model and remove unused configs
myhlolic45a706ca8d9
diff --git a/README_zh-CN.md b/README_zh-CN.mdindex 10a602f4..446d7ee5 100644--- a/README_zh-CN.md+++ b/README_zh-CN.md@@ -216,7 +216,7 @@ https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c</tr><tr><td colspan="3">python版本</td>- <td colspan="3">3.10 (请务必通过conda创建3.10虚拟环境)</td>+ <td colspan="3">>=3.9,<=3.12</td></tr><tr><td colspan="3">Nvidia Driver 版本</td>@@ -226,8 +226,8 @@ https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c</tr><tr><td colspan="3">CUDA环境</td>- <td>自动安装[12.1(pytorch)+11.8(paddle)]</td>- <td>11.8(手动安装)+cuDNN v8.7.0(手动安装)</td>+ <td>11.8/12.4/12.6</td>+ <td>11.8/12.4/12.6</td><td>None</td></tr><tr>@@ -237,12 +237,12 @@ https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c<td>None</td></tr><tr>- <td rowspan="2">GPU硬件支持列表</td>- <td colspan="2">显存8G以上</td>+ <td rowspan="2">GPU/MPS 硬件支持列表</td>+ <td colspan="2">显存6G以上</td><td colspan="2">- 2080~2080Ti / 3060Ti~3090Ti / 4060~4090<br>- 8G显存及以上可开启全部加速功能</td>- <td rowspan="2">None</td>+ Volta(2017)及之后生产的全部带Tensor Core的GPU <br>+ 6G显存及以上</td>+ <td rowspan="2">apple slicon</td></tr></table>@@ -262,9 +262,9 @@ https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c> 最新版本国内镜像源同步可能会有延迟,请耐心等待```bash-conda create -n mineru python=3.10+conda create -n mineru 'python<3.13' -yconda activate mineru-pip install -U "magic-pdf[full]" --extra-index-url https://wheels.myhloli.com -i https://mirrors.aliyun.com/pypi/simple+pip install -U "magic-pdf[full]" -i https://mirrors.aliyun.com/pypi/simple```#### 2. 下载模型权重文件diff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorch_paddle.py b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorch_paddle.pyindex 4f62ca92..316b5f9d 100644--- a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorch_paddle.py+++ b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorch_paddle.py@@ -63,14 +63,14 @@ class PytorchPaddleOCR(TextSystem):else:pass- models_config_path = os.path.join(root_dir, 'models_config.yml')+ models_config_path = os.path.join(root_dir, 'pytorchocr', 'utils', 'resources', 'models_config.yml')with open(models_config_path) as file:config = yaml.safe_load(file)det, rec, dict_file = get_model_params(self.lang, config)ocr_models_dir = os.path.join(get_local_models_dir(), 'OCR', 'paddleocr_torch')kwargs['det_model_path'] = os.path.join(ocr_models_dir, det)kwargs['rec_model_path'] = os.path.join(ocr_models_dir, rec)- kwargs['rec_char_dict_path'] = os.path.join(root_dir, 'pytorchocr', 'utils', 'dict', dict_file)+ kwargs['rec_char_dict_path'] = os.path.join(root_dir, 'pytorchocr', 'utils', 'resources', 'dict', dict_file)kwargs['device'] = get_device()diff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/arabic_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/arabic_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/arabic_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/arabic_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/chinese_cht_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/chinese_cht_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/chinese_cht_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/chinese_cht_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/cyrillic_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/cyrillic_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/cyrillic_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/cyrillic_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/devanagari_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/devanagari_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/devanagari_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/devanagari_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/en_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/en_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/en_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/en_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/japan_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/japan_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/japan_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/japan_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/ka_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/ka_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/ka_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/ka_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/korean_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/korean_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/korean_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/korean_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/latin_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/latin_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/latin_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/latin_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/ppocr_keys_v1.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/ppocr_keys_v1.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/ppocr_keys_v1.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/ppocr_keys_v1.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/ta_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/ta_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/ta_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/ta_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/te_dict.txt b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/te_dict.txtsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/dict/te_dict.txtrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/dict/te_dict.txtdiff --git a/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/models_config.yml b/magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/models_config.ymlsimilarity index 100%rename from magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/models_config.ymlrename to magic_pdf/model/sub_modules/ocr/paddleocr2pytorch/pytorchocr/utils/resources/models_config.ymldiff --git a/magic_pdf/resources/model_config/UniMERNet/demo.yaml b/magic_pdf/resources/model_config/UniMERNet/demo.yamldeleted file mode 100644index de83b07a..00000000--- a/magic_pdf/resources/model_config/UniMERNet/demo.yaml+++ /dev/null@@ -1,46 +0,0 @@-model:- arch: unimernet- model_type: unimernet- model_config:- model_name: ./models/unimernet_base- max_seq_len: 1536-- load_pretrained: True- pretrained: './models/unimernet_base/pytorch_model.pth'- tokenizer_config:- path: ./models/unimernet_base--datasets:- formula_rec_eval:- vis_processor:- eval:- name: "formula_image_eval"- image_size:- - 192- - 672--run:- runner: runner_iter- task: unimernet_train-- batch_size_train: 64- batch_size_eval: 64- num_workers: 1-- iters_per_inner_epoch: 2000- max_iters: 60000-- seed: 42- output_dir: "../output/demo"-- evaluate: True- test_splits: [ "eval" ]-- device: "cuda"- world_size: 1- dist_url: "env://"- distributed: True- distributed_type: ddp # or fsdp when train llm-- generate_cfg:- temperature: 0.0\ No newline at end of filediff --git a/magic_pdf/resources/model_config/layoutlmv3/layoutlmv3_base_inference.yaml b/magic_pdf/resources/model_config/layoutlmv3/layoutlmv3_base_inference.yamldeleted file mode 100644index 3e0fd309..00000000--- a/magic_pdf/resources/model_config/layoutlmv3/layoutlmv3_base_inference.yaml+++ /dev/null@@ -1,351 +0,0 @@-AUG:- DETR: true-CACHE_DIR: ~/cache/huggingface-CUDNN_BENCHMARK: false-DATALOADER:- ASPECT_RATIO_GROUPING: true- FILTER_EMPTY_ANNOTATIONS: false- NUM_WORKERS: 4- REPEAT_THRESHOLD: 0.0- SAMPLER_TRAIN: TrainingSampler-DATASETS:- PRECOMPUTED_PROPOSAL_TOPK_TEST: 1000- PRECOMPUTED_PROPOSAL_TOPK_TRAIN: 2000- PROPOSAL_FILES_TEST: []- PROPOSAL_FILES_TRAIN: []- TEST:- - scihub_train- TRAIN:- - scihub_train-GLOBAL:- HACK: 1.0-ICDAR_DATA_DIR_TEST: ''-ICDAR_DATA_DIR_TRAIN: ''-INPUT:- CROP:- ENABLED: true- SIZE:- - 384- - 600- TYPE: absolute_range- FORMAT: RGB- MASK_FORMAT: polygon- MAX_SIZE_TEST: 1333- MAX_SIZE_TRAIN: 1333- MIN_SIZE_TEST: 800- MIN_SIZE_TRAIN:- - 480- - 512- - 544- - 576- - 608- - 640- - 672- - 704- - 736- - 768- - 800- MIN_SIZE_TRAIN_SAMPLING: choice- RANDOM_FLIP: horizontal-MODEL:- ANCHOR_GENERATOR:- ANGLES:- - - -90- - 0- - 90- ASPECT_RATIOS:- - - 0.5- - 1.0- - 2.0- NAME: DefaultAnchorGenerator- OFFSET: 0.0- SIZES:- - - 32- - - 64- - - 128- - - 256- - - 512- BACKBONE:- FREEZE_AT: 2- NAME: build_vit_fpn_backbone- CONFIG_PATH: ''- DEVICE: cuda- FPN:- FUSE_TYPE: sum- IN_FEATURES:- - layer3- - layer5- - layer7- - layer11- NORM: ''- OUT_CHANNELS: 256- IMAGE_ONLY: true- KEYPOINT_ON: false- LOAD_PROPOSALS: false- MASK_ON: true- META_ARCHITECTURE: VLGeneralizedRCNN- PANOPTIC_FPN:- COMBINE:- ENABLED: true- INSTANCES_CONFIDENCE_THRESH: 0.5- OVERLAP_THRESH: 0.5- STUFF_AREA_LIMIT: 4096- INSTANCE_LOSS_WEIGHT: 1.0- PIXEL_MEAN:- - 127.5- - 127.5- - 127.5- PIXEL_STD:- - 127.5- - 127.5- - 127.5- PROPOSAL_GENERATOR:- MIN_SIZE: 0- NAME: RPN- RESNETS:- DEFORM_MODULATED: false- DEFORM_NUM_GROUPS: 1- DEFORM_ON_PER_STAGE:- - false- - false- - false- - false- DEPTH: 50- NORM: FrozenBN- NUM_GROUPS: 1- OUT_FEATURES:- - res4- RES2_OUT_CHANNELS: 256- RES5_DILATION: 1- STEM_OUT_CHANNELS: 64- STRIDE_IN_1X1: true- WIDTH_PER_GROUP: 64- RETINANET:- BBOX_REG_LOSS_TYPE: smooth_l1- BBOX_REG_WEIGHTS:- - 1.0- - 1.0- - 1.0- - 1.0- FOCAL_LOSS_ALPHA: 0.25- FOCAL_LOSS_GAMMA: 2.0- IN_FEATURES:- - p3- - p4- - p5- - p6- - p7- IOU_LABELS:- - 0- - -1- - 1- IOU_THRESHOLDS:- - 0.4- - 0.5- NMS_THRESH_TEST: 0.5- NORM: ''- NUM_CLASSES: 10- NUM_CONVS: 4- PRIOR_PROB: 0.01- SCORE_THRESH_TEST: 0.05- SMOOTH_L1_LOSS_BETA: 0.1- TOPK_CANDIDATES_TEST: 1000- ROI_BOX_CASCADE_HEAD:- BBOX_REG_WEIGHTS:- - - 10.0- - 10.0- - 5.0- - 5.0- - - 20.0- - 20.0- - 10.0- - 10.0- - - 30.0- - 30.0- - 15.0- - 15.0- IOUS:- - 0.5- - 0.6- - 0.7- ROI_BOX_HEAD:- BBOX_REG_LOSS_TYPE: smooth_l1- BBOX_REG_LOSS_WEIGHT: 1.0- BBOX_REG_WEIGHTS:- - 10.0- - 10.0- - 5.0- - 5.0- CLS_AGNOSTIC_BBOX_REG: true- CONV_DIM: 256- FC_DIM: 1024- NAME: FastRCNNConvFCHead- NORM: ''- NUM_CONV: 0- NUM_FC: 2- POOLER_RESOLUTION: 7- POOLER_SAMPLING_RATIO: 0- POOLER_TYPE: ROIAlignV2- SMOOTH_L1_BETA: 0.0- TRAIN_ON_PRED_BOXES: false- ROI_HEADS:- BATCH_SIZE_PER_IMAGE: 512- IN_FEATURES:- - p2- - p3- - p4- - p5- IOU_LABELS:- - 0- - 1- IOU_THRESHOLDS:- - 0.5- NAME: CascadeROIHeads- NMS_THRESH_TEST: 0.5- NUM_CLASSES: 10- POSITIVE_FRACTION: 0.25- PROPOSAL_APPEND_GT: true- SCORE_THRESH_TEST: 0.05- ROI_KEYPOINT_HEAD:- CONV_DIMS:- - 512- - 512- - 512- - 512- - 512- - 512- - 512- - 512- LOSS_WEIGHT: 1.0- MIN_KEYPOINTS_PER_IMAGE: 1- NAME: KRCNNConvDeconvUpsampleHead- NORMALIZE_LOSS_BY_VISIBLE_KEYPOINTS: true- NUM_KEYPOINTS: 17- POOLER_RESOLUTION: 14- POOLER_SAMPLING_RATIO: 0- POOLER_TYPE: ROIAlignV2- ROI_MASK_HEAD:- CLS_AGNOSTIC_MASK: false- CONV_DIM: 256- NAME: MaskRCNNConvUpsampleHead- NORM: ''- NUM_CONV: 4- POOLER_RESOLUTION: 14- POOLER_SAMPLING_RATIO: 0- POOLER_TYPE: ROIAlignV2- RPN:- BATCH_SIZE_PER_IMAGE: 256- BBOX_REG_LOSS_TYPE: smooth_l1- BBOX_REG_LOSS_WEIGHT: 1.0- BBOX_REG_WEIGHTS:- - 1.0- - 1.0- - 1.0- - 1.0- BOUNDARY_THRESH: -1- CONV_DIMS:- - -1- HEAD_NAME: StandardRPNHead- IN_FEATURES:- - p2- - p3- - p4- - p5- - p6- IOU_LABELS:- - 0- - -1- - 1- IOU_THRESHOLDS:- - 0.3- - 0.7- LOSS_WEIGHT: 1.0- NMS_THRESH: 0.7- POSITIVE_FRACTION: 0.5- POST_NMS_TOPK_TEST: 1000- POST_NMS_TOPK_TRAIN: 2000- PRE_NMS_TOPK_TEST: 1000- PRE_NMS_TOPK_TRAIN: 2000- SMOOTH_L1_BETA: 0.0- SEM_SEG_HEAD:- COMMON_STRIDE: 4- CONVS_DIM: 128- IGNORE_VALUE: 255- IN_FEATURES:- - p2- - p3- - p4- - p5- LOSS_WEIGHT: 1.0- NAME: SemSegFPNHead- NORM: GN- NUM_CLASSES: 10- VIT:- DROP_PATH: 0.1- IMG_SIZE:- - 224- - 224- NAME: layoutlmv3_base- OUT_FEATURES:- - layer3- - layer5- - layer7- - layer11- POS_TYPE: abs- WEIGHTS:-OUTPUT_DIR:-SCIHUB_DATA_DIR_TRAIN: ~/publaynet/layout_scihub/train-SEED: 42-SOLVER:- AMP:- ENABLED: true- BACKBONE_MULTIPLIER: 1.0- BASE_LR: 0.0002- BIAS_LR_FACTOR: 1.0- CHECKPOINT_PERIOD: 2000- CLIP_GRADIENTS:- CLIP_TYPE: full_model- CLIP_VALUE: 1.0- ENABLED: true- NORM_TYPE: 2.0- GAMMA: 0.1- GRADIENT_ACCUMULATION_STEPS: 1- IMS_PER_BATCH: 32- LR_SCHEDULER_NAME: WarmupCosineLR- MAX_ITER: 20000- MOMENTUM: 0.9- NESTEROV: false- OPTIMIZER: ADAMW- REFERENCE_WORLD_SIZE: 0- STEPS:- - 10000- WARMUP_FACTOR: 0.01- WARMUP_ITERS: 333- WARMUP_METHOD: linear- WEIGHT_DECAY: 0.05- WEIGHT_DECAY_BIAS: null- WEIGHT_DECAY_NORM: 0.0-TEST:- AUG:- ENABLED: false- FLIP: true- MAX_SIZE: 4000- MIN_SIZES:- - 400- - 500- - 600- - 700- - 800- - 900- - 1000- - 1100- - 1200- DETECTIONS_PER_IMAGE: 100- EVAL_PERIOD: 1000- EXPECTED_RESULTS: []- KEYPOINT_OKS_SIGMAS: []- PRECISE_BN:- ENABLED: false- NUM_ITER: 200-VERSION: 2-VIS_PERIOD: 0diff --git a/setup.py b/setup.pyindex 0576d0bc..f7e7b7db 100644--- a/setup.py+++ b/setup.py@@ -26,9 +26,10 @@ if __name__ == '__main__':setup(name="magic_pdf", # 项目名version=__version__, # 自动从tag中获取版本号- packages=find_packages() + ["magic_pdf.resources"], # 包含所有的包+ packages=find_packages() + ["magic_pdf.resources"] + ["magic_pdf.model.sub_modules.ocr.paddleocr2pytorch.pytorchocr.utils.resources"], # 包含所有的包package_data={"magic_pdf.resources": ["**"], # 包含magic_pdf.resources目录下的所有文件+ "magic_pdf.model.sub_modules.ocr.paddleocr2pytorch.pytorchocr.utils.resources": ["**"], # pytorchocr.resources目录下的所有文件},install_requires=parse_requirements('requirements.txt'), # 项目依赖的第三方库extras_require={@@ -41,9 +42,10 @@ if __name__ == '__main__':"matplotlib;platform_system=='Linux' or platform_system=='Darwin'", # linux 和 macos 不应限制matplotlib的最高版本,以避免无法更新导致的一些bug"ultralytics>=8.3.48", # yolov8,公式检测"doclayout_yolo==0.0.2b1", # doclayout_yolo+ "dill", # doclayout_yolo"rapid_table>=1.0.3,<2.0.0", # rapid_table"PyYAML", # yaml- "ftfy"+ "ftfy", # unimernet_hf"openai", # openai SDK],"old_linux":[