File size: 894 Bytes
28e1bbf a643398 c25db7d a643398 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
---
license: agpl-3.0
pipeline_tag: image-segmentation
library_name: transformers.js
tags:
- background-removal
---
## Usage (Transformers.js)
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:
```bash
npm i @huggingface/transformers
```
**Example**: Remove background of an image
```js
import { pipeline } from '@huggingface/transformers';
const segmenter = await pipeline('background-removal', 'onnx-community/ISNet-ONNX');
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
const output = await segmenter(url);
output[0].save('mask.png');
// You can also use `output[0].toCanvas()` or `await output[0].toBlob()` if you would like to access the output without saving.
```
|