Views
No views yet
npm i @huggingface/transformersonnx-community/maskformer-swin-tiny-coco.1import { pipeline } from '@huggingface/transformers';
2
3// Create an image segmentation pipeline
4const segmenter = await pipeline('image-segmentation', 'onnx-community/maskformer-swin-tiny-coco');
5
6// Segment an image
7const url = 'http://images.cocodataset.org/val2017/000000039769.jpg';
8const output = await segmenter(url);
9console.log(output)
10// [
11// {
12// score: 0.9626941680908203,
13// label: 'couch',
14// mask: RawImage { ... }
15// },
16// {
17// score: 0.9967071413993835,
18// label: 'cat',
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).