opendatalab / MinerU

A one-stop, open-source, high-quality data extraction tool, supports PDF/webpage/e-book extraction.一站式开源高质量数据提取工具,支持PDF/网页/多格式电子书提取。
https://opendatalab.com/OpenSourceTools
GNU Affero General Public License v3.0
13.51k stars 1.02k forks source link

转换时间过慢问题 #322

Closed UFOyyds closed 2 months ago

UFOyyds commented 2 months ago

Description of the bug | 错误描述

一篇简短的PDF to markdown 等待时间有点久,不知什么原因?感谢给予指导

How to reproduce the bug | 如何复现

JSON文件中默认"max_time": 400,请问这个可以适度调节吗?

Operating system | 操作系统

Windows

Python version | Python 版本

3.10

Software version | 软件版本 (magic-pdf --version)

0.6.x

Device mode | 设备模式

cpu

myhloli commented 2 months ago

能上传一些解析过程中的日志看看具体是具体哪个步骤耗时过长吗

2257396011 commented 2 months ago

cpu是会比较慢的,你可以试试gpu环境,目前我也用的cpu,模型加载1分钟左右。不算模型加载的话使用ocr处理,一页大概要处理30-45秒,不过因为设备限制我也不确定gpu能快多少。

myhloli commented 2 months ago

cpu是会比较慢的,你可以试试gpu环境,目前我也用的cpu,模型加载1分钟左右。不算模型加载的话使用ocr处理,一页大概要处理30-45秒,不过因为设备限制我也不确定gpu能快多少。

gpu正常情况一页1~2秒左右

UFOyyds commented 2 months ago

能上传一些解析过程中的日志看看具体是具体哪个步骤耗时过长吗

`(detectron2_env) C:\Users\XXXXX>magic-pdf pdf-command --pdf "pdf_path" --inside_model true 2024-08-05 14:10:24.153 WARNING magic_pdf.cli.magicpdf:get_model_json:312 - not found json "pdf_path".json existed 2024-08-05 14:10:24.154 WARNING magic_pdf.libs.config_reader:get_local_dir:64 - 'temp-output-dir' not found in magic-pdf.json, use '/tmp' as default 2024-08-05 14:10:24.378 INFO magic_pdf.libs.pdf_check:detect_invalid_chars:57 - cid_count: 0, text_len: 2, cid_chars_radio: 0.0 2024-08-05 14:10:24.378 WARNING magic_pdf.filter.pdf_classify_by_type:classify:334 - pdf is not classified by area and text_len, by_image_area: False, by_text: False, by_avg_words: False, by_img_num: True, by_text_layout: False, by_img_narrow_strips: True, by_invalid_chars: True INFO:datasets:PyTorch version 2.3.1 available. 2024-08-05 14:10:32.531 INFO magic_pdf.model.pdf_extract_kit:init:99 - DocAnalysis init, this may take some times. apply_layout: True, apply_formula: True, apply_ocr: True 2024-08-05 14:10:32.532 INFO magic_pdf.model.pdf_extract_kit:init:107 - using device: cpu 2024-08-05 14:10:32.532 INFO magic_pdf.model.pdf_extract_kit:init:109 - using models_dir: E:\PDF-Extract-Kit\models CustomVisionEncoderDecoderModel init CustomMBartForCausalLM init CustomMBartDecoder init [08/05 14:10:55 detectron2]: Rank of current process: 0. World size: 1 [08/05 14:10:56 detectron2]: Environment info:
sys.platform win32 Python 3.10.14 packaged by Anaconda, Inc. (main, May 6 2024, 19:44:50) [MSC v.1916 64 bit (AMD64)] numpy 1.26.4 detectron2 0.6 @D:\anaconda\envs\detectron2_env\lib\site-packages\detectron2 detectron2._C not built correctly: DLL load failed while importing _C: 找不到指定的程序。 DETECTRON2_ENV_MODULE PyTorch 2.3.1+cpu @D:\anaconda\envs\detectron2_env\lib\site-packages\torch PyTorch debug build False torch._C._GLIBCXX_USE_CXX11_ABI False GPU available No: torch.cuda.is_available() == False Pillow 10.4.0 torchvision 0.18.1+cpu @D:\anaconda\envs\detectron2_env\lib\site-packages\torchvision fvcore 0.1.5.post20221221 iopath 0.1.9 cv2 4.6.0

PyTorch built with:

[08/05 14:10:56 detectron2]: Command line arguments: {'config_file': 'D:\anaconda\envs\detectron2_env\lib\site-packages\magic_pdf\resources\model_config\layoutlmv3\layoutlmv3_base_inference.yaml', 'resume': False, 'eval_only': False, 'num_gpus': 1, 'num_machines': 1, 'machine_rank': 0, 'dist_url': 'tcp://127.0.0.1:57823', 'opts': ['MODEL.WEIGHTS', 'E:\PDF-Extract-Kit\models\Layout/model_final.pth']} [08/05 14:10:56 detectron2]: Contents of args.config_file=D:\anaconda\envs\detectron2_env\lib\site-packages\magic_pdf\resources\model_config\layoutlmv3\layoutlmv3_base_inference.yaml: 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:

[08/05 14:10:58 d2.checkpoint.detection_checkpoint]: [DetectionCheckpointer] Loading from E:\PDF-Extract-Kit\models\Layout/model_final.pth ... [08/05 14:10:58 fvcore.common.checkpoint]: [Checkpointer] Loading from e:\PDF-Extract-Kit\models\Layout/model_final.pth ... 2024-08-05 14:11:00.031 | INFO | magic_pdf.model.pdf_extract_kit:init:132 - DocAnalysis init done! 2024-08-05 14:11:00.032 | INFO | magic_pdf.model.doc_analyze_by_custom_model:custom_model_init:92 - model init cost: 35.65274977684021 2024-08-05 14:11:35.095 | INFO | magic_pdf.model.pdf_extract_kit:call:143 - layout detection cost: 34.73

0: 1888x1344 (no detections), 5070.7ms Speed: 27.2ms preprocess, 5070.7ms inference, 1.0ms postprocess per image at shape (1, 3, 1888, 1344) 2024-08-05 14:11:42.570 | INFO | magic_pdf.model.pdf_extract_kit:call:173 - formula nums: 0, mfr time: 0.0 2024-08-05 14:11:50.457 | INFO | magic_pdf.model.pdf_extract_kit:call:250 - ocr cost: 7.89 2024-08-05 14:12:24.253 | INFO | magic_pdf.model.pdf_extract_kit:call:143 - layout detection cost: 33.79

0: 1888x1344 (no detections), 4877.3ms Speed: 26.4ms preprocess, 4877.3ms inference, 0.0ms postprocess per image at shape (1, 3, 1888, 1344) 2024-08-05 14:12:29.161 | INFO | magic_pdf.model.pdf_extract_kit:call:173 - formula nums: 0, mfr time: 0.0 2024-08-05 14:12:30.193 | INFO | magic_pdf.model.pdf_extract_kit:call:250 - ocr cost: 1.03 2024-08-05 14:12:30.194 | INFO | magic_pdf.model.doc_analyze_by_custom_model:doc_analyze:118 - doc analyze cost: 89.82563972473145 2024-08-05 14:12:30.260 | INFO | magic_pdf.pdf_parse_union_core:pdf_parse_union:221 - page_id: 0, last_page_cost_time: 0.0 2024-08-05 14:12:30.480 | INFO | magic_pdf.pdf_parse_union_core:pdf_parse_union:221 - page_id: 1, last_page_cost_time: 0.22 2024-08-05 14:12:30.802 | INFO | magic_pdf.para.para_split_v2:__connect_middle_align_text:682 - 1.0 2024-08-05 14:12:30.848 | INFO | magic_pdf.pipe.UNIPipe:pipe_mk_markdown:48 - uni_pipe mk mm_markdown finished 2024-08-05 14:12:30.865 | INFO | magic_pdf.pipe.UNIPipe:pipe_mk_uni_format:43 - uni_pipe mk content list finished 2024-08-05 14:12:30.867 | INFO | magic_pdf.cli.magicpdf:do_parse:165 - local output dir is '/tmp\magic-pdf\单个文件名\auto', you can found the result in it.`

