Views
No views yet
npm i @huggingface/transformersonnx-community/maskformer-resnet101-cityscapes.1import { pipeline } from '@huggingface/transformers';
2
3// Create an image segmentation pipeline
4const segmenter = await pipeline('image-segmentation', 'onnx-community/maskformer-resnet101-cityscapes');
5
6// Segment an image
7const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cityscapes.png';
8const output = await segmenter(url);
9console.log(output)
10// [
11// {
12// score: 0.9999792575836182,
13// label: 'car',
14// mask: RawImage { ... }
15// },
16// {
17// score: 0.9999257326126099,
18// label: 'traffic light',
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).