opendatalab / PDF-Extract-Kit

A Comprehensive Toolkit for High-Quality PDF Content Extraction
https://pdf-extract-kit.readthedocs.io/zh-cn/latest/index.html
GNU Affero General Public License v3.0
5.49k stars 364 forks source link

ValueError: zero-size array to reduction operation maximum which has no identity #30

Open Sariel2018 opened 3 months ago

Sariel2018 commented 3 months ago

新装的环境,python 3.10 magic-pdf 0.6.1 detectron2 0.6 paddleocr 2.7.3 paddlepaddle 2.6.1

运行 magic-pdf pdf-command --pdf "test_pdf_files_list/test1.pdf" --inside_model true 报错如下:

2024-07-18 11:16:36.831 | INFO | magic_pdf.model.pdf_extract_kit:init:124 - DocAnalysis init done! 2024-07-18 11:16:36.831 | INFO | magic_pdf.model.doc_analyze_by_custom_model:doc_analyze:74 - model init cost: 349.3428432941437 2024-07-18 11:16:46.497 | INFO | magic_pdf.model.pdf_extract_kit:call:135 - layout detection cost: 9.25

0: 1888x1344 250 embeddings, 50 isolateds, 50.3ms Speed: 152.1ms preprocess, 50.3ms inference, 926.0ms postprocess per image at shape (1, 3, 1888, 1344) 2024-07-18 11:17:59.371 | INFO | magic_pdf.model.pdf_extract_kit:call:164 - formula nums: 300, mfr time: 65.15 2024-07-18 11:18:03.702 | INFO | magic_pdf.model.pdf_extract_kit:call:135 - layout detection cost: 4.33

0: 1888x1344 212 embeddings, 88 isolateds, 49.7ms Speed: 27.1ms preprocess, 49.7ms inference, 18.0ms postprocess per image at shape (1, 3, 1888, 1344) Traceback (most recent call last): File "/ailab/user/.conda/envs/py310/bin/magic-pdf", line 8, in sys.exit(cli()) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 783, in invoke return __callback(args, **kwargs) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/cli/magicpdf.py", line 325, in pdf_command do_parse( File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/cli/magicpdf.py", line 111, in do_parse pipe.pipe_analyze() File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/pipe/UNIPipe.py", line 29, in pipe_analyze self.model_list = doc_analyze(self.pdf_bytes, ocr=False) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/model/doc_analyze_by_custom_model.py", line 87, in doc_analyze result = custom_model(img) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/model/pdf_extract_kit.py", line 157, in call for mf_img in dataloader: File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 631, in next data = self._next_data() File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/torch/utils/data/dataloader.py", line 675, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py", line 51, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/model/pdf_extract_kit.py", line 66, in getitem image = self.transform(raw_image) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/torchvision/transforms/transforms.py", line 95, in call img = t(img) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/unimernet/processors/formula_processor.py", line 164, in call image = self.prepare_input(item) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/unimernet/processors/formula_processor.py", line 51, in prepare_input img = self.crop_margin(img.convert("RGB")) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/unimernet/processors/formula_processor.py", line 29, in crop_margin max_val = data.max() File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/numpy/core/_methods.py", line 41, in _amax return umr_maximum(a, axis, None, out, keepdims, initial, where) ValueError: zero-size array to reduction operation maximum which has no identity test1.pdf

Sariel2018 commented 3 months ago

上面使用的是device-mode"cpu",换成device-mode"cuda"后报错如下:

[07/18 13:05:39 d2.checkpoint.detection_checkpoint]: [DetectionCheckpointer] Loading from /ailab/user/PDF-Extract-Kit/models/Layout/model_final.pth ... [07/18 13:05:39 fvcore.common.checkpoint]: [Checkpointer] Loading from /ailab/user/PDF-Extract-Kit/models/Layout/model_final.pth ... 2024-07-18 13:05:39.897 | INFO | magic_pdf.model.pdf_extract_kit:init:124 - DocAnalysis init done! 2024-07-18 13:05:39.897 | INFO | magic_pdf.model.doc_analyze_by_custom_model:doc_analyze:74 - model init cost: 27.201046228408813 2024-07-18 13:05:41.121 | INFO | magic_pdf.model.pdf_extract_kit:call:135 - layout detection cost: 0.78

0: 1888x1344 300 embeddings, 50.1ms Speed: 86.1ms preprocess, 50.1ms inference, 14.2ms postprocess per image at shape (1, 3, 1888, 1344) 2024-07-18 13:06:14.461 | INFO | magic_pdf.model.pdf_extract_kit:call:164 - formula nums: 300, mfr time: 30.69 2024-07-18 13:06:14.752 | INFO | magic_pdf.model.pdf_extract_kit:call:135 - layout detection cost: 0.29

0: 1888x1344 215 embeddings, 85 isolateds, 49.4ms Speed: 13.9ms preprocess, 49.4ms inference, 38.4ms postprocess per image at shape (1, 3, 1888, 1344) Traceback (most recent call last): File "/ailab/user/.conda/envs/py310/bin/magic-pdf", line 8, in sys.exit(cli()) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/click/core.py", line 783, in invoke return __callback(args, **kwargs) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/cli/magicpdf.py", line 325, in pdf_command do_parse( File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/cli/magicpdf.py", line 111, in do_parse pipe.pipe_analyze() File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/pipe/UNIPipe.py", line 29, in pipe_analyze self.model_list = doc_analyze(self.pdf_bytes, ocr=False) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/model/doc_analyze_by_custom_model.py", line 87, in doc_analyze result = custom_model(img) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/model/pdf_extract_kit.py", line 149, in call bbox_img = get_croped_image(Image.fromarray(image), [xmin, ymin, xmax, ymax]) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/magic_pdf/model/pek_sub_modules/post_process.py", line 16, in get_croped_image croped_img = image_pil.crop((x_min, y_min, x_max, y_max)) File "/ailab/user/.conda/envs/py310/lib/python3.10/site-packages/PIL/Image.py", line 1296, in crop raise ValueError(msg) ValueError: Coordinate 'right' is less than 'left'

Sariel2018 commented 3 months ago

pillow version为 10.4.0