De l’expérience rapide à la production : trois façons de déployer RMBG-1.4
1. Démo en ligne et API REST
Accédez à l’espace Hugging Face officiel ou à un miror Chine-mainland, glissez-déposez une image et récupérez le résultat en un clic. Pour une intégration programmatique :
from huggingface_hub import InferenceClient
client = InferenceClient("briaai/RMBG-1.4", token="hf_***")
mask = client.image_segmentation("photo.jpg", return_mask=True)
2. Installation locale en 4 commandes
uv venv rmbg
source rmbg/bin/activate
uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
uv pip install briarmbg pillow opencv-python
Lencez ensuite :
python - <<'PY'
from briarmbg import BriaRMBG
from PIL import Image
net = BriaRMBG.from_pretrained("briaai/RMBG-1.4").cuda().eval()
img = Image.open("produit.jpg").convert("RGB")
out = net.remove_background(img, output_type="pil")
out.save("produit_alpha.png")
PY
3. Déploiement ONNX haute performance
Convertissez le modèle PyTorch vers ONNX puis TensorRT pour un service GPU millisecondes :
torch.onnx.export(
net, torch.randn(1,3,1024,1024).cuda(),
"rmbg.onnx", opset_version=17,
input_names=["image"], output_names=["alpha"]
)
trtexec --onnx=rmbg.onnx --saveEngine=rmbg.engine --fp16
Architecture technique : le cœur RSU revisité
Le réseau RSU (Residual U-Block) de RMBG-1.4 est découpé en trois échelles :
- RSU-7 : capture les structures fines (cheveux, fils)
- RSU-5 : équilibre détails et contexte
- RSU-4 : focalise les objets volumineux
Chaque bloc applique des convolutions dilatées dirate=2 pour agrandir le champ réceptif sans augmenter le nombre de paramètres. Le schéma ci-dessous montre le pipeline complet :
Image 1024×1024
│
┌───┴──────────┐
│ RSU-7 │ → feature map 512×512
│ RSU-5 │ → feature map 256×256
│ RSU-4 │ → feature map 128×128
└───┬──────────┘
│ concat + 1×1 conv
↓
Binaire alpha mat 1024×1024
Cas d’usage industriels
E-commerce : chaîne de traitement batch
import asyncio, aiofiles
from pathlib import Path
async def process_folder(src: Path, dst: Path):
tasks = []
for f in src.glob("*"):
if f.suffix.lower() in {".jpg", ".png"}:
tasks.append(worker(f, dst/f"{f.stem}.png"))
await asyncio.gather(*tasks)
async def worker(src, dst):
img = Image.open(src)
alpha = await asyncio.to_thread(net.remove_background, img)
async with aiofiles.open(dst, "wb") as fp:
alpha.save(fp, format="PNG")
asyncio.run(process_folder(Path("in"), Path("out")))
Avec 8 cœurs CPU et le modèle quantisé INT8, 1 000 images 2K sont traitées en 6 minutes.
Studio de jeux : génération de sprites
Photographiez un accessoire réel, détourez-le automatiquement, puis appliquez une palette PBR dans Blender via le nœud Image Texture. Le gain de temps est estimé à 70 % par rapport au rotoscopage manuel.
Agence marketing : API serverless
Déployez le modèle ONNX sur AWS Lambda (10 GB mémoire, GPU T4) exposé via Amazon API Gateway. Coût moyen : 0,002 USD par image à 1 000 QPS.
Licence et limites
| Usage | Statut | Condition |
|---|---|---|
| Recherche | Gratuit | Attribution requise |
| Prototype SaaS | Gratuit | < 1 000 images/mois |
| Produciton | Contrat | Contact commercial BRIA |
Limites actuelles :
- Transparence fine (verre, fumée) : 78 % IoU
- Objets < 32×32 px : 15 % de faux négatifs
- Images non photo-réalistes : dégradation visible
Feuille de route communautaire
Les prochaines étapes discutées sur GitHub :
- Support vidéo 30 fps (déjà en branche
feature/video) - Modèles spécialisés : portrait, produit, document
- Plugin Figma & Photoshop signé par la communauté
Contribuez via git clone https://github.com/briaai/RMBG-1.4.git et ouvrez une PR ; les datasets additionnels doivent être publiés sous CC-BY-4.0.