VincentGOURBIN commited on
Commit
d2f14a1
·
verified ·
1 Parent(s): dce0224

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ library_name: coreml
4
+ pipeline_tag: image-segmentation
5
+ tags:
6
+ - background-removal
7
+ - image-segmentation
8
+ - coreml
9
+ - apple-neural-engine
10
+ - birefnet
11
+ - rmbg
12
+ language:
13
+ - en
14
+ base_model: briaai/RMBG-2.0
15
+ ---
16
+
17
+ # RMBG-2 CoreML - Background Removal Model
18
+
19
+ 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).
20
+
21
+ ## Model Description
22
+
23
+ This is a native ML Program format CoreML model converted from RMBG-2.0 (BiRefNet architecture) for high-quality background removal on Apple devices.
24
+
25
+ ### Key Features
26
+
27
+ - **Native CoreML ML Program format** - Full ANE compatibility
28
+ - **No custom layers** - Uses only native CoreML operations
29
+ - **1024x1024 input resolution** - High-quality segmentation
30
+ - **Fast inference** - ~3 seconds on Apple Silicon with ANE
31
+
32
+ ## Usage
33
+
34
+ ### With RMBG2Swift Package
35
+
36
+ ```swift
37
+ import RMBG2Swift
38
+
39
+ // Simple one-liner
40
+ let rmbg = try await RMBG2()
41
+ let result = try await rmbg.removeBackground(from: image)
42
+
43
+ // Access the result
44
+ let outputImage = result.image // Image with transparent background
45
+ let mask = result.mask // Grayscale segmentation mask
46
+ ```
47
+
48
+ **Swift Package:** [github.com/VincentGourbin/RMBG2Swift](https://github.com/VincentGourbin/RMBG2Swift)
49
+
50
+ ### Manual Integration
51
+
52
+ ```swift
53
+ import CoreML
54
+
55
+ // Load the model
56
+ let config = MLModelConfiguration()
57
+ config.computeUnits = .all // Enable ANE
58
+
59
+ let model = try await MLModel.load(contentsOf: modelURL, configuration: config)
60
+
61
+ // Prepare input (1024x1024, NCHW format with ImageNet normalization)
62
+ let input = MLDictionaryFeatureProvider(dictionary: ["input": inputArray])
63
+
64
+ // Run inference
65
+ let output = try model.prediction(from: input)
66
+
67
+ // Get mask from output_3 (full resolution)
68
+ let mask = output.featureValue(for: "output_3")?.multiArrayValue
69
+ ```
70
+
71
+ ## Model Details
72
+
73
+ | Property | Value |
74
+ |----------|-------|
75
+ | Architecture | BiRefNet |
76
+ | Input Size | 1024 x 1024 |
77
+ | Input Format | RGB, NCHW [1, 3, 1024, 1024] |
78
+ | Normalization | ImageNet (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) |
79
+ | Output | 4 scales (output_0 to output_3), use output_3 for full resolution |
80
+ | Format | ML Program (.mlpackage) |
81
+ | Minimum OS | macOS 13+ / iOS 16+ |
82
+ | Compute Units | All (CPU, GPU, ANE) |
83
+
84
+ ## Performance
85
+
86
+ Tested on Apple Silicon:
87
+
88
+ | Device | Inference Time |
89
+ |--------|---------------|
90
+ | M1 Pro (ANE) | ~3s |
91
+ | M1 Pro (GPU) | ~5s |
92
+
93
+ ## Files
94
+
95
+ - `RMBG-2-native.mlpackage/` - CoreML ML Program model
96
+
97
+ ## License
98
+
99
+ **Creative Commons Attribution-NonCommercial 4.0 (CC BY-NC 4.0)**
100
+
101
+ - **Free for non-commercial use**: Research, personal projects, education
102
+ - **Commercial use requires a separate license** from BRIA AI
103
+
104
+ For commercial licensing, contact: [bria.ai/contact-us](https://bria.ai/contact-us)
105
+
106
+ ## Attribution
107
+
108
+ This CoreML conversion is based on the RMBG-2.0 model by BRIA AI:
109
+
110
+ - **Original Model**: [briaai/RMBG-2.0](https://huggingface.co/briaai/RMBG-2.0)
111
+ - **Architecture**: BiRefNet
112
+ - **Creator**: [BRIA AI](https://bria.ai)
113
+
114
+ ## Related Links
115
+
116
+ - [RMBG2Swift - Swift Package](https://github.com/VincentGourbin/RMBG2Swift)
117
+ - [Original RMBG-2.0 Model](https://huggingface.co/briaai/RMBG-2.0)
118
+ - [BiRefNet Paper](https://github.com/ZhengPeng7/BiRefNet)
RMBG-2-native.mlpackage/Data/com.apple.CoreML/model.mlmodel ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:81bb844737d0f29d4e8a07ea19d8867573904d522c94838dfb588fb2a44fa3a2
3
+ size 3188148
RMBG-2-native.mlpackage/Data/com.apple.CoreML/weights/weight.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2efd4c12d4a106d9e1b02703d7848cb1d6fd4c2ffb5cf2631065bf4e0271c823
3
+ size 480636448
RMBG-2-native.mlpackage/Manifest.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fileFormatVersion": "1.0.0",
3
+ "itemInfoEntries": {
4
+ "19571D65-9D4F-446B-8F53-D1804442FDF4": {
5
+ "author": "com.apple.CoreML",
6
+ "description": "CoreML Model Specification",
7
+ "name": "model.mlmodel",
8
+ "path": "com.apple.CoreML/model.mlmodel"
9
+ },
10
+ "BE5CBAF5-BDF3-4E72-A73C-2F4D5EBCE60F": {
11
+ "author": "com.apple.CoreML",
12
+ "description": "CoreML Model Weights",
13
+ "name": "weights",
14
+ "path": "com.apple.CoreML/weights"
15
+ }
16
+ },
17
+ "rootModelIdentifier": "19571D65-9D4F-446B-8F53-D1804442FDF4"
18
+ }
config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "RMBG-2-CoreML",
3
+ "architecture": "BiRefNet",
4
+ "input_size": 1024,
5
+ "input_format": "NCHW",
6
+ "input_channels": 3,
7
+ "normalization": {
8
+ "mean": [0.485, 0.456, 0.406],
9
+ "std": [0.229, 0.224, 0.225]
10
+ },
11
+ "outputs": ["output_0", "output_1", "output_2", "output_3"],
12
+ "primary_output": "output_3",
13
+ "format": "mlpackage",
14
+ "compute_units": "all",
15
+ "minimum_deployment_target": {
16
+ "macOS": "13.0",
17
+ "iOS": "16.0"
18
+ },
19
+ "original_model": "briaai/RMBG-2.0",
20
+ "license": "CC-BY-NC-4.0",
21
+ "version": "1.0.0"
22
+ }