metadata
library_name: transformers.js
pipeline_tag: image-segmentation
Usage (Transformers.js)
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @huggingface/transformers
Example: Semantic segmentation with onnx-community/sapiens-seg-0.3b
.
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:
for (const l of output) {
l.mask.save(`${l.label}.png`);
}