Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Segformer #480

Merged
merged 3 commits into from
Dec 27, 2023
Merged

Add support for Segformer #480

merged 3 commits into from
Dec 27, 2023

Conversation

xenova
Copy link
Collaborator

@xenova xenova commented Dec 26, 2023

Example usage

Semantic segmentation

import { pipeline } from '@xenova/transformers';

const segmenter = await pipeline('image-segmentation', 'Xenova/segformer_b2_clothes', { quantized: false });

const url = "https://freerangestock.com/sample/139043/young-man-standing-and-leaning-on-car.jpg"
const output = await segmenter(url);
console.log(output)
// [
//   {
//     score: null,
//     label: 'Background',
//     mask: RawImage { ... }
//   },
//   {
//     score: null,
//     label: 'Hair',
//     mask: RawImage { ... }
//   },
//   ...
//   }
// ]

// Visualize images
for (const l of output) {
  l.mask.save(`${l.label}.png`);
}

semantic-segmentation

Image classification

import { pipeline } from '@xenova/transformers';

const classifier = await pipeline('image-classification', 'Xenova/mit-b0');
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg';
const output = await classifier(url);
console.log(output)
// [{ label: 'tiger, Panthera tigris', score: 0.5399330854415894 }]

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@xenova xenova merged commit 80af1c4 into main Dec 27, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants