Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers.js
|
| 3 |
+
pipeline_tag: image-segmentation
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
## Usage (Transformers.js)
|
| 7 |
+
|
| 8 |
+
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:
|
| 9 |
+
```bash
|
| 10 |
+
npm i @huggingface/transformers
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
**Example:** Semantic segmentation with `onnx-community/sapiens-seg-0.3b`.
|
| 14 |
+
|
| 15 |
+
```js
|
| 16 |
+
import { pipeline } from '@huggingface/transformers';
|
| 17 |
+
|
| 18 |
+
const segmenter = await pipeline('image-segmentation', 'onnx-community/sapiens-seg-0.3b');
|
| 19 |
+
|
| 20 |
+
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/ryan-gosling.jpg';
|
| 21 |
+
const output = await segmenter(url);
|
| 22 |
+
console.log(output)
|
| 23 |
+
// [
|
| 24 |
+
// {
|
| 25 |
+
// score: null,
|
| 26 |
+
// label: 'Background',
|
| 27 |
+
// mask: RawImage { ... }
|
| 28 |
+
// },
|
| 29 |
+
// {
|
| 30 |
+
// score: null,
|
| 31 |
+
// label: 'Apparel',
|
| 32 |
+
// mask: RawImage { ... }
|
| 33 |
+
// },
|
| 34 |
+
// ...
|
| 35 |
+
// ]
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
You can visualize the outputs with:
|
| 39 |
+
```js
|
| 40 |
+
for (const l of output) {
|
| 41 |
+
l.mask.save(`${l.label}.png`);
|
| 42 |
+
}
|
| 43 |
+
```
|