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.7k stars 558 forks source link

[Docker] Migrating app to docker #34

Closed gtntdev closed 1 year ago

gtntdev commented 2 years ago

I have created a docker image, if there is enough interest in it (likes) and @nadermx wants to support this kind of deployment I'll create a PR. So far the image processing works fine with all the models and other options, videos seem to work but the output file size is 0 Byte so this will still need some investigation.

nadermx commented 2 years ago

You can add it. Ill merge it in, make sure its documented well. I dont know much about docker as I use ansible for all deployment needs. The 0kb issue is with the file naming between version of ubuntu and windows apparently with /n/r and the /tmp directory. Shouldnt be hard to fix. Ill try to actually get to it this week.

gtntdev commented 2 years ago

A first version of the docker variant is available here. I added a first version of documentation in the README. My problem is with the image size (torch, torchvision and torchaudio take up 2.5GB of the whole 3GB image, don't know if I can get this smaller). Will improve the docs this week and clean up commits and so on before the PR. @nadermx please let me know if you want to have any basic changes. Ofcourse you will have to sign up with docker.hub yourself but I'll provide you with the official guide and a short video what to change in my github actions (it's just about a few minutes to get this working with good instructions)

nadermx commented 1 year ago

If you want to try the new version, finally got around to fixing the 0kb issue in none linux I believe. pip install --upgrade backgroundremover

eevmanu commented 1 year ago

another recent (and good 👌) dockerfile + compose yaml file alternative https://gist.github.com/benperiton/2d37ea18377a80f9b9768522d08a4253

gtntdev commented 1 year ago

Hi @eevmanu , these two Dockerfiles basically do the same things, and they both produce images way to large. There is an approach to decrease the size: multi-stage building. E.g. first you install all depencies as static librarys and compile your programm into binaries. Second you move your static output to a new image to get rid of all the overhead which was needed during the initial building process. However this only works out with compiled programming languages, since python is interpreted this is just not possible. I once read a bit about optimizing container in size but then stoped as I didn't get a feedback and the existing solution worked for me. But we should come up with some similar efficient strategy to improve the image size. Give me a few more days and I will come back to you (hopefully with a good approach - any hint is welcome:)) Best regards, Lukas

benperiton commented 1 year ago

Yea, mine was just to test this out - not really for any serious use - someone on HN asked me to share it, so I chucked it up. Although for my intended use case, 5GB is nothing (storage is cheap)

gtntdev commented 1 year ago

Same with me. I had to learn it the hard way, that installing these kind of images e.g. on a RPi is quite painful if they're not optimized. Just had a quick search and I guess we can get a "good enough" dockerization. Just let my apply those techniques and then I'll report back.

nadermx commented 1 year ago

Okay, so just to clarify as I have never used Docker (ansible type of guy). I just go to docker, make an account and you then make a pull request with this, or I put it in?

nadermx commented 1 year ago

Okay, progress on this, https://hub.docker.com/r/nadermx/backgroundremover If some one wants to make a PR to this repo with the file, I think then I can push it to docker? I can find a tutorial, or some one has a quick one would be helpful

gtntdev commented 1 year ago

Hi @nadermx , here is a quick guide to get you started. Actually you just need to create an api token for the repo and can leave out all the rest. I'll provide you with the github workflow action where you only will have to fill in the creds. Please give me till the end of this week, to get a reasonable Dockerfile including all new commits and testing. Best, Lukas

nadermx commented 1 year ago

Awesome, token made. If you want I can make you a collaborator on the Docker

nadermx commented 1 year ago

Closed in https://github.com/nadermx/backgroundremover/commit/d3c65a5af9666ad7e2757af10b5bd575a31a61e5