rembg icon indicating copy to clipboard operation
rembg copied to clipboard

[BUG] _pickle.UnpicklingError: invalid load key, '<'. error

Open canerucal opened this issue 1 year ago • 1 comments

I want to use basically the library but it gives that error

Downloading u2net.pth to /Users/cucal/.u2net: 2.21kiB [00:00, 1.26MiB/s]
Traceback (most recent call last):
  File "/Users/cucal/Desktop/portfolio/bionluk/remove-bg/remove-pg.py", line 8, in <module>
    output = remove(input)
  File "/Users/cucal/Desktop/coding/venvs/science/lib/python3.9/site-packages/rembg/bg.py", line 90, in remove
    model = get_model(model_name)
  File "/Users/cucal/Desktop/coding/venvs/science/lib/python3.9/site-packages/rembg/bg.py", line 78, in get_model
    return detect.load_model(model_name="u2net")
  File "/Users/cucal/Desktop/coding/venvs/science/lib/python3.9/site-packages/rembg/u2net/detect.py", line 113, in load_model
    torch.load(
  File "/Users/cucal/Desktop/coding/venvs/science/lib/python3.9/site-packages/torch/serialization.py", line 713, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/Users/cucal/Desktop/coding/venvs/science/lib/python3.9/site-packages/torch/serialization.py", line 920, in _legacy_load
    magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, '<'.

Here is my code:

from rembg.bg import remove
from PIL import Image

input_path = 'man.jpeg'
output_path = 'output.png'

input = Image.open(input_path)
output = remove(input)
output.save(output_path)

This is the 'man.jpeg' image url: https://images.unsplash.com/photo-1624797432677-6f803a98acb3?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8YnVzaW5lc3MlMjBtYW58ZW58MHx8MHx8&w=1000&q=80

OS Version: macOS Monterey 12.4

Rembg version: 1.0.27

Python version: 3.9.12

Chip: Apple M1 Silicon

Edit: I downloaded the models again. But the file which I downloaded is '.onnx' When I copy this file to u2net file, same error happens.

I also copied u2net.pth to u2net document. Error happens again.

canerucal avatar Jul 22 '22 16:07 canerucal

This is duplicate bug Go to u2net/detect.py

Change line 29 to...

response = session.get(URL, params={"id": id, "confirm":"t"}, stream=True)

ranahaani avatar Jul 31 '22 13:07 ranahaani

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 31 '22 02:08 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Sep 14 '22 02:09 github-actions[bot]