panoramic

Rembg – background segmentation tool using machine learning

Last Updated on March 6, 2023

Rembg is a tool to remove the backgrounds from images. It’s written in Python and published under an open source license. It’s a versatile tool. It can be run from the command-line, and process a whole folder. It’s also possible to use it as a web server, as a shared library, and run as a Docker image.

The tool relies on the U2Net model, a machine learning model that performs object cropping in a single shot. Taking an image of a person, cat, etc. as input, it can compute an alpha value to separate the background from the panoramic view.

U2Net is a neural network based on a two-level nested architecture. This offers two main advantages: the ability to capture information at different levels of scale and the ability to go deeper without increasing the computational cost too much. U2-Net’s authors aim to design a new neural network for salient object-detection that can be trained from scratch.

Getting Started

We first need to choose between the CPU version or the GPU-accelerated version of Rembg. Both versions are installed with the assistance of pip, a package-management system written in Python used to install and manage software packages. To install the CPU version:

$ pip install rembg

If you want your GPU to help process the calculations, issue the command:

$ pip install rembg[gpu]

Don’t forget the square brackets.

Rembg supports a few machine learning models which are automatically retrieved when you first use a model.

Next page: Page 2 – In Operation

Pages in this article:
Page 1 – Introduction / Getting Started
Page 2 – In Operation
Page 3 – Human segmentation model
Page 4 – Summary

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments