File size: 3,889 Bytes
d2f14a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0da071b
d2f14a1
 
0da071b
d2f14a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0da071b
 
d2f14a1
 
 
 
 
 
 
0da071b
 
 
 
 
 
d2f14a1
 
 
0da071b
 
 
 
 
 
 
 
d2f14a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: cc-by-nc-4.0
library_name: coreml
pipeline_tag: image-segmentation
tags:
  - background-removal
  - image-segmentation
  - coreml
  - apple-neural-engine
  - birefnet
  - rmbg
language:
  - en
base_model: briaai/RMBG-2.0
---

# RMBG-2 CoreML - Background Removal Model

CoreML conversion of [BRIA AI's RMBG-2.0](https://huggingface.co/briaai/RMBG-2.0) background removal model, optimized for Apple Neural Engine (ANE).

## Model Description

This is a native ML Program format CoreML model converted from RMBG-2.0 (BiRefNet architecture) for high-quality background removal on Apple devices.

### Key Features

- **Native CoreML ML Program format** - Full ANE compatibility
- **INT8 weight quantization** - Reduced model size (233MB vs 461MB)
- **No custom layers** - Uses only native CoreML operations
- **1024x1024 input resolution** - High-quality segmentation
- **Fast inference** - ~3-5 seconds on Apple Silicon

## Usage

### With RMBG2Swift Package

```swift
import RMBG2Swift

// Simple one-liner
let rmbg = try await RMBG2()
let result = try await rmbg.removeBackground(from: image)

// Access the result
let outputImage = result.image  // Image with transparent background
let mask = result.mask          // Grayscale segmentation mask
```

**Swift Package:** [github.com/VincentGourbin/RMBG2Swift](https://github.com/VincentGourbin/RMBG2Swift)

### Manual Integration

```swift
import CoreML

// Load the model
let config = MLModelConfiguration()
config.computeUnits = .all  // Enable ANE

let model = try await MLModel.load(contentsOf: modelURL, configuration: config)

// Prepare input (1024x1024, NCHW format with ImageNet normalization)
let input = MLDictionaryFeatureProvider(dictionary: ["input": inputArray])

// Run inference
let output = try model.prediction(from: input)

// Get mask from output_3 (full resolution)
let mask = output.featureValue(for: "output_3")?.multiArrayValue
```

## Model Details

| Property | Value |
|----------|-------|
| Architecture | BiRefNet |
| Input Size | 1024 x 1024 |
| Input Format | RGB, NCHW [1, 3, 1024, 1024] |
| Normalization | ImageNet (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) |
| Output | 4 scales (output_0 to output_3), use output_3 for full resolution |
| Format | ML Program (.mlpackage) |
| Weight Quantization | INT8 (symmetric linear) |
| Model Size | ~233 MB |
| Minimum OS | macOS 13+ / iOS 16+ |
| Compute Units | All (CPU, GPU, ANE) |

## Performance

Tested on Apple Silicon:

| Device | Compute Units | Inference Time |
|--------|--------------|---------------|
| M1 Pro | .all (ANE) | ~5s |
| M1 Pro | .cpuAndGPU | ~3s |

> Note: ANE performance varies by device. The INT8 quantization improves memory efficiency and model size while maintaining quality.

## Files

Two model versions are available:

| File | Size | Description |
|------|------|-------------|
| `RMBG-2-native.mlpackage/` | 461 MB | Original FP32 model |
| `RMBG-2-native-int8.mlpackage/` | 233 MB | INT8 quantized model (recommended) |

**Recommended:** Use the INT8 version for better memory efficiency and smaller download size with equivalent quality.

## License

**Creative Commons Attribution-NonCommercial 4.0 (CC BY-NC 4.0)**

- **Free for non-commercial use**: Research, personal projects, education
- **Commercial use requires a separate license** from BRIA AI

For commercial licensing, contact: [bria.ai/contact-us](https://bria.ai/contact-us)

## Attribution

This CoreML conversion is based on the RMBG-2.0 model by BRIA AI:

- **Original Model**: [briaai/RMBG-2.0](https://huggingface.co/briaai/RMBG-2.0)
- **Architecture**: BiRefNet
- **Creator**: [BRIA AI](https://bria.ai)

## Related Links

- [RMBG2Swift - Swift Package](https://github.com/VincentGourbin/RMBG2Swift)
- [Original RMBG-2.0 Model](https://huggingface.co/briaai/RMBG-2.0)
- [BiRefNet Paper](https://github.com/ZhengPeng7/BiRefNet)