rmbg2-cli 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,38 @@
1
+ RMBG-2.0 MODEL WEIGHTS LICENSE NOTICE
2
+
3
+ This repository uses the briaai/RMBG-2.0 model. The model weights are licensed
4
+ separately by BRIA AI for non-commercial use under the Creative Commons
5
+ Attribution-NonCommercial 4.0 International license (CC BY-NC 4.0).
6
+
7
+ Model and license information:
8
+ https://huggingface.co/briaai/RMBG-2.0
9
+ https://creativecommons.org/licenses/by-nc/4.0/
10
+
11
+ Commercial use of the model weights requires a separate agreement with BRIA.
12
+ The notice above applies to the model weights and does not replace the MIT
13
+ license for this repository's source code, reproduced unchanged below.
14
+
15
+ -------------------------------------------------------------------------------
16
+
17
+ MIT License
18
+
19
+ Copyright (c) 2026 rmbg-cli contributors
20
+ Copyright (c) 2026 rmtg contributors
21
+
22
+ Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ of this software and associated documentation files (the "Software"), to deal
24
+ in the Software without restriction, including without limitation the rights
25
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ copies of the Software, and to permit persons to whom the Software is
27
+ furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in all
30
+ copies or substantial portions of the Software.
31
+
32
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # rmbg-cli
2
+
3
+ [![CI](https://github.com/shayyz-code/rmbg-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/shayyz-code/rmbg-cli/actions/workflows/ci.yml)
4
+ [![Release](https://github.com/shayyz-code/rmbg-cli/actions/workflows/release.yml/badge.svg)](https://github.com/shayyz-code/rmbg-cli/actions/workflows/release.yml)
5
+ [![npm](https://img.shields.io/npm/v/rmbg2-cli.svg)](https://www.npmjs.com/package/rmbg2-cli)
6
+ [![Code License: MIT](https://img.shields.io/badge/code-MIT-blue.svg)](LICENSE)
7
+ [![Model License: CC BY--NC 4.0](https://img.shields.io/badge/model-CC_BY--NC_4.0-orange.svg)](https://huggingface.co/briaai/RMBG-2.0)
8
+
9
+ `rmbg` removes image backgrounds locally with
10
+ [`briaai/RMBG-2.0`](https://huggingface.co/briaai/RMBG-2.0). A small Rust CLI
11
+ validates arguments and starts a locked, uv-managed Transformers runtime. No
12
+ hosted inference API is used.
13
+
14
+ > [!IMPORTANT]
15
+ > The RMBG-2.0 model weights are available for **non-commercial use only**
16
+ > under CC BY-NC 4.0. Commercial use requires a separate agreement with BRIA.
17
+ > The repository code remains MIT-licensed; that license does not extend to
18
+ > the model weights.
19
+
20
+ ## Example
21
+
22
+ The example below was processed locally with:
23
+
24
+ ```bash
25
+ rmbg marin.png -o marin-no-bg.png
26
+ ```
27
+
28
+ | Before | After — transparent PNG |
29
+ |:------:|:-----------------------:|
30
+ | <img width="427" height="640" alt="marin" src="https://github.com/user-attachments/assets/a810e266-607f-43d5-b8e6-845bed9f1d67" /> | <img width="427" height="640" alt="marin-no-bg" src="https://github.com/user-attachments/assets/99711dfc-6ee7-4df0-bdb1-09e7b64b8d44" /> |
31
+
32
+ ## System requirements
33
+
34
+ BRIA publishes RMBG-2.0 as a 0.2B-parameter model with FP32 weights and a
35
+ 1024×1024 inference size, but does not publish minimum RAM or VRAM figures. The
36
+ values below are conservative project guidance based on that architecture, the
37
+ 844 MB pinned weights, and the local PyTorch runtime. See the
38
+ [official model card](https://huggingface.co/briaai/RMBG-2.0) and
39
+ [BRIA repository](https://github.com/Bria-AI/RMBG-2.0).
40
+
41
+ | Resource | Minimum | Recommended |
42
+ |----------|---------|-------------|
43
+ | Platform | Linux glibc x64/ARM64, Apple Silicon macOS, or Windows x64 | A current release of one of the supported operating systems |
44
+ | CPU | 2 cores; CPU-only inference is supported | 4 or more modern CPU cores |
45
+ | Memory | 8 GB RAM | 16 GB RAM |
46
+ | Free storage | 5 GB for dependencies, weights, and caches | 10 GB, especially for Linux CUDA packages |
47
+ | Acceleration | None; a GPU is optional | NVIDIA GPU with 6 GB VRAM, or Apple Silicon with 16 GB unified memory |
48
+ | Network | Required during initial setup | Broadband connection for the model and dependency download |
49
+ | Account | Hugging Face account with the RMBG-2.0 terms accepted | `HF_TOKEN` configured for non-interactive setup |
50
+ | Software | [uv](https://docs.astral.sh/uv/) and Python 3.10–3.12, managed by uv | Node.js 18+ for npm installation; Rust 1.75+ only when building from source |
51
+
52
+ The official implementation depends on PyTorch, Torchvision, Pillow, Kornia,
53
+ and Transformers. CUDA, Apple MPS, and CPU execution are selected automatically
54
+ by this CLI.
55
+
56
+ ## Installation
57
+
58
+ Install the native CLI from npm:
59
+
60
+ ```bash
61
+ npm install --global rmbg2-cli
62
+ rmbg setup
63
+ ```
64
+
65
+ Node.js is only used by the npm launcher. The image processing runtime remains
66
+ local Python, Transformers, and PyTorch managed by uv.
67
+
68
+ To install without Node.js on Linux or macOS:
69
+
70
+ ```bash
71
+ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/shayyz-code/rmbg-cli/releases/latest/download/rmbg-installer.sh | sh
72
+ ```
73
+
74
+ On Windows PowerShell:
75
+
76
+ ```powershell
77
+ irm https://github.com/shayyz-code/rmbg-cli/releases/latest/download/rmbg-installer.ps1 | iex
78
+ ```
79
+
80
+ Both direct installers verify the downloaded archive against the release
81
+ SHA-256 manifest, install into a user-local bin directory, and print PATH
82
+ guidance when needed. Set `RMBG_INSTALL_DIR` to choose another directory or
83
+ `RMBG_VERSION` to install a specific release.
84
+
85
+ Then prepare the local model runtime once:
86
+
87
+ ```bash
88
+ rmbg setup
89
+ ```
90
+
91
+ To build from source instead:
92
+
93
+ ```bash
94
+ git clone https://github.com/shayyz-code/rmbg-cli.git
95
+ cd rmbg-cli
96
+ cargo build --release
97
+ ./target/release/rmbg setup
98
+ ```
99
+
100
+ Setup checks for [uv](https://docs.astral.sh/uv/getting-started/installation/),
101
+ prints the official installation command if it is missing, installs the locked
102
+ Python dependencies, starts Hugging Face login when needed, downloads the pinned
103
+ 844 MB model, and validates that it loads on the selected device. If BRIA's
104
+ non-commercial terms have not been accepted, setup prints the model page and can
105
+ be rerun after access is granted. You can use `HF_TOKEN` instead of interactive
106
+ login.
107
+
108
+ Setup is idempotent and reuses installed dependencies and cached weights:
109
+
110
+ ```bash
111
+ rmbg setup --device cpu
112
+ ```
113
+
114
+ ## Usage
115
+
116
+ Remove a background and write `<input>-no-bg.png`:
117
+
118
+ ```bash
119
+ rmbg photo.jpg
120
+ rmbg photo.jpg -o cutout.png -v
121
+ ```
122
+
123
+ Composite the foreground onto a solid color:
124
+
125
+ ```bash
126
+ rmbg photo.jpg --background white -o on-white.png
127
+ rmbg photo.jpg --background "#336699" -o on-blue.png
128
+ rmbg photo.jpg --background 255,128,0 -o on-orange.png
129
+ ```
130
+
131
+ Device selection defaults to CUDA, then Apple MPS, then CPU. Override it when
132
+ needed:
133
+
134
+ ```bash
135
+ rmbg photo.jpg --device cpu
136
+ ```
137
+
138
+ | Flag | Description |
139
+ |------|-------------|
140
+ | `-o, --output <PATH>` | Output PNG path (default: `<input>-no-bg.png`) |
141
+ | `--background <COLOR>` | Solid background (`#RRGGBB`, `R,G,B`, `white`, `black`) |
142
+ | `--device <DEVICE>` | `auto`, `cuda`, `mps`, or `cpu` (default: `auto`) |
143
+ | `-v, --verbose` | Print model, device, revision, and output details |
144
+ | `-h, --help` | Show help |
145
+
146
+ `rmbg setup [--device auto|cuda|mps|cpu]` prepares and validates all local
147
+ runtime prerequisites. Because `setup` is reserved as a command, process a file
148
+ with that exact name as `rmbg ./setup`.
149
+
150
+ Exit code `1` indicates invalid input or a setup action the user must complete,
151
+ such as installing uv, authenticating non-interactively, or accepting model
152
+ terms. Exit code `2` indicates dependency, network, runtime, model-load,
153
+ inference, or output failure.
154
+
155
+ ## How it works
156
+
157
+ The worker follows the RMBG-2.0 model card: it normalizes a 1024×1024 RGB copy,
158
+ runs local Transformers/PyTorch inference, resizes the predicted grayscale
159
+ matte to the original dimensions, and applies it as alpha. Existing alpha is
160
+ multiplied with the prediction so transparent source pixels are never restored.
161
+
162
+ The model requires `trust_remote_code=True`. The tested model revision is
163
+ [`5df4c9c76d8170882c34f6986e848ee07fd0ba43`](https://huggingface.co/briaai/RMBG-2.0/tree/5df4c9c76d8170882c34f6986e848ee07fd0ba43),
164
+ reported by `rmbg -v`. It can be overridden for deliberate maintenance with
165
+ `RMBG_MODEL_REVISION`.
166
+
167
+ ## Development
168
+
169
+ ```bash
170
+ uv sync --project runtime --frozen
171
+ cargo fmt --all -- --check
172
+ cargo clippy --all-targets -- -D warnings
173
+ cargo test --all
174
+ npm run check:versions
175
+ npm test
176
+ uv run --project runtime --frozen python runtime/tests/test_runtime.py
177
+ ```
178
+
179
+ Ordinary tests use a fake segmentation model and do not download weights.
180
+
181
+ ## License
182
+
183
+ Repository code is MIT-licensed. RMBG-2.0 model weights are separately licensed
184
+ for non-commercial use under CC BY-NC 4.0. See [LICENSE](LICENSE) and the
185
+ [official model card](https://huggingface.co/briaai/RMBG-2.0).
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const path = require("node:path");
6
+ const { spawn } = require("node:child_process");
7
+ const { packageForCurrentPlatform } = require("../lib/platform");
8
+
9
+ let platformPackage;
10
+ try {
11
+ platformPackage = packageForCurrentPlatform();
12
+ } catch (error) {
13
+ console.error(`rmbg: ${error.message}`);
14
+ process.exit(1);
15
+ }
16
+
17
+ let packageJson;
18
+ try {
19
+ packageJson = require.resolve(`${platformPackage}/package.json`);
20
+ } catch {
21
+ console.error(
22
+ `rmbg: native package ${platformPackage} is missing. ` +
23
+ "Reinstall rmbg2-cli without omitting optional dependencies."
24
+ );
25
+ process.exit(1);
26
+ }
27
+
28
+ const executable = path.join(
29
+ path.dirname(packageJson),
30
+ "bin",
31
+ process.platform === "win32" ? "rmbg.exe" : "rmbg"
32
+ );
33
+ const child = spawn(executable, process.argv.slice(2), { stdio: "inherit" });
34
+
35
+ child.on("error", (error) => {
36
+ console.error(`rmbg: failed to start native executable: ${error.message}`);
37
+ process.exit(1);
38
+ });
39
+
40
+ for (const signal of ["SIGINT", "SIGTERM"]) {
41
+ process.on(signal, () => child.kill(signal));
42
+ }
43
+
44
+ child.on("exit", (code, signal) => {
45
+ if (signal) {
46
+ process.kill(process.pid, signal);
47
+ return;
48
+ }
49
+ process.exit(code ?? 1);
50
+ });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ const PACKAGES = new Map([
4
+ ["darwin-arm64", "rmbg2-cli-darwin-arm64"],
5
+ ["linux-arm64", "rmbg2-cli-linux-arm64-gnu"],
6
+ ["linux-x64", "rmbg2-cli-linux-x64-gnu"],
7
+ ["win32-x64", "rmbg2-cli-win32-x64-msvc"]
8
+ ]);
9
+
10
+ function usesGlibc(report = process.report) {
11
+ if (!report || typeof report.getReport !== "function") return false;
12
+ return Boolean(report.getReport().header?.glibcVersionRuntime);
13
+ }
14
+
15
+ function packageForPlatform(platform, arch, report = process.report) {
16
+ if (platform === "linux" && !usesGlibc(report)) {
17
+ throw new Error("Linux musl is not supported; a glibc-based distribution is required");
18
+ }
19
+
20
+ const packageName = PACKAGES.get(`${platform}-${arch}`);
21
+ if (!packageName) {
22
+ throw new Error(
23
+ `unsupported platform ${platform}/${arch}; supported targets are Linux x64/ARM64 (glibc), macOS ARM64, and Windows x64`
24
+ );
25
+ }
26
+ return packageName;
27
+ }
28
+
29
+ function packageForCurrentPlatform() {
30
+ return packageForPlatform(process.platform, process.arch);
31
+ }
32
+
33
+ module.exports = { packageForCurrentPlatform, packageForPlatform, usesGlibc };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "rmbg2-cli",
3
+ "version": "0.4.0",
4
+ "description": "Remove image backgrounds locally with BRIA RMBG-2.0",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/shayyz-code/rmbg-cli.git"
9
+ },
10
+ "homepage": "https://github.com/shayyz-code/rmbg-cli#readme",
11
+ "engines": {
12
+ "node": ">=18"
13
+ },
14
+ "bin": {
15
+ "rmbg": "npm/bin/rmbg.js"
16
+ },
17
+ "files": [
18
+ "npm/bin",
19
+ "npm/lib",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "optionalDependencies": {
24
+ "rmbg2-cli-darwin-arm64": "0.4.0",
25
+ "rmbg2-cli-linux-arm64-gnu": "0.4.0",
26
+ "rmbg2-cli-linux-x64-gnu": "0.4.0",
27
+ "rmbg2-cli-win32-x64-msvc": "0.4.0"
28
+ },
29
+ "scripts": {
30
+ "check:versions": "node npm/scripts/check-versions.js",
31
+ "test": "node --test npm/tests/*.test.js"
32
+ }
33
+ }