File size: 1,050 Bytes
68828f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
---
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`);
}
``` |