Views
No views yet
npm i @huggingface/transformersonnx-community/maskformer-swin-small-ade.1import { pipeline } from '@huggingface/transformers';
2
3// Create an image segmentation pipeline
4const segmenter = await pipeline('image-segmentation', 'onnx-community/maskformer-swin-small-ade');
5
6// Segment an image
7const url = 'https://huggingface.co/datasets/hf-internal-testing/fixtures_ade20k/resolve/main/ADE_val_00000001.jpg';
8const output = await segmenter(url);
9console.log(output)
10// [
11// {
12// score: 0.9240802526473999,
13// label: 'plant',
14// mask: RawImage { ... }
15// },
16// {
17// score: 0.967036783695221,
18// label: 'house',
19// mask: RawImage { ... }
20// },
21// ...
22// }
23// ]1for (let i = 0; i < output.length; ++i) {
2 const { mask, label } = output[i];
3 mask.save(`${label}-${i}.png`);
4}onnx).