Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weight file includes doclayout_yolo.nn.tasks.YOLOv10DetectionModel which not in the default safe globals list #512

Open
Surinrasu opened this issue Jan 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Surinrasu
Copy link

问题描述

I just installed it and try to use it following the doc:

> OLLAMA_HOST="127.0.0.1:11434" pdf2zh -s ollama:qwen2.5:32b-instruct-q8_0 ~/Downloads/ATP_7-100.3.pdf
Traceback (most recent call last):
  File "/opt/homebrew/bin/pdf2zh", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/opt/homebrew/lib/python3.13/site-packages/pdf2zh/pdf2zh.py", line 274, in main
    extract_text(**vars(parsed_args))
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.13/site-packages/pdf2zh/pdf2zh.py", line 93, in extract_text
    model = doclayout_yolo.YOLOv10(pth)
  File "/opt/homebrew/lib/python3.13/site-packages/doclayout_yolo/models/yolov10/model.py", line 10, in __init__
    super().__init__(model=model, task=task, verbose=verbose)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.13/site-packages/doclayout_yolo/engine/model.py", line 144, in __init__
    self._load(model, task=task)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.13/site-packages/doclayout_yolo/engine/model.py", line 233, in _load
    self.model, self.ckpt = attempt_load_one_weight(weights)
                            ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/opt/homebrew/lib/python3.13/site-packages/doclayout_yolo/nn/tasks.py", line 807, in attempt_load_one_weight
    ckpt, weight = torch_safe_load(weight)  # load ckpt
                   ~~~~~~~~~~~~~~~^^^^^^^^
  File "/opt/homebrew/lib/python3.13/site-packages/doclayout_yolo/nn/tasks.py", line 733, in torch_safe_load
    ckpt = torch.load(file, map_location="cpu")
  File "/opt/homebrew/lib/python3.13/site-packages/torch/serialization.py", line 1489, in load
    raise pickle.UnpicklingError(_get_wo_message(str(e))) from None
_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. 
	(1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
	(2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.
	WeightsUnpickler error: Unsupported global: GLOBAL doclayout_yolo.nn.tasks.YOLOv10DetectionModel was not an allowed global by default. Please use `torch.serialization.add_safe_globals([YOLOv10DetectionModel])` or the `torch.serialization.safe_globals([YOLOv10DetectionModel])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.

macOS 15.2(24C101), Python 3.13.1, PyTorch 2.7.0.dev20250121, installed with pip, can be reproduced in an initial macOS container with same deps installed

测试文档

Especially considering that this issue is unrelated to the content of the doc, only the first 10 pages can be provided here:

ATP 7-100.3.pdf

@Surinrasu Surinrasu added the bug Something isn't working label Jan 22, 2025
@hellofinch
Copy link
Contributor

Interesting!
extract_text is deprecated. Which version are you using? And how do you install the pdf2zh?
As you can see here, Python 3.13 is not supported. Maybe you can degrade your Python version and try again.
BTW, 1.8.9 has some known bugs show in #488 .
If you want to use the latest version, there are three ways to fix the bug temporary.

  1. install with source code using pip install .
  2. With docker, you can apply the PR fix : prompt not work with GUI. #495 and reinstall the pdf2zh.
  3. install with pip, you should find the site-package and apply the PR montioned above to fix the bug.

have fun.

: )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants