Description
Describe the issue
When testing Transformers.js v3.4 on WASM, I ran into an issue where values for MODNet were outside the bounds of 0 → 1. This causes the background-removal pipeline to perform a sigmoid operation to ensure all values are between 0 and 1.
Input | Output (WASM) | Output (WebGPU) |
---|---|---|
![]() |
![]() |
![]() |
Inspecting the graph, it's clear that a sigmoid is applied in the graph, so it seems as though the only explanation for the above is that another sigmoid is applied since some value is below 0 or above 1. Inspecting the alpha values of the WASM image shows that indeed, sigmoid(0)=0.5, and sigmoid(1)≈0.73.
To reproduce
WASM (incorrect)
https://jsfiddle.net/9hvyxft7/
<script type="module">
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]';
const segmenter = await pipeline("background-removal", "Xenova/modnet", { device: "wasm", dtype: "fp32" });
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro_medium.jpg';
const output = await segmenter(url);
output[0].save("output.png"); // (Optional) Save the image
</script>
WebGPU (correct)
https://jsfiddle.net/ctdhewgo/
<script type="module">
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]';
const segmenter = await pipeline("background-removal", "Xenova/modnet", { device: "webgpu", dtype: "fp32" });
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/woman-with-afro_medium.jpg';
const output = await segmenter(url);
output[0].save("output.png"); // (Optional) Save the image
</script>
Urgency
Causes issues in Transformers.js v3.4. This may have wider implications for the CPU backend too, but I'm not sure as it seems to work correctly in Node.js.
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.22.0-dev.20250306-ccf8fdd9ea
Execution Provider
'wasm'/'cpu' (WebAssembly CPU)