fix: use U2-Net as default model (fast, 2s) with BiRefNet as opt-in

BiRefNet-Lite times out on first load (~60s+ for 973MB model).
U2-Net works in 2 seconds. Users can still select BiRefNet for
higher quality when they're willing to wait. Added timing hints
in model descriptions and increased timeout for BiRefNet models.
This commit is contained in:
Siddharth Kumar Sah
2026-03-22 21:08:37 +08:00
parent cf68eaf732
commit fb1d366d5f
3 changed files with 12 additions and 9 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ def main():
output_path = sys.argv[2]
settings = json.loads(sys.argv[3]) if len(sys.argv) > 3 else {}
model = settings.get("model", "birefnet-general-lite")
model = settings.get("model", "u2net")
bg_color = settings.get("backgroundColor", "")
try:
+5 -2
View File
@@ -3,7 +3,8 @@ import { writeFile, readFile } from "node:fs/promises";
import { join } from "node:path";
export interface RemoveBackgroundOptions {
model?: "u2net" | "isnet";
model?: string;
backgroundColor?: string;
}
export async function removeBackground(
@@ -15,11 +16,13 @@ export async function removeBackground(
const outputPath = join(outputDir, "output_bg.png");
await writeFile(inputPath, inputBuffer);
// BiRefNet models need longer timeout (up to 10 min for first load)
const timeout = options.model?.startsWith("birefnet") ? 600000 : 300000;
const { stdout } = await runPythonScript("remove_bg.py", [
inputPath,
outputPath,
JSON.stringify(options),
]);
], timeout);
const result = JSON.parse(stdout);
if (!result.success) {