README.md
1.6 KB · 52 lines · markdown Raw
1 ---
2 base_model: nvidia/segformer-b0-finetuned-ade-512-512
3 library_name: transformers.js
4 pipeline_tag: image-segmentation
5 ---
6
7 https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512 with ONNX weights to be compatible with Transformers.js.
8
9 ## Usage (Transformers.js)
10
11 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:
12 ```bash
13 npm i @huggingface/transformers
14 ```
15
16 **Example:** Image segmentation with `Xenova/segformer-b0-finetuned-ade-512-512`.
17
18 ```js
19 import { pipeline } from '@huggingface/transformers';
20
21 // Create an image segmentation pipeline
22 const segmenter = await pipeline('image-segmentation', 'Xenova/segformer-b0-finetuned-ade-512-512');
23
24 // Segment an image
25 const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/house.jpg';
26 const output = await segmenter(url);
27 console.log(output)
28 // [
29 // {
30 // score: null,
31 // label: 'wall',
32 // mask: RawImage { ... }
33 // },
34 // {
35 // score: null,
36 // label: 'building',
37 // mask: RawImage { ... }
38 // },
39 // ...
40 // ]
41 ```
42
43 You can visualize the outputs with:
44 ```js
45 for (const l of output) {
46 l.mask.save(`${l.label}.png`);
47 }
48 ```
49
50 ---
51
52 Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).