Machine Learning in Linux

Machine Learning in Linux: BackgroundRemover – remove backgrounds from images and video

Our Machine Learning in Linux series focuses on apps that make it easy to experiment with machine learning.

BackgroundRemover is a command line tool to remove the background from images and videos using AI. The AI is performed courtesy of U2Net, a machine learning model that allows you to crop objects 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.

BackgroundRemover is written in Python and published under an open source license.


We tested BackgroundRemover primarily on Ubuntu 23.04 and Manjaro.

The project’s GitHub repository recommends you install the software using pip. We strongly recommend you don’t use pip. From experience, installing lots of software with pip inevitably leads to a broken system in the long run.

Instead, we substitute pipx in place of pip. pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.

Install BackgroundRemover with the command:

$ pipx install backgroundremover

When you first run the software, it checks to see if U2Net is present on your system. If not, the software downloads the model for you.

You’ll see output like:

downloading model [u2net] to /home/username/.u2net/u2net.pth ...
downloading part 1 of u2net
finished downloading part 1 of u2net
downloading part 2 of u2net
finished downloading part 2 of u2net
downloading part 3 of u2net
finished downloading part 3 of u2net
downloading part 4 of u2net
finished downloading part 4 of u2net

Next page: Page 2 – In Operation and Summary

Pages in this article:
Page 1 – Introduction and Installation
Page 2 – In Operation and Summary

Notify of

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

Inline Feedbacks
View all comments