myhloli commented 2 months ago

@UFOyyds 看了下你的log,一个2页的扫描版pdf,除去模型加载34秒,解析用时89秒,其中约70秒是在layout检测上,这个时间是符合预期的。使用纯cpu解析时,解析效率与cpu的核心数量和主频相关性极高。一般4核cpu单页layout时间30秒左右是正常的,8核cpu可以把这个时间缩短到15秒左右。 cpu解析方案只是为了兼容更多设备,为没有gpu设备的用户提供的一种快速体验方案,不适合在生产环境长时间和大量处理文档使用,这一点在readme中也已经做了说明。 如果需要较快的解析速度,一张大显存显卡是不可缺少的。具体显卡型号选择,可以参考

https://github.com/opendatalab/MinerU/blob/master/README_zh-CN_v2.md

中【安装前必看——软硬件环境支持说明】的表格。

UFOyyds commented 2 months ago

@UFOyyds 看了下你的log,一个2页的扫描版pdf,除去模型加载34秒,解析用时89秒,其中约70秒是在layout检测上,这个时间是符合预期的。使用纯cpu解析时,解析效率与cpu的核心数量和主频相关性极高。一般4核cpu单页layout时间30秒左右是正常的,8核cpu可以把这个时间缩短到15秒左右。 cpu解析方案只是为了兼容更多设备,为没有gpu设备的用户提供的一种快速体验方案,不适合在生产环境长时间和大量处理文档使用,这一点在readme中也已经做了说明。 如果需要较快的解析速度,一张大显存显卡是不可缺少的。具体显卡型号选择,可以参考

https://github.com/opendatalab/MinerU/blob/master/README_zh-CN_v2.md

中【安装前必看——软硬件环境支持说明】的表格。

感谢解答!

papayalove commented 2 months ago

JSON文件中默认"max_time": 400,请问这个可以适度调节吗?

这个是表格识别的超时时间,单位:s