remix logo

Hacker Remix

Show HN: Remove-bg – open-source remove background using WebGPU

286 points by anduc 8 months ago | 121 comments

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)

Birch-san 8 months ago

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.

jfoster 8 months ago

A lot of these AI licenses are a lot more restrictive than old school open source licenses were.

My company runs a bunch of similar web-based services and plan to do a background remover at some stage, but as far as I know there's no current models with a sufficiently permissive license that can also feasibly download & run in browsers.

sangnoir 8 months ago

Meta's second Segment Anything Model (SAM2) has an Apache license. It only does segmenting, and needs additional elbow grease to distill it for browsers, so it's not turnkey, but it's freely licensed.

jfoster 8 months ago

Yeah, that one seems to be the closest so far. Not sure if it would be easier to create a background removal model from scratch (since that's a more simple operation than segmentation) or distill it.

jaxn 8 months ago

I got pretty far down that path during Covid for a feature of my saas, but limited to specific product categories on solid-ish backgrounds. Like with a lot of things, it’s easy to get good, and takes forever to get great.

littlestymaar 8 months ago

Keep in mind that whether or not a model can be copyrighted at all is still an open question.

Everyone publishing AI model is actually acting as if they owned copyright over it and as such are sharing it with a license, but there's no legal basis for such claim at this point, it's all about pretending and hoping the law will be changed later on to make their claim valid.

NewJazz 8 months ago

Train on copyrighted material

Claim fair use

Release model

Claim copyright

Infinite copyright!

Mathnerd314 8 months ago

It is a 2024 model, for comparison https://github.com/danielgatis/rembg/ uses U2-Net which is open source from 2022. There is also https://github.com/ZhengPeng7/BiRefNet (another 2024 model, also open source), it's not too late to switch.

xdennis 8 months ago

It's kind of silly to complain about not abiding by the model license when these models are trained on content not explicitly licensed for AI training.

You might say that the models were legally trained since no law mandates consent for AI training. But no law says that models are copyrightable either.

sva_ 8 months ago

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.

Loughla 8 months ago

After 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.

zamadatix 8 months ago

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.

sva_ 8 months ago

> Looks like ~4 MB

You got me!

The model was 176 MB. Total pageload transferred 182 MB.

https://imgur.com/a/6xx3Lgu

It doesn't seem like "Disable cache" in the DevTools empties the Cache Storage.

lynguist 8 months ago

I would probably consider 50 MB that size, or in the special case of metered connections 20 MB (for example downloading maps or so).

jfoster 8 months ago

50 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.

xnx 8 months ago

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 8 months ago

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 8 months ago

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 8 months ago

How does this compare to "segment anything" from Meta

m00x 8 months ago

Much smaller and better at background removal, but doesn't segment everything.