Xenova HF staff commited on
Commit
01e9693
1 Parent(s): 7745e12

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +46 -0
README.md CHANGED
@@ -4,4 +4,50 @@ library_name: transformers.js
4
 
5
  https://huggingface.co/mattmdjaga/segformer_b2_clothes 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`).
 
4
 
5
  https://huggingface.co/mattmdjaga/segformer_b2_clothes with ONNX weights to be compatible with Transformers.js.
6
 
7
+ ## Usage (Transformers.js)
8
+
9
+ 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:
10
+ ```bash
11
+ npm i @xenova/transformers
12
+ ```
13
+
14
+ **Example:** Clothes segmentation with `Xenova/segformer_b2_clothes`.
15
+
16
+ ```js
17
+ import { pipeline } from '@xenova/transformers';
18
+
19
+ const segmenter = await pipeline('image-segmentation', 'Xenova/segformer_b2_clothes');
20
+
21
+ const url = 'https://freerangestock.com/sample/139043/young-man-standing-and-leaning-on-car.jpg';
22
+ const output = await segmenter(url);
23
+ console.log(output)
24
+ // [
25
+ // {
26
+ // score: null,
27
+ // label: 'Background',
28
+ // mask: RawImage { ... }
29
+ // },
30
+ // {
31
+ // score: null,
32
+ // label: 'Hair',
33
+ // mask: RawImage { ... }
34
+ // },
35
+ // ...
36
+ // }
37
+ // ]
38
+ ```
39
+
40
+ You can visualize the outputs with:
41
+ ```js
42
+ for (const l of output) {
43
+ l.mask.save(`${l.label}.png`);
44
+ }
45
+ ```
46
+
47
+
48
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/surPAnEVlas1VbHGWAcR0.png)
49
+
50
+ ---
51
+
52
+
53
  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`).