Mediapipe Selfie Segmentation
If you haven't already, you can install the Transformers.js JavaScript library from NPM using: npm i @huggingface/transformers
Source du modèle
- Type
- Other
- Taille du fichier
- 219–452 KB
- Version
- vRevision be49485
- Mis à jour
- 20 oct. 2026
- Téléchargements
- 807
- Source
- Hugging Face
Description de la source
Usage (Transformers.js)
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @huggingface/transformers
Example: Selfie segmentation with onnx-community/mediapipe_selfie_segmentation.
import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
// Load model and processor
const model_id = 'onnx-community/mediapipe_selfie_segmentation';
const model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' });
const processor = await AutoProcessor.from_pretrained(model_id);
// Load image from URL
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/selfie_segmentation.png';
const image = await RawImage.read(url);
// Pre-process image
const inputs = await processor(image);
// Predict alpha matte
const { alphas } = await model(inputs);
// Save output mask
const mask = await RawImage.fromTensor(alphas[0].mul(255).to('uint8')).resize(image.width, image.height);
mask.save('mask.png');
// (Optional) Apply mask to original image
const result = image.clone().putAlpha(mask);
result.save('result.png');
| Input image | Predicted mask | Output image |
|---|---|---|
| image/png | image/png | image/png |
Sources
1 source
Sources
1 sourceVérifié 20 oct.
Artefacts du modèle
8 artefacts
Artefacts du modèle
8 artefactsExtraits de sources
3 extraits
Extraits de sources
3 extraits--- license: apache-2.0 pipeline_tag: image-segmentation tags: - background-removal --- ## Usage (Transformers.js) If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using: ```bash npm i @huggingface/transformers ``` **Example:** Selfie segmentation with `onnx-community/mediapipe_selfie_segmentation`. ```js import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers'; // Load model and processor const model_id = 'onnx-community/mediapipe_selfie_segmentation'; const model = await AutoModel.from_pretrained(model_id, { dtype: 'fp32' }); const processor = await AutoProcessor.from_pretrained(model_id); // Load image from URL const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/selfie_segmentation.png'; const image = await RawImage.read(url); // Pre-process image const inputs = await processor(image); // Predict alpha matte const { alphas } = await model(inputs); // Save output mask const mask = await RawImage.fromTensor(alphas[0].mul(255).to('uint8')).resize(image.width, image.height); mask.save('mask.png'); // (Optional) Apply mask to original image const result = image.clone().putAlpha(mask); result.save('result.png'); ``` | Input image | Predicted mask | Output image | | :----------:|:------------:|:------------:| |  |  |  |
Source context: 807 downloads · 7 likes · Pipeline image-segmentation · Repo onnx-community/mediapipe_selfie_segmentation
Source context: 671 downloads · 5 likes · Pipeline image-segmentation · Repo onnx-community/mediapipe_selfie_segmentation
