Blazing fast and Robust Background removal for the Web.
🚀 Try Live Demo – See it in action with your own images
Performance benchmarks on M1 MacBook Pro (WebGPU enabled):
| Resolution | Total Time |
|---|---|
| 1000x1000 | 0.73s |
| 1024×1536 | 0.95s |
| 3000×3000 | 1.40s |
| 5203×7800 | 3.05s |
Note: First-time initialization adds delay for model download and compilation (cached thereafter). WASM fallback is approximately 3-5× slower than WebGPU.
Have different hardware? We'd love to see benchmarks from your device! Submit a PR with your results (include device specs, browser, and whether WebGPU or WASM was used).
rembg-webgpu is a production-ready, client-side background removal library that runs entirely in the browser. Built on rembg.com's distilled AI model and powered by @huggingface/transformers, it delivers state-of-the-art segmentation without server dependencies or privacy compromises.
Core Features:
getCapabilities()Unlike most browser-based background removal solutions that are merely thin wrappers around demo code, rembg-webgpu was engineered from the ground up for production environments.
We started with @huggingface/transformers as a foundation, then extensively rebuilt and optimized the entire pipeline with:
The result is a library that doesn't just work in demos—it scales to real-world applications with thousands of users.
npm i rembg-webgpu
Your bundler must support web workers via new URL('./worker.ts', import.meta.url) (Vite, Webpack 5, etc.).
Modern browsers only.
import { removeBackground, subscribeToProgress, getCapabilities } from 'rembg-webgpu';
// Optional: Check device capabilities before initialization
const capability = await getCapabilities();
console.log(`Backend: ${capability.device}, Precision: ${capability.dtype}`);
// Possible results:
// - { device: 'webgpu', dtype: 'fp16' } - Best performance
// - { device: 'webgpu', dtype: 'fp32' } - Good performance
// - { device: 'wasm', dtype: 'fp32' } - Universal fallback
// Optional: Subscribe to ONNX download/build progress to show a loader
const unsubscribe = subscribeToProgress(({ phase, progress }) => {
// phase: 'idle' | 'downloading' | 'building' | 'ready' | 'error'
// progress: 0..100 (ready sets to 100)
console.log(`${phase}: ${progress}%`);
});
// Remove background from an image
const result = await removeBackground(imageUrl);
// Clean up when done
unsubscribe();
Backend Selection
Performance Optimizations
Resource Management
removeBackground(url) for optimal performanceURL.revokeObjectURL() when done to prevent memory leaksBackground Removal Library provided by www.rembg.com
This project is licensed under the RemBG Attribution License (MIT-Compatible). See the LICENSE file for details.
16 commits
TypeScript
100.0%
Blazing fast and Robust Background removal for the Web.
🚀 Try Live Demo – See it in action with your own images
Performance benchmarks on M1 MacBook Pro (WebGPU enabled):
| Resolution | Total Time |
|---|---|
| 1000x1000 | 0.73s |
| 1024×1536 | 0.95s |
| 3000×3000 | 1.40s |
| 5203×7800 | 3.05s |
Note: First-time initialization adds delay for model download and compilation (cached thereafter). WASM fallback is approximately 3-5× slower than WebGPU.
Have different hardware? We'd love to see benchmarks from your device! Submit a PR with your results (include device specs, browser, and whether WebGPU or WASM was used).
rembg-webgpu is a production-ready, client-side background removal library that runs entirely in the browser. Built on rembg.com's distilled AI model and powered by @huggingface/transformers, it delivers state-of-the-art segmentation without server dependencies or privacy compromises.
Core Features:
getCapabilities()Unlike most browser-based background removal solutions that are merely thin wrappers around demo code, rembg-webgpu was engineered from the ground up for production environments.
We started with @huggingface/transformers as a foundation, then extensively rebuilt and optimized the entire pipeline with:
The result is a library that doesn't just work in demos—it scales to real-world applications with thousands of users.
npm i rembg-webgpu
Your bundler must support web workers via new URL('./worker.ts', import.meta.url) (Vite, Webpack 5, etc.).
Modern browsers only.
import { removeBackground, subscribeToProgress, getCapabilities } from 'rembg-webgpu';
// Optional: Check device capabilities before initialization
const capability = await getCapabilities();
console.log(`Backend: ${capability.device}, Precision: ${capability.dtype}`);
// Possible results:
// - { device: 'webgpu', dtype: 'fp16' } - Best performance
// - { device: 'webgpu', dtype: 'fp32' } - Good performance
// - { device: 'wasm', dtype: 'fp32' } - Universal fallback
// Optional: Subscribe to ONNX download/build progress to show a loader
const unsubscribe = subscribeToProgress(({ phase, progress }) => {
// phase: 'idle' | 'downloading' | 'building' | 'ready' | 'error'
// progress: 0..100 (ready sets to 100)
console.log(`${phase}: ${progress}%`);
});
// Remove background from an image
const result = await removeBackground(imageUrl);
// Clean up when done
unsubscribe();
Backend Selection
Performance Optimizations
Resource Management
removeBackground(url) for optimal performanceURL.revokeObjectURL() when done to prevent memory leaksBackground Removal Library provided by www.rembg.com
This project is licensed under the RemBG Attribution License (MIT-Compatible). See the LICENSE file for details.
16 commits
TypeScript
100.0%