ONNX
File size: 4,740 Bytes
23c2970
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
license: apache-2.0
---

# WithoutBG Snap Models

**Free, high-quality background removal models powered by AI**

[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![ONNX Runtime](https://img.shields.io/badge/Runtime-ONNX-orange.svg)](https://onnxruntime.ai/)

This repository contains the **Snap tier** models for the [withoutbg](https://github.com/withoutbg/withoutbg) library - a complete set of ONNX models for local, free background removal processing.

## πŸ“‹ Model Overview

The Snap tier implements a sophisticated 3-stage pipeline for background removal:

| Model | File | Purpose | Input | Output | License |
|-------|------|---------|-------|---------|---------|
| **Depth Estimation** | `depth_anything_v2_vits_slim.onnx` | Stage 1: Depth map generation | RGB (518Γ—518) | Inverse depth map | Apache 2.0 |
| **Matting** | `snap_matting_0.1.0.onnx` | Stage 2: Initial background separation | RGBD (256Γ—256) | Alpha channel (A1) | Apache 2.0 |
| **Refiner** | `snap_refiner_0.1.0.onnx` | Stage 3: High-resolution refinement | RGB+D+A (original size) | Refined alpha (A2) | Apache 2.0 |

## πŸš€ Quick Start

### Using the withoutbg library (Recommended)

```bash
pip install withoutbg
```

```python
from withoutbg import remove_background

# Automatically downloads and uses these models
result = remove_background("image.jpg")
result.save("output.png")
```


## πŸ”„ Processing Pipeline

### Stage 1: Depth Estimation
- **Model**: Depth Anything V2 ViT-S (Apache 2.0 licensed)
- **Input**: RGB image (518Γ—518 pixels, ImageNet normalized)
- **Output**: Inverse depth map (0-255 range)
- **Purpose**: Provides spatial understanding for better background separation

### Stage 2: Matting
- **Input**: RGBD (RGB + depth concatenated as 4-channel input, 256Γ—256)
- **Output**: Initial alpha channel (A1)
- **Purpose**: Performs initial foreground/background segmentation

### Stage 3: Refining
- **Input**: RGB + depth + A1 (5-channel input at original resolution)
- **Output**: Refined alpha channel (A2) with high detail
- **Purpose**: Enhances edge quality and removes artifacts


## πŸ”§ Technical Specifications

### Model Details
- **Framework**: ONNX (compatible with ONNX Runtime)
- **Providers**: CPU, CUDA (automatically detected)
- **Precision**: FP32
- **Total Size**: ~140 MB (all three models)

### Input Requirements
- **Format**: RGB images (any resolution)
- **Preprocessing**: Automatic resizing and normalization
- **Output**: RGBA images with transparent background

## πŸ—οΈ Integration Examples

### Batch Processing
```python
from withoutbg import remove_background_batch

results = remove_background_batch([
    "image1.jpg", 
    "image2.jpg", 
    "image3.jpg"
], output_dir="results/")
```

### Custom Model Paths
```python
from withoutbg.models import SnapModel

model = SnapModel(
    depth_model_path="custom/depth_model.onnx",
    matting_model_path="custom/matting_model.onnx", 
    refiner_model_path="custom/refiner_model.onnx"
)

result = model.remove_background("image.jpg")
```

## πŸ“„ Licensing

### Open Source Components
- **`depth_anything_v2_vits_slim.onnx`**: Apache 2.0 License
  - Based on [Depth-Anything V2](https://github.com/DepthAnything/Depth-Anything-V2)

### Snap Tier Components  
- **`snap_matting_0.1.0.onnx`**: Apache 2.0 License
- **`snap_refiner_0.1.0.onnx`**: Apache 2.0 License
- Free for commercial and non-commercial use
- Open source models for the Snap tier

## πŸ”— Related Links

- **Main Library**: [withoutbg/withoutbg](https://github.com/withoutbg/withoutbg)
- **Documentation**: [withoutbg.com/docs](https://withoutbg.com/documentation)
- **Demo**: [Hugging Face Space](https://huggingface.co/spaces/withoutbg/demo)
- **Commercial Licensing**: [withoutbg.com/focus](https://withoutbg.com/focus)

## 🎯 Use Cases

- **Development & Prototyping**: Free local processing
- **E-commerce**: Product photo background removal  
- **Social Media**: Profile picture editing
- **Content Creation**: Video thumbnails and graphics

## 🀝 Contributing

We welcome improvements to the open source components:

1. **Depth Anything V2 optimizations**: Submit PRs to improve inference speed
2. **Preprocessing enhancements**: Better image handling and normalization
3. **Documentation**: Examples, tutorials, and integration guides
4. **Bug reports**: Issues with model loading or inference

## πŸ“§ Support

- **Technical Issues**: [GitHub Issues](https://github.com/withoutbg/withoutbg/issues)
- **Community**: [GitHub Discussions](https://github.com/withoutbg/withoutbg/discussions)

---

**Try the models**: Install `pip install withoutbg` and start removing backgrounds instantly!