Commit
·
614b52f
1
Parent(s):
acfff92
Add ONNX model (fp32).
Browse files- README.md +53 -0
- config.json +20 -0
- onnx/model.onnx +3 -0
- preprocessor_config.json +27 -0
README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
pipeline_tag: image-segmentation
|
| 4 |
+
tags:
|
| 5 |
+
- image-segmentation
|
| 6 |
+
- mask-generation
|
| 7 |
+
- transformers.js
|
| 8 |
license: apache-2.0
|
| 9 |
+
language:
|
| 10 |
+
- en
|
| 11 |
---
|
| 12 |
+
# U-2-Net
|
| 13 |
+
|
| 14 |
+
## Model Description
|
| 15 |
+
U-2-Net is a deep learning model designed for image segmentation tasks, particularly for generating detailed masks. It leverages a unique architecture with nested U-blocks that allow the model to capture both high-level semantic features and fine-grained details. U-2-Net has demonstrated high performance in a variety of segmentation tasks, making it a versatile choice for applications such as background removal, object detection, and medical image analysis.
|
| 16 |
+
|
| 17 |
+
## Usage
|
| 18 |
+
Perform mask generation with `BritishWerewolf/U-2-Net`.
|
| 19 |
+
|
| 20 |
+
### Example
|
| 21 |
+
```javascript
|
| 22 |
+
import { AutoModel, AutoProcessor, RawImage } from '@huggingface/transformers';
|
| 23 |
+
|
| 24 |
+
const img_url = 'https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png';
|
| 25 |
+
const image = await RawImage.read(img_url);
|
| 26 |
+
|
| 27 |
+
const processor = await AutoProcessor.from_pretrained('BritishWerewolf/U-2-Net');
|
| 28 |
+
const processed = await processor(image);
|
| 29 |
+
|
| 30 |
+
const model = await AutoModel.from_pretrained('BritishWerewolf/U-2-Net', {
|
| 31 |
+
dtype: 'fp32',
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
const output = await model({ input: processed.pixel_values });
|
| 35 |
+
// {
|
| 36 |
+
// mask: Tensor {
|
| 37 |
+
// dims: [ 1, 320, 320 ],
|
| 38 |
+
// type: 'uint8',
|
| 39 |
+
// data: Uint8Array(102400) [ ... ],
|
| 40 |
+
// size: 102400
|
| 41 |
+
// }
|
| 42 |
+
// }
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
## Model Architecture
|
| 46 |
+
The U-2-Net model is built upon a nested U-structure, where each U-block consists of multiple convolutional layers, pooling, and up-sampling operations. The architecture features a combination of down-sampling and up-sampling paths, enabling the model to learn features at different scales. This design allows the U-2-Net to produce accurate and high-resolution segmentation maps. The key components of the architecture include Residual U-blocks (RSU) that enhance feature representation and ensure efficient information flow through the network.
|
| 47 |
+
|
| 48 |
+
### Inference
|
| 49 |
+
To use the model for inference, you can follow the example provided above. The `AutoProcessor` and `AutoModel` classes from the `transformers` library make it easy to load the model and processor.
|
| 50 |
+
|
| 51 |
+
## Credits
|
| 52 |
+
* [`rembg`](https://github.com/danielgatis/rembg) for the ONNX model.
|
| 53 |
+
* The authors of the original U-2-Net model can be credited at https://github.com/xuebinqin/U-2-Net.
|
| 54 |
+
|
| 55 |
+
## Licence
|
| 56 |
+
This model is licensed under the Apache License 2.0 to match the original U-2-Net model.
|
config.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "u2net",
|
| 3 |
+
"model_type": "u2net",
|
| 4 |
+
"architectures": [
|
| 5 |
+
"U2NetModel"
|
| 6 |
+
],
|
| 7 |
+
"input_name": ["input.1"],
|
| 8 |
+
"input_shape": [1, 3, 320, 320],
|
| 9 |
+
"output_composite": "1959",
|
| 10 |
+
"output_names": [
|
| 11 |
+
"1959",
|
| 12 |
+
"1960",
|
| 13 |
+
"1961",
|
| 14 |
+
"1962",
|
| 15 |
+
"1963",
|
| 16 |
+
"1964",
|
| 17 |
+
"1965"
|
| 18 |
+
],
|
| 19 |
+
"output_shape": [1, 320, 320]
|
| 20 |
+
}
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8d10d2f3bb75ae3b6d527c77944fc5e7dcd94b29809d47a739a7a728a912b491
|
| 3 |
+
size 175997641
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"processor_class": "U2NetProcessor",
|
| 3 |
+
"image_processor_type": "U2NetImageProcessor",
|
| 4 |
+
"do_convert_rgb": true,
|
| 5 |
+
"do_normalize": true,
|
| 6 |
+
"do_pad": true,
|
| 7 |
+
"do_rescale": true,
|
| 8 |
+
"do_resize": true,
|
| 9 |
+
"keep_aspect_ratio": true,
|
| 10 |
+
"image_mean": [
|
| 11 |
+
0.485,
|
| 12 |
+
0.456,
|
| 13 |
+
0.406
|
| 14 |
+
],
|
| 15 |
+
"image_std": [
|
| 16 |
+
0.229,
|
| 17 |
+
0.224,
|
| 18 |
+
0.225
|
| 19 |
+
],
|
| 20 |
+
"pad_size": {
|
| 21 |
+
"width": 320,
|
| 22 |
+
"height": 320
|
| 23 |
+
},
|
| 24 |
+
"size": {
|
| 25 |
+
"longest_edge": 320
|
| 26 |
+
}
|
| 27 |
+
}
|