--- library_name: transformers.js pipeline_tag: image-segmentation --- ## Usage (Transformers.js) If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using: ```bash npm i @huggingface/transformers ``` **Example:** Semantic segmentation with `onnx-community/sapiens-seg-0.3b`. ```js import { pipeline } from '@huggingface/transformers'; const segmenter = await pipeline('image-segmentation', 'onnx-community/sapiens-seg-0.3b'); const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/ryan-gosling.jpg'; const output = await segmenter(url); console.log(output) // [ // { // score: null, // label: 'Background', // mask: RawImage { ... } // }, // { // score: null, // label: 'Apparel', // mask: RawImage { ... } // }, // ... // ] ``` You can visualize the outputs with: ```js for (const l of output) { l.mask.save(`${l.label}.png`); } ```