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

Docker always download models #105

Open DavidGasku opened 10 months ago

DavidGasku commented 10 months ago

I'm following the exact commands, but every call to the container is downloading the models. Not sure why.

nadermx commented 10 months ago

I still have to read up on docker. The file was made by some one, if you want to check it and see perhaps there is something in the docker setup where it doesn't check the /u2net directory?

DavidGasku commented 10 months ago

Thanks, I'll try to check it, maybe I can fix it. I'll let you know.

HotNoob commented 8 months ago

bump

Stehos commented 8 months ago

the issue still persist:

backgroundremover -i "./AB6-CF-8-303.jpg" -o "AB6-CF-8-303.png"
AB6-CF-8-303.png
downloading model [u2net] to /root/.u2net/u2net.pth ...
downloading part 1 of u2net
finished downloading part 1 of u2net
downloading part 2 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
nadermx commented 8 months ago

This only with docker?

On Wed, Jan 17, 2024, 1:52 AM Stehos @.***> wrote:

the issue still persist:

backgroundremover -i "./AB6-CF-8-303.jpg" -o "AB6-CF-8-303.png" AB6-CF-8-303.png downloading model [u2net] to /root/.u2net/u2net.pth ... downloading part 1 of u2net finished downloading part 1 of u2net downloading part 2 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

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

nadermx commented 8 months ago

I wonder if the docker id not checking the U2 net folder

On Wed, Jan 17, 2024, 2:08 AM Johnathan Nader @.***> wrote:

This only with docker?

On Wed, Jan 17, 2024, 1:52 AM Stehos @.***> wrote:

the issue still persist:

backgroundremover -i "./AB6-CF-8-303.jpg" -o "AB6-CF-8-303.png" AB6-CF-8-303.png downloading model [u2net] to /root/.u2net/u2net.pth ... downloading part 1 of u2net finished downloading part 1 of u2net downloading part 2 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

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

Stehos commented 8 months ago

@nadermx yes, this is via docker use on ubuntu 20.04.6. btw on macbook i was not able to start docker instance. It was stopped at:

=> [builder 3/7] RUN conda install 'ffmpeg>=4.4.0' -c conda-forge                                                                                                                           22.3s
 => ERROR [builder 4/7] RUN conda install pytorch torchvision torchaudio cpuonly -c pytorch                                                                                                   6.3s
------
 > [builder 4/7] RUN conda install pytorch torchvision torchaudio cpuonly -c pytorch:
0.320 Could not load conda plugin `conda-libmamba-solver`:
0.320
0.320 libarchive.so.19: cannot open shared object file: No such file or directory
0.488 Collecting package metadata (current_repodata.json): ...working... done
2.158 Solving environment: ...working... unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
2.159 Collecting package metadata (repodata.json): ...working... done
5.891 Solving environment: ...working... unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
5.892
5.892 PackagesNotFoundError: The following packages are not available from current channels:
5.892
5.892   - torchaudio
5.892
5.892 Current channels:
5.892
5.892   - https://conda.anaconda.org/pytorch/linux-aarch64
5.892   - https://conda.anaconda.org/pytorch/noarch
5.892   - https://repo.anaconda.com/pkgs/main/linux-aarch64
5.892   - https://repo.anaconda.com/pkgs/main/noarch
5.892   - https://repo.anaconda.com/pkgs/r/linux-aarch64
5.892   - https://repo.anaconda.com/pkgs/r/noarch
5.892
5.892 To search for alternate channels that may provide the conda package you're
5.892 looking for, navigate to
5.892
5.892     https://anaconda.org
5.892
5.892 and use the search bar at the top of the page.
5.892
5.892
------
Dockerfile:11
--------------------
   9 |
  10 |     RUN conda install 'ffmpeg>=4.4.0' -c conda-forge
  11 | >>> RUN conda install pytorch torchvision torchaudio cpuonly -c pytorch
  12 |
  13 |     WORKDIR /usr/local/src
ErikXu commented 7 months ago

You could try to mount the models to host machine. Then the models will be downloaded only once.

like: alias backgroundremover='docker run -it --rm -v "$(pwd):/tmp" -v /root/model:/root bgremover:latest'

charles-large commented 4 months ago

building on the previous comment, I was able to download and mount the model to prevent the container from downloading it every time.

Looking at the code, an environmental variable is first checked for the existance of a path to the model

I was already mounting a local volume into the container and just moved the model to my current directory before mounting. Downloaded model from here

My full command where I reference the path to my downloaded model in environmental variable. "U2NETP_PATH" would need to be changed to the model you are using. Reference code above.

docker run -it --rm -e U2NETP_PATH=/tmp/u2netp.pth -v ".:/tmp" bgremover:latest -i <inputFile> -o <outputFile> -m "u2netp"

It didn't save me a lot of time in processing speed, as the model sizes are pretty small to download and I have a decent internet speed, but the output no longer shows messages of having to download the model every time.