Instructions to use moonbox-dev/ormbg-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use moonbox-dev/ormbg-MLX with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download moonbox-dev/ormbg-MLX --local-dir ormbg-MLX
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Model card and the original license
Browse files- .gitattributes +4 -0
- README.md +126 -0
- example.png +3 -0
- examples.jpg +3 -0
- explanation.jpg +3 -0
- no-background.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
+
example.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
examples.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
explanation.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
no-background.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: schirrmacher/ormbg
|
| 3 |
+
base_model_relation: quantized
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
pipeline_tag: image-segmentation
|
| 6 |
+
library_name: mlx
|
| 7 |
+
tags:
|
| 8 |
+
- mlx
|
| 9 |
+
- moonbox
|
| 10 |
+
- background-removal
|
| 11 |
+
- isnet
|
| 12 |
+
- image-matting
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# ORMBG MLX
|
| 16 |
+
|
| 17 |
+
MLX builds of [ORMBG](https://huggingface.co/schirrmacher/ormbg), made by Moonbox for Apple Silicon Macs. Each precision is a folder; keep a folder's
|
| 18 |
+
files together. Only the parts listed below are converted: the rest of the pipeline comes from the original
|
| 19 |
+
repository unless the section below says otherwise.
|
| 20 |
+
|
| 21 |
+
## Files
|
| 22 |
+
|
| 23 |
+
The last column is how far each build is from the original PyTorch model on the same inputs (see the section below
|
| 24 |
+
for what was measured).
|
| 25 |
+
|
| 26 |
+
| Precision | File | Size | sha256 | Checked against the original |
|
| 27 |
+
|---|---|---|---|---|
|
| 28 |
+
| fp16 | [`fp16/config.json`](https://huggingface.co/moonbox-ai/ormbg-MLX/blob/main/fp16/config.json) | 0.1 kB | `484d65d02eff` | alpha MAE <= 0.0004, mask IoU >= 0.998 |
|
| 29 |
+
| fp16 | [`fp16/mlx_model.py`](https://huggingface.co/moonbox-ai/ormbg-MLX/blob/main/fp16/mlx_model.py) | 8.2 kB | `8cf5c652dcbb` | alpha MAE <= 0.0004, mask IoU >= 0.998 |
|
| 30 |
+
| fp16 | [`fp16/model.safetensors`](https://huggingface.co/moonbox-ai/ormbg-MLX/blob/main/fp16/model.safetensors) | 88.0 MB | `a7f5a13a20a9` | alpha MAE <= 0.0004, mask IoU >= 0.998 |
|
| 31 |
+
|
| 32 |
+
## How to run
|
| 33 |
+
|
| 34 |
+
ORMBG ported to MLX. Each folder holds `model.safetensors`, `config.json` and `mlx_model.py`, the port (only `mlx`
|
| 35 |
+
and `numpy` needed):
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
import numpy as np, mlx_model
|
| 39 |
+
from PIL import Image
|
| 40 |
+
model = mlx_model.load("fp16")
|
| 41 |
+
rgb = np.array(Image.open("in.jpg").convert("RGB"))
|
| 42 |
+
alpha = mlx_model.matte(model, rgb) # HxW uint8, as ormbg/inference.py (input resized to 1024x1024)
|
| 43 |
+
Image.fromarray(np.dstack([rgb, alpha])).save("cutout.png")
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
The BatchNorm layers are folded into the convolutions. There are no 8bit / 6bit / 4bit builds: the network is all
|
| 47 |
+
convolutions, which MLX doesn't quantize.
|
| 48 |
+
|
| 49 |
+
| Precision | Size | Alpha MAE vs PyTorch fp32 (worst image) | Mask IoU (worst) | Time per image on an M5 |
|
| 50 |
+
|---|---|---|---|---|
|
| 51 |
+
| `fp16/` | 88 MB | 0.0004 | 0.998 | 0.17 s |
|
| 52 |
+
| `bf16/` | 88 MB | 0.0026 | 0.987 | 0.18 s |
|
| 53 |
+
|
| 54 |
+
## How these were made
|
| 55 |
+
|
| 56 |
+
From [ORMBG](https://huggingface.co/schirrmacher/ormbg) at revision `6253b31824`: the original weights loaded in MLX and stored as bf16 or fp16, or
|
| 57 |
+
quantized with MLX's affine quantization (`8bit`, `6bit`, `4bit`, group size 64; layers MLX can't quantize, such as
|
| 58 |
+
convolutions and norms, stay bf16). Every build was checked against the original before upload; the `sha256` column
|
| 59 |
+
above is what the files must hash to.
|
| 60 |
+
|
| 61 |
+
## License
|
| 62 |
+
|
| 63 |
+
Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this
|
| 64 |
+
repository, and it governs your use of these files. The original model card follows unchanged.
|
| 65 |
+
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
# Original model card
|
| 69 |
+
|
| 70 |
+
# Open Remove Background Model (ormbg)
|
| 71 |
+
|
| 72 |
+
[>>> DEMO <<<](https://huggingface.co/spaces/schirrmacher/ormbg)
|
| 73 |
+
|
| 74 |
+
Join our [Research Discord Group](https://discord.gg/YYZ3D66t)!
|
| 75 |
+
|
| 76 |
+

|
| 77 |
+
|
| 78 |
+
This model is a **fully open-source background remover** optimized for images with humans. It is based on [Highly Accurate Dichotomous Image Segmentation research](https://github.com/xuebinqin/DIS).
|
| 79 |
+
|
| 80 |
+
## Inference
|
| 81 |
+
|
| 82 |
+
```
|
| 83 |
+
python ormbg/inference.py
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## Training
|
| 87 |
+
|
| 88 |
+
Install dependencies:
|
| 89 |
+
|
| 90 |
+
```
|
| 91 |
+
conda env create -f environment.yaml
|
| 92 |
+
conda activate ormbg
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
Replace dummy dataset with [training dataset](https://huggingface.co/datasets/schirrmacher/humans).
|
| 96 |
+
|
| 97 |
+
```
|
| 98 |
+
python3 ormbg/train_model.py
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
# Research
|
| 102 |
+
|
| 103 |
+
I started training the model with synthetic images of the [Human Segmentation Dataset](https://huggingface.co/datasets/schirrmacher/humans) crafted with [LayerDiffuse](https://github.com/layerdiffusion/LayerDiffuse). However, I noticed that the model struggles to perform well on real images.
|
| 104 |
+
|
| 105 |
+
Synthetic datasets have limitations for achieving great segmentation results. This is because artificial lighting, occlusion, scale or backgrounds create a gap between synthetic and real images. A "model trained solely on synthetic data generated with naïve domain randomization struggles to generalize on the real domain", see [PEOPLESANSPEOPLE: A Synthetic Data Generator for Human-Centric Computer Vision (2022)](https://arxiv.org/pdf/2112.09290).
|
| 106 |
+
|
| 107 |
+
### Next steps:
|
| 108 |
+
|
| 109 |
+
- Expand dataset with synthetic and real images
|
| 110 |
+
- Research on state of the art loss functions
|
| 111 |
+
|
| 112 |
+
### Latest changes (26/07/2024):
|
| 113 |
+
|
| 114 |
+
- Created synthetic dataset with 10k images, crafted with [BlenderProc](https://github.com/DLR-RM/BlenderProc)
|
| 115 |
+
- Removed training data created with [LayerDiffuse](https://github.com/layerdiffusion/LayerDiffuse), since it lacks the accuracy needed
|
| 116 |
+
- Improved model performance (after 100k iterations):
|
| 117 |
+
- F1: 0.9888 -> 0.9932
|
| 118 |
+
- MAE: 0.0113 -> 0.008
|
| 119 |
+
- Scores based on [this validation dataset](https://drive.google.com/drive/folders/1Yy9clZ58xCiai1zYESQkEKZCkslSC8eg)
|
| 120 |
+
|
| 121 |
+
### 05/07/2024
|
| 122 |
+
|
| 123 |
+
- Added [P3M-10K](https://paperswithcode.com/dataset/p3m-10k) dataset for training and validation
|
| 124 |
+
- Added [AIM-500](https://paperswithcode.com/dataset/aim-500) dataset for training and validation
|
| 125 |
+
- Added [PPM-100](https://github.com/ZHKKKe/PPM) dataset for training and validation
|
| 126 |
+
- Applied [Grid Dropout](https://albumentations.ai/docs/api_reference/augmentations/dropout/grid_dropout/) to make the model smarter
|
example.png
ADDED
|
Git LFS Details
|
examples.jpg
ADDED
|
Git LFS Details
|
explanation.jpg
ADDED
|
Git LFS Details
|
no-background.png
ADDED
|
Git LFS Details
|