U²-Net WebGPU Weights

Browser-loadable U²-Net (u2net) weights for background removal on WebGPU, as used by Kaminos to cut a subject out of an ordinary photo before image-to-3D generation.

The browser route reproduces rembg 2.0.76 remove(image, session=u2net): the Lanczos resize to 320×320, ImageNet normalization, U²-Net inference, min–max mask, Lanczos mask back to image size and the composited cutout. Every step around the network matches rembg and Pillow 12.3 byte for byte; the WebGPU network output differs from onnxruntime's CPU result by at most about 4e-5, and finished cutouts on test photos are within 1/255 of rembg's.

Package

f32/graph.json lists the 259 operations of the network (convolutions with their ReLU fused, max-pools, bilinear resizes, concatenations, additions and sigmoids) with static shapes at the fixed 1×3×320×320 input, plus offsets into f32/weights.f32: 43,981,069 little-endian float32 values, 175,924,276 bytes. The graph records the weights' SHA-256 and the browser loader refuses a mismatch.

Use an immutable Hub commit in the package URL:

import {loadU2NetPackage, createU2NetRunner} from './models/u2net/u2net-webgpu.js';
import {removeForegroundU2Net} from './models/u2net/rembg-u2net.js';

const pkg = await loadU2NetPackage('https://huggingface.co/BasinShapers/u2net-webgpu/resolve/<commit>/f32/');
const runner = createU2NetRunner({device, ...pkg});
const {rgba, width, height} = await removeForegroundU2Net({pixels, width: w, height: h, channels: 3, runner});

The loader, WebGPU kernels and rembg-equivalent pre- and post-processing are in Kaminos models/u2net. This repository contains weights, not executable model code.

Sources And Terms

Weights: rembg's distributed u2net.onnx (release asset), MD5 60024c5c889badc19c04ad937298a77b as pinned by rembg, SHA-256 8d10d2f3bb75ae3b6d527c77944fc5e7dcd94b29809d47a739a7a728a912b491.

U²-Net is by Xuebin Qin, Zichen Zhang, Chenyang Huang, Masood Dehghan, Osmar R. Zaiane and Martin Jagersand (xuebinqin/U-2-Net; "U²-Net: Going Deeper with Nested U-Structure for Salient Object Detection", Pattern Recognition 2020). Its Apache License 2.0 is included as LICENSE-U2NET. rembg's MIT notice is included as LICENSE-REMBG.

Modification notice for f32/: Kaminos read the ONNX graph, folded its shape-computation operations into static shapes, fused each ReLU into its convolution and wrote the convolution weights and biases unchanged as float32 in one file. No values were quantized, fine-tuned or otherwise changed.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support