[HN Gopher] Show HN: Remove-bg - open-source remove background u...
___________________________________________________________________
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
It's still new so welcome any ideas and contributions Powered by
WebGPU and Transformer.js (RMBG V1.4 model)
Author : anduc
Score : 131 points
Date : 2024-08-26 15:58 UTC (7 hours ago)
(HTM) web link (bannerify.co)
(TXT) w3m dump (bannerify.co)
| ericol wrote:
| The very first image I uploaded (A model lighthouse with a very
| obvious background) gives just "Error".
| dindresto wrote:
| Does your browser support WebGPU?
| https://webgpu.github.io/webgpu-samples/
| anduc wrote:
| The 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 wrote:
| I'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 wrote:
| A lot of tools exist for this, even on my macbook i can just
| right click, quick action and remove background.
| wongarsu wrote:
| It'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 wrote:
| Same 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 wrote:
| Opened, uploaded image, looked good (it worked!). Then my browser
| (Arc) started freezing, unfroze after closing your website :/
| xnx wrote:
| Great to have local tools. Here's another one that uses the exact
| same combination of technologies:
| https://huggingface.co/spaces/Xenova/remove-background-web (Feb
| 2024)
| anduc wrote:
| Exactly 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
| stavros wrote:
| Nice! This is the model it uses, for anyone curious (it's also
| mentioned in the description):
|
| https://huggingface.co/briaai/RMBG-1.4
| maven29 wrote:
| How does this compare to "segment anything" from Meta
| m00x wrote:
| Much smaller and better at background removal, but doesn't
| segment everything.
| simjnd wrote:
| Very cool, but man pulling 900+ dependencies to build and run
| this thing feels awful. The NPM culture is out of control.
| anduc wrote:
| Haha, 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 wrote:
| > 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 wrote:
| JS standard library is very limited. So, pulling in third party
| dependencies to even left pad a string is normal.
| throwaway63820 wrote:
| you mean the native `str.padStart(targetLength, padString)`
| zamadatix wrote:
| To 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.
| beeboobaa3 wrote:
| Status: 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 wrote:
| "chrome://gpu/" may give more clues as to what went wrong.
| cWave wrote:
| for Chromium, on Linux you also need to run it with --enable-
| features=Vulkan
| https://github.com/gpuweb/gpuweb/wiki/Implementation-Status#...
| beeboobaa3 wrote:
| This worked, thanks!
| arendtio wrote:
| This!
| anduc wrote:
| Maybe 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/ and pass
| the result here
| beeboobaa3 wrote:
| { "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
| nadermx wrote:
| This is cool. I made a background remover for image and video a
| few years back https://github.com/nadermx/backgroundremover/
|
| Always happy to see other people exploring this niche
| anduc wrote:
| It'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 wrote:
| Yeah, that is awesome
| akpa1 wrote:
| Very 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 wrote:
| I 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 wrote:
| Please 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 wrote:
| A 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 wrote:
| What 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 wrote:
| Every 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.
| jml7c5 wrote:
| Sounds a bit like running out of memory, followed by the OOM
| killer going after the process... though I'm not sure the OOM
| killer would act that quickly. Do you get any interesting
| messages in `dmesg`?
| akpa1 wrote:
| You're spot on - dmesg shows it's OOMing, and pretty fast
| too. Turns out that it happens even if I just open the web
| page, yet alone start trying to remove the background of an
| image, so I'd guess it's something to do with loading
| whatever model is being used.
| cmgriffing wrote:
| Looks like WEBGPU is only on nightly for FF, for now.
| codethief wrote:
| Ahh, for a second I thought 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!
| Flop7331 wrote:
| Non-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 wrote:
| firefox / linux. I only get fully transparent output :
| https://i.imgur.com/kcu2LSR.png
|
| nothing interesting on the console.
| nabla9 wrote:
| Same here. Plus error with Chromium.
|
| Working with just one setup is midpoint of web development.
| cultureulterior wrote:
| Nice, works perfectly on win/chrome
| cutiepatootiee wrote:
| Looking forward to testing this out and sharing w network if it
| works well
| hokkos wrote:
| why do you use a canary version of an old react version ?
| lelandfe wrote:
| Thanks 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
|
| BG removed: 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.
| andrewstuart wrote:
| "Remove Background" is at Tools/Remove Background in MacOS
| Preview.
| stephenr wrote:
| Or just press and hold (iOS/iPadOS) / right click (macOS) on
| the subject and choose "copy subject".
| nextaccountic wrote:
| This one is open source.
| sva_ wrote:
| It 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 wrote:
| Looks 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 wrote:
| I would probably consider 50 MB that size, or in the special
| case of metered connections 20 MB (for example downloading
| maps or so).
| Birch-san wrote:
| feels like it could be nice to abide by the license terms
| 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.
| amelius wrote:
| Why 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.
| kinduff wrote:
| I 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
| akdev1l wrote:
| Because someone just created it so no one has packaged it yet
| zurtri wrote:
| I 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 wrote:
| Not 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/
___________________________________________________________________
(page generated 2024-08-26 23:00 UTC)