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

_pickle.UnpicklingError: invalid load key, '<'. #180

Open
cullen122 opened this issue Apr 18, 2023 · 6 comments
Open

_pickle.UnpicklingError: invalid load key, '<'. #180

cullen122 opened this issue Apr 18, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@cullen122
Copy link

I am facing error while building the detectron2 base model from the example given in github and I receive the following error. Couldnt find any solution. Is there anyone facing this issue as well?

PLATFORM : Windows 10

model_final.pth: 942kB [00:02, 436kB/s]
Traceback (most recent call last):
File "C:\Users\Alexander\layoutTest\main.py", line 3, in
model = lp.Detectron2LayoutModel(
File "C:\Users\Alexander\anaconda3\envs\detectron_env\lib\site-packages\layoutparser\models\detectron2\layoutmodel.py", line 119, in init
self._create_model()
File "C:\Users\Alexander\anaconda3\envs\detectron_env\lib\site-packages\layoutparser\models\detectron2\layoutmodel.py", line 122, in _create_model
self.model = detectron2.engine.DefaultPredictor(self.cfg)
File "C:\Users\Alexander\layoutTest\detectron2\detectron2\engine\defaults.py", line 288, in init
checkpointer.load(cfg.MODEL.WEIGHTS)
File "C:\Users\Alexander\layoutTest\detectron2\detectron2\checkpoint\detection_checkpoint.py", line 62, in load
ret = super().load(path, *args, **kwargs)
File "C:\Users\Alexander\anaconda3\envs\detectron_env\lib\site-packages\fvcore\common\checkpoint.py", line 155, in load
checkpoint = self._load_file(path)
File "C:\Users\Alexander\layoutTest\detectron2\detectron2\checkpoint\detection_checkpoint.py", line 99, in _load_file
loaded = self._torch_load(filename)
File "C:\Users\Alexander\layoutTest\detectron2\detectron2\checkpoint\detection_checkpoint.py", line 114, in _torch_load
return super()._load_file(f)
File "C:\Users\Alexander\anaconda3\envs\detectron_env\lib\site-packages\fvcore\common\checkpoint.py", line 252, in _load_file
return torch.load(f, map_location=torch.device("cpu"))
File "C:\Users\Alexander\anaconda3\envs\detectron_env\lib\site-packages\torch\serialization.py", line 815, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "C:\Users\Alexander\anaconda3\envs\detectron_env\lib\site-packages\torch\serialization.py", line 1033, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, '<'.

Process finished with exit code 1

@cullen122 cullen122 added the bug Something isn't working label Apr 18, 2023
@ashrewdmint
Copy link

I had this issue, but I fixed it by using the version of detectron2 specified in the dev-requirements.txt file: git+https://github.com/facebookresearch/detectron2.git@v0.4#egg=detectron2

This version differs with the version specified in the installation.md file, which uses v0.5. Fortunately, using that version also works for me.

I'm on linux and not using anaconda, so hopefully this fix will still work for you.

@Balthus1989
Copy link

Hey @ashrewdmint , despite the fact that in dev-requirements.txt is present the fix, I still got the _pickle.UnpicklingError

@pedrohavay
Copy link

Hey @Balthus1989 and @ashrewdmint ! This has nothing to do with the version of detectron2 or torch. Basically, the error occurs because pickle does not load the model file due to its incorrect format, which in this case is an HTML returned by DropBox in the download attempt made based on the configuration passed to layoutparser like, for example, lp://PubLayNet/mask_rcnn_X_101_32x8d_FPN_3x/config.

I recommend you download the desired configuration file at this link and change the Dropbox URL to the address of the model on your computer. And then provide the address of your config.yaml file when initializing the layoutparser.

Ex.: model = lp.Detectron2LayoutModel( "/Users/[youuser]/Downloads/config.yaml", label_map={ 0: "Text", 1: "Title", 2: "List", 3: "Table", 4: "Figure", })

@junxi-liu
Copy link

junxi-liu commented Oct 22, 2023

Hey @pedrohavay , unfortunately this method still doesn't work for me.

Edit: installing detectron2==0.5 solved the issue. Using detectron2==0.6 always fails.

@fabmeyer
Copy link

fabmeyer commented Nov 21, 2023

@junxi-liu is it possible to install an older version from source?
like python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' but with version 0.5 instead of the latest version? Else it doesn't match my torch version.

Edit: I found it out by myself.
Download the zip file (https://github.com/facebookresearch/detectron2/releases), unzip it and then run python -m pip install detectron2-0.5/ in the given directory.

@BiboyQG
Copy link

BiboyQG commented Mar 28, 2024

@junxi-liu is it possible to install an older version from source? like python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' but with version 0.5 instead of the latest version? Else it doesn't match my torch version.

Edit: I found it out by myself. Download the zip file (https://github.com/facebookresearch/detectron2/releases), unzip it and then run python -m pip install detectron2-0.5/ in the given directory.

Really appreciate the help!

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

7 participants