Xenova HF staff commited on
Commit
fa76b39
1 Parent(s): ad19ebf

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +44 -0
README.md CHANGED
@@ -4,4 +4,48 @@ library_name: transformers.js
4
 
5
  https://huggingface.co/jonathandinu/face-parsing 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/jonathandinu/face-parsing 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:** Face segmentation with `Xenova/face-parsing`.
15
+
16
+ ```js
17
+ import { pipeline } from '@xenova/transformers';
18
+
19
+ const segmenter = await pipeline('image-segmentation', 'Xenova/face-parsing');
20
+
21
+ const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/portrait-of-woman.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: 'skin.png',
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
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/530NS10pjaIlycdGWp9E9.png)
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`).