20 ms·
Show HN: Remove-bg – open-source remove background using WebGPU
Yesterday,I saw a post in X asking for a self-hostable background remover service. I was thinking, can we make it work by using WebGPU? So it will run in the browser and doesn't require any server/queue to run
After a couple of hours, I created this and published the source code on
https://github.com/ducan-ne/remove-bg https://github.com/ducan-ne/remove-bg
It's still new so welcome any ideas and contributions
Powered by WebGPU and Transformer.js (RMBG V1.4 model)
- cultureulterior 2y agoNice, works perfectly on win/chrome
- ericol 2y agoThe very first image I uploaded (A model lighthouse with a very obvious background) gives just "Error".
- dindresto 2y agoDoes your browser support WebGPU? https://webgpu.github.io/webgpu-samples/ https://webgpu.github.io/webgpu-samples/
- anduc 2y agoThe error is ambiguous right now and I'll try to make it clearer (welcome for contributions) The idea is it fallbacks to not use webgpu if your browser is not supported, but it was made in 2 hours, bug is acceptable :)
- fragmede 2y agoI'm impressed by it working, since the olden days this was a painstaking job in photoshop, and I haven't been keeping up with SOTA, but I'm also impressed at how little code there actually is in src/ai.ts to make it happen. Good job!
- seanthemon 2y agoA lot of tools exist for this, even on my macbook i can just right click, quick action and remove background.
- wongarsu 2y agoIt's pretty much one click in photoshop now too. With better results and more control than what this tool is offering. Not that I'm blaming this tool for being worse than a $200+/yr product. If anything it's impressive how close it gets with so little code. And if you just want rough results on a large number of files it even looks superior
- anduc 2y agoSame here, this is the first time working with this library to me, it's really making me believe even more in the future of Transformer.js/WebGPU, it just beginning
- ramonverse 2y agoOpened, uploaded image, looked good (it worked!). Then my browser (Arc) started freezing, unfroze after closing your website :/
- anduc 2y agoSorry for the inconvenience, I've tested with Arc and can confirm this error, I didn't know why this happens. I will check further to determine the reason and report it to the upstream library (I think it's because the engine or Arc itself)
- vednig 2y agoSince, Arc is built over chromium and does not have active inbuilt chrome popups and error dialogues. Most probably it because of cache utilization and network overload, can simply be solved with clearing cache and creating a service worker for managing download of model and invalidating memory.
- xnx 2y agoGreat to have local tools. Here's another one that uses the exact same combination of technologies: https://huggingface.co/spaces/Xenova/remove-background-web https://huggingface.co/spaces/Xenova/remove-background-web (Feb 2024)
- anduc 2y agoExactly this, as mentioned in the post I've used the same technology with this playground (copied lots of code from here) What I do is mostly make the UX better PS: WebGPU is the future
- simjnd 2y agoVery cool, but man pulling 900+ dependencies to build and run this thing feels awful. The NPM culture is out of control.
- anduc 2y agoHaha, I didn't notice this! Yeah, only Vite will reduce the dependencies a lot, but I'm not sure which one is the biggest here to talk about Will try to the deps simpler later, after all this is about a little time of work
- thelastparadise 2y ago> Will try to the deps simpler later, after all this is about a little time of work Word of tip, you may not want to jump on every last suggestion from the peanut gallery instantly
- ashishb 2y agoJS standard library is very limited. So, pulling in third party dependencies to even left pad a string is normal.
- throwaway63820 2y agoyou mean the native `str.padStart(targetLength, padString)`
- zamadatix 2y agoTo be fair (as one who leans pretty heavy in favor of the JS world) .padStart() was only added in response to the aforementioned left-pad fiasco. The language adding that was more a face saving measure from the blowback than an attempt to fix the actual problems. Despite all that, left-pad still gets > 1 million weekly downloads on npm.
- deleted 2y ago[deleted]
- stavros 2y agoNice! This is the model it uses, for anyone curious (it's also mentioned in the description): https://huggingface.co/briaai/RMBG-1.4 https://huggingface.co/briaai/RMBG-1.4
- beeboobaa3 2y agoStatus: Error Firefox on Linux: Error: Unsupported device: "webgpu". Should be one of: wasm. Chromium on Linux: Error: no available backend found. ERR: [webgpu] Error: Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome. Passing the --enable-unsafe-webgpu flag results in the same error.
- cwillu 2y ago“chrome://gpu/” may give more clues as to what went wrong.
- anduc 2y agoMaybe it's because of how I detect the GPU and switch to another backend (to support devices that don't support WebGPU). Can you try to go https://pmndrs.github.io/detect-gpu/ https://pmndrs.github.io/detect-gpu/ and pass the result here
- beeboobaa3 2y ago{ "fps": 60, "gpu": "amd radeon r9 200", "isMobile": false, "tier": 3, "type": "BENCHMARK" } It's a AMD Radeon RX 6600. It worked on Chromium after passing --enable-unsafe-webgpu --enable-features=Vulkan
- cWave 2y agofor Chromium, on Linux you also need to run it with --enable-features=Vulkan https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#chromium-chrome-edge-etc https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#...
- beeboobaa3 2y agoThis worked, thanks!
- arendtio 2y agoThis!
- nadermx 2y agoThis is cool. I made a background remover for image and video a few years back https://github.com/nadermx/backgroundremover/ https://github.com/nadermx/backgroundremover/ Always happy to see other people exploring this niche
- anduc 2y agoIt's nice to see it here, imagine it works like your repo but runs entirely in the user's browser, very cool, doesn't need any complicated setup
- nadermx 2y agoYeah, that is awesome
- afuqya 2y ago@nadermx Does it work in real time for webcam? I ask that because you have an animated gif in your link.
- nadermx 2y agoI haven't messed much with it, but it would be possible to probably have ffmpeg pull the stream and run it at 30 fps blocks. Can do a pull request if you want
- akpa1 2y agoVery cool idea, but for me it completely doesn't work. I'll open an image, the entire computer (running Linux) will briefly freeze (including stopping Spotify in its tracks) and when it comes back, the only thing that's left is a message from Firefox telling the tab has crashed.
- anduc 2y agoI tried it on my Chrome-Mac device, but not sure how it works on other devices (assuming it works). I'll test it out later. Sorry for the inconvenience
- akpa1 2y agoPlease don't apologise for any inconvenience! It's a cool project and I'd love to see it working, I'm just sorry I can't give any positive feedback
- lxgr 2y agoA website being able to do this is arguably a browser bug. If a browser's sandbox can't even protect against accidental resource exhaustion, I'd be very concerned about that as an intentional attack vector.
- ipaddr 2y agoWhat browser protects against resource exhaustion? Chrome and all variants do not. Running out of memory or cpu or even hard drive space can happen and does in all browsers.
- lxgr 2y agoEvery browser I know meters all APIs capable of using disk space, and 100% CPU usage doesn’t hang your system on any reasonable OS. Memory can indeed be a problem, but at least if a tab becomes the largest single memory user on my system, the OOM killer will come for it first. So if for CPU and memory browsers can lean on the OS for proper resource management but it’s not the case for GPU, maybe their WebGPU implementations aren’t ready for production yet.
- codethief 2y agoAhh, for a second I thought https://remove.bg https://remove.bg had open-sourced their product (which I've been quite happy with on the few occasions I've used it). Very cool, though!
- deleted 2y ago[deleted]
- Flop7331 2y agoNon-descript error after 180 seconds. Vivaldi on Android. Please turn off the rolling animation for the duration timer. It looks really wrong when the numbers wind back (which they wouldn't do on a rotor) and when the trailing zeroes vanish.
- tech-no-logical 2y agofirefox / linux. I only get fully transparent output : https://i.imgur.com/kcu2LSR.png https://i.imgur.com/kcu2LSR.png nothing interesting on the console.
- cutiepatootiee 2y agoLooking forward to testing this out and sharing w network if it works well
- anduc 2y agoThank you, looking forward to this, if you have any feedback please let me know via x.com/duc__an
- hokkos 2y agowhy do you use a canary version of an old react version ?
- anduc 2y agoHi there, it's because I copied the project template from my previous project, will check and try to upgrade to the React 19 soon if it'll work with the libraries
- lelandfe 2y agoThanks for sharing; it looks like this has trouble with certain kinds of images. Here's likely the most representative example: Original: https://imgur.com/a/NrEXfua https://imgur.com/a/NrEXfua BG removed: https://imgur.com/a/JWKHVGE https://imgur.com/a/JWKHVGE Much of the background was untouched, and almost all of the actual data (the axis and bars) were removed instead.
- anduc 2y agoSorry for my late I missed the comment Yeah I think it's because the quanlity of the model, hopefully we will have better quanlity in near future. I will see if anything I can do with the settings
- andrewstuart 2y ago"Remove Background" is at Tools/Remove Background in MacOS Preview.
- stephenr 2y agoOr just press and hold (iOS/iPadOS) / right click (macOS) on the subject and choose "copy subject".
- nextaccountic 2y agoThis one is open source.
- stephenr 2y agoWhat are you basing that assertion on? There’s no licence information provided in the repo or on the site, that I can see.
- sva_ 2y agoIt would be cool if it could ask before loading the model, or at least indicate to me how large the download will be, as I'm on a metered connection right now. But maybe that's just a me-problem.
- zamadatix 2y agoLooks like ~4 MB, I think that's a fair size to not throw up warnings about (unless I'm missing something in the Network view of dev tools w/o cache). That said I wonder what people consider the "Click to enlarge (may take a while to load)" courtesy size to be in 2024.
- lynguist 2y agoI would probably consider 50 MB that size, or in the special case of metered connections 20 MB (for example downloading maps or so).
- jfoster 2y ago50 MB might be fine for desktops on effectively unlimited & high speed connections, but consider the case of a mobile user with a few GB of data per month. Might be unacceptable for them. Not sure how common that case is in the US, but certainly possible outside the US.
- sva_ 2y ago> Looks like ~4 MB You got me! The model was 176 MB. Total pageload transferred 182 MB. https://imgur.com/a/6xx3Lgu https://imgur.com/a/6xx3Lgu It doesn't seem like "Disable cache" in the DevTools empties the Cache Storage.
- Loughla 2y agoAfter living with satellite Internet as the only option for about 15 years, now that I have fiber, I still catch myself declining downloads that are too big and opening the scheduler. Old habits die hard. And the modern Internet implicitly assumes the end user is not on a metered connection. Websites are fucking massive these days.
- Birch-san 2y agofeels like it could be nice to abide by the license terms https://bria.ai/bria-huggingface-model-license-agreement/ https://bria.ai/bria-huggingface-model-license-agreement/ > 1.1 License. > BRIA grants Customer a time-limited, non-exclusive, non-sublicensable, personal and non-transferable right and license to install, deploy and use the Foundation Model for the sole purpose of evaluating and examining the Foundation Model. > The functionality of the Foundation Model is limited. Accordingly, Customer are not permitted to utilize the Foundation Model for purposes other than the testing and evaluation thereof. > 1.2.Restrictions. Customer may not: > 1.2.2. sell, rent, lease, sublicense, distribute or lend the Foundation Model to others, in whole or in part, or host the Foundation Model for access or use by others. > The Foundation Model made available through Hugging Face is intended for internal evaluation purposes and/or demonstration to potential customers only.
- Laaas 2y agoThe repo doesn’t include the model.
- NewJazz 2y agoDoes the site not distribute it?
- benatkin 2y agoIt doesn't, except that it runs it. There's no download link or code playground for running arbitrary code on it, so while technically it transfers the model to the computer where it's running (I think) it's not usually considered the same as distributing it.
- NewJazz 2y agoYeah, that doesn't sound right to me.
- 2y ago
- deleted 2y ago[deleted]
- amelius 2y agoWhy can't I just "apt-get install" tools like this? I used to have all the powerful tools at my fingertips but now I feel like my Linux distro is slowly disappearing into a vortex of irrelevance.
- akdev1l 2y agoBecause someone just created it so no one has packaged it yet
- kinduff 2y agoI wouldn't blame apt-get, there are a lot of command-line tools nowadays. I don't usually install these if its not going to be a frequent task. Anyways, if you're looking for a cmd tool, rembg [0] is a pretty good one. [0]: https://github.com/danielgatis/rembg https://github.com/danielgatis/rembg
- solardev 2y agoFor every Linux power user, there are probably a million regular web users who don't know (or care to know) what a command line is. Web tools are for them. Why not fork the repo and repackage it as a CLI app if you really want it that way?
- fulafel 2y agoPeople are trying to write software for GPUs more commonly now + because of the troubled GPU programming landscape, it's hard to make programs that work more than one vendor's proprietary flavour of GPU. WebGPU is an attempt to address some of that in browser apps, but it's not ready yet.
- zurtri 2y agoI tried it on an image of me and a horse in front of a paddock and it worked perfectly. Really impressed. Other background removal tools would find me - but erase half the horse or erase his tack or his ears. This tool worked perfectly. Very well done!
- mvdtnz 2y agoNot sure if you realise you've given it the same name as another product that does this exact thing. (Disclosure I work for Canva, the company which owns remove.bg). https://www.remove.bg/ https://www.remove.bg/
- anduc 2y agoAh, I didn't realize that there is any product with a similar name, and in case I already know, I think I'll still pick this name since it's only an experimental open source project with WebGPU. Remove-bg is quite common IMO, but definitely will affect SEO if I want to do more for the project, but I have no plan yet
- jacobn 2y agoNice work! Making AI accessible directly in the browser (even if you have to download quite the payload for the model parameters) is a real accessibility game changer. Shameless plug: if you prefer API-based background removal we offer a super low cost, high quality option on https://pixian.ai https://pixian.ai
- cutiepatootiee 2y agoIt's not working for me
- anduc 2y agoCan you provide more additional information for me? If you're using Linux and Chrome you probably need to pass GPU flag `--enable-unsafe-webgpu --enable-features=Vulkan`
- kamjin 2y agoCan you take a look at this open source background removal project? https://www.reddit.com/r/StableDiffusion/comments/1dwkwrx/i_made_a_free_background_remover_webapp_using_6/ https://www.reddit.com/r/StableDiffusion/comments/1dwkwrx/i_... It's based on python and neural network modeling, and I was wondering if it's possible to run it via webgpu? Or run it based on wasm? No offense, just because it looks awesome.
- anduc 2y agoFirst time I see this, by the first impression I think the output quality of this one is better than mine and my code is only based on one model In my understanding, It'll possible if the model's author build to https://onnxruntime.ai https://onnxruntime.ai ONNX Runtime. And maybe the downside is user will need to download ton of data to their device, currently it's ~100-200mb
- kamjin 2y agoI tried your site using the image: https://bannerify.co/tools/remove-bg https://bannerify.co/tools/remove-bg I crashed the page after 10 or so seconds and Chrome prompted me: Crashpad_NotConnectedToHandler, it doesn't work!
- anduc 2y agocan you raise this issue on Github? I will take a look into this later since it's not common error. I think it's because some settings on the browser I've heard someone reported that Arc had a similar error
- ivolimmen 2y agoWell gave it 2 tries before giving up. Does not do anything in FireFox and in Chrome it also failed after loading some data. It told me to restart Chrome with some GPU unsafe flag.
- anduc 2y agoHey there, sorry for the issue, does it show status "Error"? if so can you try to enable WebGPU using this flag "--enable-unsafe-webgpu --enable-features=Vulkan", if not it doesn't seems like a common error and I will spend more time on testing later Feel free to raise an issue on Github to keep track progress, it helps open source a lot, or you can DM on x.com/duc__an anytime
- anduc 2y agoSomeone mentioned > Looks like WEBGPU is only on nightly for FF, for now
- Akash_deshmukh 2y agothanks ! finds useful .
- codedokode 2y agoYou might want to warn about memory usage. I had Chromium consume several GBs of RAM and had to terminate it. But it is great that there now is more offline tools. It would be great if there was a browser API that allowed the page to voluntarily go offline to guarantee that no data will be leaked.
- anduc 2y agoSeveral GBs of RAM definitely too much, I'm not aware that this consumes that much memory. I will spend more time trying to figure out how much memory is minimum necessary for this and will warn in the page.
- anduc 2y agoHi guys, thanks for your interest in my little project, I'm glad you all like it. I just spend my free time to make it much better based on your feedback - Mobile support, tested on my iPhone - GitHub README added - Added medium zoom for easier viewing on Mobile - The error banner makes it more friendly and easy troubleshooting - Troubleshooting section in README If you have any idea to make the UX better, please let me know, I'll appreciate it
- makifoxgirl 2y agoI've tried many different background removal algorithms and found that InSPyReNet has been the most successful one. I use `transparent-background` on pip a whole bunch and it rarely fails on me compared to remove-bg and whatnot https://github.com/plemeri/transparent-background https://github.com/plemeri/transparent-background
- hauschildt 2y agoHi, nice work. I recently also published a WebGPU version of our browser-only background removal library. It's using the onnx-runtime under the hood. Weights are from isnet. It could also run birefnet – if there is some interest – however BirefNet weights are almost 1GB in size, which is a bit much to download I guess. There is a blog post about it and also a CPU only version available. https://img.ly/blog/browser-background-removal-using-onnx-runtime-webgpu/ https://img.ly/blog/browser-background-removal-using-onnx-ru... Source is available at: https://github.com/imgly/background-removal-js https://github.com/imgly/background-removal-js and on npm: @imgly/background-removal Feel free to check it out!
- san_dimitri 2y agoThanks for sharing this repo. While I don't have time to actively contribute to the code, I have been testing on images to share my feedback for future devs. 1. Background removal is working good on a lot of different types of images. This includes images with background, plain or white background, men, women, children, hair, and pets. 2. After background removal, the new image is warped in some areas. For example, I have a picture of a child eating ice-cream. The background was removed perfectly but left a lot of artifacts on the child. I can share those images for testing. Please let me know if there are other areas I can test.
- ccbikai 2y agoI have used this model before, running it locally with Web GPU is quite fun https://news.ycombinator.com/item?id=40715181 https://news.ycombinator.com/item?id=40715181