nadermx / backgroundremover

Background Remover lets you Remove Background from images and video using AI with a simple command line interface that is free and open source.
https://www.backgroundremoverai.com
MIT License
6.69k stars 556 forks source link

RuntimeError: storage has wrong byte size #97

Closed Desmond-Campbell closed 1 year ago

Desmond-Campbell commented 1 year ago

My sequence of commands on 4 different Ubuntu 22 boxes below. I'm about to try on a lower version of Ubuntu.

sudo apt install ffmpeg python3.10 or sudo apt install ffmpeg python3.10-dev

sudo apt install pip

pip install backgroundremover

backgroundremover -i "/path/to/image.jpeg" -o "output.png" or backgroundremover -i "/path/to/image.jpeg" -m "u2net" -o "output.png" or backgroundremover -i "/path/to/image.jpeg" -m "u2net_human_seg" -o "output.png" or backgroundremover -i "/path/to/image.jpeg" -m "u2netp" -o "output.png"

I got this error on all the boxes.

Traceback (most recent call last):
  File "/usr/local/bin/backgroundremover", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/backgroundremover/cmd/cli.py", line 239, in main
    remove(
  File "/usr/local/lib/python3.10/dist-packages/backgroundremover/bg.py", line 183, in remove
    model = get_model(model_name)
  File "/usr/local/lib/python3.10/dist-packages/backgroundremover/bg.py", line 171, in get_model
    return detect.load_model(model_name="u2net")
  File "/usr/local/lib/python3.10/dist-packages/backgroundremover/u2net/detect.py", line 82, in load_model
    torch.load(
  File "/usr/local/lib/python3.10/dist-packages/torch/serialization.py", line 815, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.10/dist-packages/torch/serialization.py", line 1051, in _legacy_load
    typed_storage._untyped_storage._set_from_file(
**RuntimeError: storage has wrong byte size: expected %ld got %ld-2384061055873887482048**
nadermx commented 1 year ago

Why is there an or? Should first install python and then install python3.10-dev

On Fri, Sep 8, 2023 at 11:41 PM Desmond Campbell @.***> wrote:

My sequence of commands on 4 different Ubuntu 22 boxes below. I'm about to try on a lower version of Ubuntu.

sudo apt install ffmpeg python3.10 or sudo apt install ffmpeg python3.10-dev

sudo apt install pip

pip install backgroundremover

backgroundremover -i "/path/to/image.jpeg" -o "output.png" or backgroundremover -i "/path/to/image.jpeg" -m "u2net" -o "output.png" or backgroundremover -i "/path/to/image.jpeg" -m "u2net_human_seg" -o "output.png" or backgroundremover -i "/path/to/image.jpeg" -m "u2netp" -o "output.png"

I got this error on all the boxes.

Traceback (most recent call last): File "/usr/local/bin/backgroundremover", line 8, in sys.exit(main()) File "/usr/local/lib/python3.10/dist-packages/backgroundremover/cmd/cli.py", line 239, in main remove( File "/usr/local/lib/python3.10/dist-packages/backgroundremover/bg.py", line 183, in remove model = get_model(model_name) File "/usr/local/lib/python3.10/dist-packages/backgroundremover/bg.py", line 171, in get_model return detect.load_model(model_name="u2net") File "/usr/local/lib/python3.10/dist-packages/backgroundremover/u2net/detect.py", line 82, in load_model torch.load( File "/usr/local/lib/python3.10/dist-packages/torch/serialization.py", line 815, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "/usr/local/lib/python3.10/dist-packages/torch/serialization.py", line 1051, in _legacy_load typed_storage._untyped_storage._set_from_file( RuntimeError: storage has wrong byte size: expected %ld got %ld-2384061055873887482048**

— Reply to this email directly, view it on GitHub https://github.com/nadermx/backgroundremover/issues/97, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYACXFVN7DALWBUG36WQZ3XZPQP7ANCNFSM6AAAAAA4RFEAQA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Desmond-Campbell commented 1 year ago

My bad...the or is just specifying that I tried different variations of the commands. I'm trying now on a Ubuntu 20 box.

nadermx commented 1 year ago

Ah okay, might need more memory to run it?

Desmond-Campbell commented 1 year ago

I will try that. The box has 8GB.

I just tried on a Ubuntu 20. I'll try on a box that has 32 GB to rule it out.


finished downloading part 1 of u2net
finished downloading part 2 of u2net
downloading part 3 of u2net
finished downloading part 3 of u2net
downloading part 4 of u2net
finished downloading part 4 of u2net

Traceback (most recent call last):
  File "/usr/local/bin/backgroundremover", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/backgroundremover/cmd/cli.py", line 239, in main
    remove(
  File "/usr/local/lib/python3.8/dist-packages/backgroundremover/bg.py", line 183, in remove
    model = get_model(model_name)
  File "/usr/local/lib/python3.8/dist-packages/backgroundremover/bg.py", line 171, in get_model
    return detect.load_model(model_name="u2net")
  File "/usr/local/lib/python3.8/dist-packages/backgroundremover/u2net/detect.py", line 82, in load_model
    torch.load(
  File "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 815, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 1051, in _legacy_load
    typed_storage._untyped_storage._set_from_file(
RuntimeError: storage has wrong byte size: expected %ld got %ld-16888554710880130762048```
Desmond-Campbell commented 1 year ago

OK, I tried with the same Ubuntu 20 box with 32 GB and got the same error. Weird, right?

nadermx commented 1 year ago

can you remove the background from the image using backgroundremoverai.com/image ?

On Sat, Sep 9, 2023 at 12:12 AM Desmond Campbell @.***> wrote:

OK, I tried with the same Ubuntu 20 box with 32 GB and got the same error. Weird, right?

— Reply to this email directly, view it on GitHub https://github.com/nadermx/backgroundremover/issues/97#issuecomment-1712408358, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYACXGJNR3DQXPXMB6WIVLXZPUDHANCNFSM6AAAAAA4RFEAQA . You are receiving this because you commented.Message ID: @.***>

Desmond-Campbell commented 1 year ago

This is it: https://api.backgroundremoverai.com/static/downloads/4b6a425b51a84e61ae628b32078eb91e/backgroundremover.png

It looks weird, but that's OK. I'm more worried that the cli tool isn't working. I've tried the tool on your site with other images and they work.

Desmond-Campbell commented 1 year ago

I tried the CLI with a few different versions of torch. The oldest version that is compatible in anyway is 1.12.0. That version and every other up to 2.0.0+ throw the same runtime error.

Has anyone had success installing this recently on Ubuntu?

nadermx commented 1 year ago

Just to clarify, you installed on what ever box python3.x-dev (what ever version, so say python3.8-dev if you have python3.8, or in the other python3.10-dev)

nadermx commented 1 year ago

I just tried it with python3.10 after installing python3.10-dev it worked, image

Desmond-Campbell commented 1 year ago

So, the download seems to go to the end and all 4 parts download. It's just when I call the command to do the conversation I get that error.

What version of Ubuntu are you using? What version of torch?

Can you send a history of the commands?

nadermx commented 1 year ago

image

nadermx commented 1 year ago

So you did not clarify. First in stalled say python3.10, then you ran sudo apt install python3.10-dev or did you just run sudo apt install python3-dev?

Desmond-Campbell commented 1 year ago

So it looks lie you're using all the latest versions.Hmmm. Strange.

Send a history of the commands you used to install and then run the program, from start to finish.

Desmond-Campbell commented 1 year ago

This was the sequence:

sudo apt install ffmpeg python3.10 sudo apt install pip pip install backgroundremover

backgroundremover -i "/path/to/image.jpeg" -o "output.png"

nadermx commented 1 year ago

Once again you must install python3.10-dev and you seem to gloss over the thing that is in the read me and repeated in this thread. Please run sudo apt install python3.10-dev or what ever version of python you are using.

Desmond-Campbell commented 1 year ago

OK, so that's why I had the "or". I had tried it with the -dev first and then without it and I got the same results. It's just so strange to me.

nadermx commented 1 year ago

So, as I said imideatly after you question "Why is there an or? Should first install python and then install python3.10-dev" So I am unsure how else to make it clear that after installing python you have to install python3.10-dev and then install backgroundremover

nadermx commented 1 year ago

Or what ever version of python you installed, so say for example if you install python3.8 then you must install python3.8-dev, or in your case it showed python3.10 so then python3.10-dev

Desmond-Campbell commented 1 year ago

Ahh. It wasn't clear it had to be both. Cool. I'll try later and report here. Thanks much.

nadermx commented 1 year ago

I'm gonna close the issue, reopen if its still an issue

Desmond-Campbell commented 1 year ago

Just for the record, I'm confirming that I tried this with the advice and it worked on a fresh box.

For some reason it still didn't work on the old box.

If anyone else encounters this error, just do it in the order Johnathan specifies.

apt-get install python3.x apt-get install python3.x-dev apt-get install pip pip install backgroundremover