Update README.md
Browse files
README.md
CHANGED
@@ -5,4 +5,49 @@ pipeline_tag: image-segmentation
|
|
5 |
|
6 |
https://huggingface.co/facebook/maskformer-swin-small-ade with ONNX weights to be compatible with Transformers.js.
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
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`).
|
|
|
5 |
|
6 |
https://huggingface.co/facebook/maskformer-swin-small-ade 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/@huggingface/transformers) using:
|
11 |
+
```bash
|
12 |
+
npm i @huggingface/transformers
|
13 |
+
```
|
14 |
+
|
15 |
+
**Example:** Face segmentation with `onnx-community/maskformer-swin-small-ade`.
|
16 |
+
|
17 |
+
```js
|
18 |
+
import { pipeline } from '@huggingface/transformers';
|
19 |
+
|
20 |
+
// Create an image segmentation pipeline
|
21 |
+
const segmenter = await pipeline('image-segmentation', 'onnx-community/maskformer-swin-small-ade');
|
22 |
+
|
23 |
+
// Segment an image
|
24 |
+
const url = 'http://images.cocodataset.org/val2017/000000039769.jpg';
|
25 |
+
const output = await segmenter(url);
|
26 |
+
console.log(output)
|
27 |
+
// [
|
28 |
+
// {
|
29 |
+
// score: 0.9626941680908203,
|
30 |
+
// label: 'couch',
|
31 |
+
// mask: RawImage { ... }
|
32 |
+
// },
|
33 |
+
// {
|
34 |
+
// score: 0.9967071413993835,
|
35 |
+
// label: 'cat',
|
36 |
+
// mask: RawImage { ... }
|
37 |
+
// },
|
38 |
+
// ...
|
39 |
+
// }
|
40 |
+
// ]
|
41 |
+
```
|
42 |
+
|
43 |
+
You can visualize the outputs with:
|
44 |
+
```js
|
45 |
+
for (let i = 0; i < output.length; ++i) {
|
46 |
+
const { mask, label } = output[i];
|
47 |
+
mask.save(`${label}-${i}.png`);
|
48 |
+
}
|
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`).
|