Xenova HF staff commited on
Commit
ca90787
1 Parent(s): a726baa

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +44 -0
README.md CHANGED
@@ -1,7 +1,51 @@
1
  ---
2
  library_name: transformers.js
 
3
  ---
4
 
5
  https://huggingface.co/nvidia/segformer-b3-finetuned-ade-512-512 with ONNX weights to be compatible with Transformers.js.
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  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`).
 
1
  ---
2
  library_name: transformers.js
3
+ pipeline_tag: image-segmentation
4
  ---
5
 
6
  https://huggingface.co/nvidia/segformer-b3-finetuned-ade-512-512 with ONNX weights to be compatible with Transformers.js.
7
 
8
+ ## Usage (Transformers.js)
9
+
10
+ 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/@xenova/transformers) using:
11
+ ```bash
12
+ npm i @xenova/transformers
13
+ ```
14
+
15
+ **Example:** Image segmentation with `Xenova/segformer-b3-finetuned-ade-512-512`.
16
+
17
+ ```js
18
+ import { pipeline } from '@xenova/transformers';
19
+
20
+ // Create an image segmentation pipeline
21
+ const segmenter = await pipeline('image-segmentation', 'Xenova/segformer-b3-finetuned-ade-512-512');
22
+
23
+ // Segment an image
24
+ const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/house.jpg';
25
+ const output = await segmenter(url);
26
+ console.log(output)
27
+ // [
28
+ // {
29
+ // score: null,
30
+ // label: 'wall',
31
+ // mask: RawImage { ... }
32
+ // },
33
+ // {
34
+ // score: null,
35
+ // label: 'building',
36
+ // mask: RawImage { ... }
37
+ // },
38
+ // ...
39
+ // ]
40
+ ```
41
+
42
+ You can visualize the outputs with:
43
+ ```js
44
+ for (const l of output) {
45
+ l.mask.save(`${l.label}.png`);
46
+ }
47
+ ```
48
+
49
+ ---
50
+
51
  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`).