captainspock
commited on
Commit
•
7be0a37
1
Parent(s):
ed4644a
Upload 4 files
Browse files- README.md +58 -0
- config.json +13 -0
- gitattributes +35 -0
- preprocessor_config.json +23 -0
README.md
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers.js
|
3 |
+
tags:
|
4 |
+
- vision
|
5 |
+
- background-removal
|
6 |
+
- portrait-matting
|
7 |
+
license: apache-2.0
|
8 |
+
pipeline_tag: image-segmentation
|
9 |
+
---
|
10 |
+
|
11 |
+
# Model Source
|
12 |
+
|
13 |
+
https://huggingface.co/onnx-community/modnet-webnn/
|
14 |
+
|
15 |
+
# MODNet: Trimap-Free Portrait Matting in Real Time
|
16 |
+
|
17 |
+
![image/gif](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/KdG3M8sltgiX8hOCNn8DT.gif)
|
18 |
+
|
19 |
+
For more information, check out the official [repository](https://github.com/ZHKKKe/MODNet) and example [colab](https://colab.research.google.com/drive/1P3cWtg8fnmu9karZHYDAtmm1vj1rgA-f?usp=sharing).
|
20 |
+
|
21 |
+
## Usage (Transformers.js)
|
22 |
+
|
23 |
+
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:
|
24 |
+
```bash
|
25 |
+
npm i @xenova/transformers
|
26 |
+
```
|
27 |
+
|
28 |
+
You can then use the model for portrait matting, as follows:
|
29 |
+
|
30 |
+
```js
|
31 |
+
import { AutoModel, AutoProcessor, RawImage } from '@xenova/transformers';
|
32 |
+
|
33 |
+
// Load model and processor
|
34 |
+
const model = await AutoModel.from_pretrained('Xenova/modnet', { quantized: false });
|
35 |
+
const processor = await AutoProcessor.from_pretrained('Xenova/modnet');
|
36 |
+
|
37 |
+
// Load image from URL
|
38 |
+
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
|
39 |
+
const image = await RawImage.fromURL(url);
|
40 |
+
|
41 |
+
// Pre-process image
|
42 |
+
const { pixel_values } = await processor(image);
|
43 |
+
|
44 |
+
// Predict alpha matte
|
45 |
+
const { output } = await model({ input: pixel_values });
|
46 |
+
|
47 |
+
// Save output mask
|
48 |
+
const mask = await RawImage.fromTensor(output[0].mul(255).to('uint8')).resize(image.width, image.height);
|
49 |
+
mask.save('mask.png');
|
50 |
+
```
|
51 |
+
|
52 |
+
| Input image | Output mask |
|
53 |
+
|--------|--------|
|
54 |
+
| ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/mhmDJgp5GgnbvQnUc2SVI.png) | ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/H1VBX6dS-xTpg14cl1Zxx.png) |
|
55 |
+
|
56 |
+
---
|
57 |
+
|
58 |
+
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`).
|
config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_type": "modnet",
|
3 |
+
"transformers.js_config": {
|
4 |
+
"device": "webnn-gpu",
|
5 |
+
"dtype": "fp16",
|
6 |
+
"free_dimension_overrides": {
|
7 |
+
"batch_size": 1,
|
8 |
+
"num_channels": 3,
|
9 |
+
"height": 256,
|
10 |
+
"width": 256
|
11 |
+
}
|
12 |
+
}
|
13 |
+
}
|
gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
preprocessor_config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_normalize": true,
|
3 |
+
"do_pad": false,
|
4 |
+
"do_rescale": true,
|
5 |
+
"do_resize": true,
|
6 |
+
"image_mean": [
|
7 |
+
0.5,
|
8 |
+
0.5,
|
9 |
+
0.5
|
10 |
+
],
|
11 |
+
"feature_extractor_type": "ImageFeatureExtractor",
|
12 |
+
"image_std": [
|
13 |
+
0.5,
|
14 |
+
0.5,
|
15 |
+
0.5
|
16 |
+
],
|
17 |
+
"resample": 2,
|
18 |
+
"rescale_factor": 0.00392156862745098,
|
19 |
+
"size": {
|
20 |
+
"width": 256,
|
21 |
+
"height": 256
|
22 |
+
}
|
23 |
+
}
|