AllanK24 commited on
Commit
9cab9e8
·
verified ·
1 Parent(s): 92ef414

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +186 -14
README.md CHANGED
@@ -1,4 +1,27 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  dataset_info:
3
  features:
4
  - name: image
@@ -9,23 +32,172 @@ dataset_info:
9
  dtype: string
10
  splits:
11
  - name: train
12
- num_bytes: 8973840321
13
  num_examples: 33118
14
  - name: validation
15
- num_bytes: 1205036342
16
  num_examples: 4138
17
  - name: test
18
- num_bytes: 1174346942
19
  num_examples: 4140
20
- download_size: 11730154334
21
- dataset_size: 11353223605
22
- configs:
23
- - config_name: default
24
- data_files:
25
- - split: train
26
- path: data/train-*
27
- - split: validation
28
- path: data/validation-*
29
- - split: test
30
- path: data/test-*
31
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ annotations_creators:
3
+ - expert-generated
4
+ language:
5
+ - en
6
+ license: apple-ascl
7
+ multilinguality: monolingual
8
+ pretty_name: Apple Dense Material Segmentation (DMS) – Stratified Split
9
+ size_categories:
10
+ - 10K<n<100K
11
+ source_datasets:
12
+ - extended|open-images-v7
13
+ tags:
14
+ - material-segmentation
15
+ - semantic-segmentation
16
+ - dense-prediction
17
+ - materials
18
+ - segformer
19
+ - mask2former
20
+ - stratified-split
21
+ task_categories:
22
+ - image-segmentation
23
+ task_ids:
24
+ - semantic-segmentation
25
  dataset_info:
26
  features:
27
  - name: image
 
32
  dtype: string
33
  splits:
34
  - name: train
 
35
  num_examples: 33118
36
  - name: validation
 
37
  num_examples: 4138
38
  - name: test
 
39
  num_examples: 4140
 
 
 
 
 
 
 
 
 
 
 
40
  ---
41
+
42
+ # Apple Dense Material Segmentation (DMS) – Stratified 80/10/10 Split
43
+
44
+ A **pixel-level material segmentation** dataset containing ~41K images with dense annotations across **57 material categories**. Originally released by Apple as part of the [Dense Material Segmentation (DMS)](https://machinelearning.apple.com/research/dense-material-segmentation) research project.
45
+
46
+ This version uses a **custom stratified 80/10/10 split** (vs Apple's original 54/23/23) to maximise training data while maintaining representative validation and test sets.
47
+
48
+ ## Why a Custom Split?
49
+
50
+ Apple's original split reserves nearly half the data for evaluation (23% val + 23% test). Our re-split allocates **80% to training** while using **stratified sampling** (based on the dominant material class per image) to keep val/test distributions aligned with the training set.
51
+
52
+ ### Split Quality Comparison
53
+
54
+ | Metric | Original (Apple) | Custom (Stratified) | Improvement |
55
+ |--------|------------------|---------------------|-------------|
56
+ | Train size | 22,492 (54%) | **33,118 (80%)** | +47% more training data |
57
+ | JSD train↔val | 0.0524 | **0.0158** | ✅ **70% lower divergence** |
58
+ | JSD train↔test | 0.0526 | **0.0163** | ✅ **69% lower divergence** |
59
+ | Classes in all splits | 53/57 | 53/57 | Equal coverage |
60
+
61
+ > **JSD** = Jensen-Shannon Divergence between pixel-level class distributions. Lower values mean the evaluation sets better represent the training distribution, leading to more reliable metrics.
62
+
63
+ ## Dataset Description
64
+
65
+ Each sample consists of:
66
+
67
+ | Field | Type | Description |
68
+ |-------|------|-------------|
69
+ | `image` | `PIL.Image` | RGB input image |
70
+ | `label` | `PIL.Image` | Single-channel segmentation mask (pixel values = class indices 0–56) |
71
+ | `image_id` | `string` | Unique image identifier |
72
+
73
+ ### Splits
74
+
75
+ | Split | Samples | Percentage |
76
+ |-------|---------|------------|
77
+ | Train | 33,118 | 80.0% |
78
+ | Validation | 4,138 | 10.0% |
79
+ | Test | 4,140 | 10.0% |
80
+ | **Total** | **41,396** | **100%** |
81
+
82
+ ### Material Classes (57)
83
+
84
+ <details>
85
+ <summary>Click to expand full class list</summary>
86
+
87
+ | ID | Material | ID | Material | ID | Material |
88
+ |----|----------|----|----------|----|----------|
89
+ | 0 | No label | 19 | Gemstone/quartz | 38 | Sky |
90
+ | 1 | Animal skin | 20 | Glass | 39 | Snow |
91
+ | 2 | Bone/teeth/horn | 21 | Hair | 40 | Soap |
92
+ | 3 | Brickwork | 22 | I cannot tell | 41 | Soil/mud |
93
+ | 4 | Cardboard | 23 | Ice | 42 | Sponge |
94
+ | 5 | Carpet/rug | 24 | Leather | 43 | Stone, natural |
95
+ | 6 | Ceiling tile | 25 | Liquid, non-water | 44 | Stone, polished |
96
+ | 7 | Ceramic | 26 | Metal | 45 | Styrofoam |
97
+ | 8 | Chalkboard/blackboard | 27 | Mirror | 46 | Tile |
98
+ | 9 | Clutter | 28 | Not on list | 47 | Wallpaper |
99
+ | 10 | Concrete | 29 | Paint/plaster/enamel | 48 | Water |
100
+ | 11 | Cork/corkboard | 30 | Paper | 49 | Wax |
101
+ | 12 | Engineered stone | 31 | Pearl | 50 | Whiteboard |
102
+ | 13 | Fabric/cloth | 32 | Photograph/painting | 51 | Wicker |
103
+ | 14 | Fiberglass wool | 33 | Plastic, clear | 52 | Wood |
104
+ | 15 | Fire | 34 | Plastic, non-clear | 53 | Wood, tree |
105
+ | 16 | Foliage | 35 | Rubber/latex | 54 | Bad polygon |
106
+ | 17 | Food | 36 | Sand | 55 | Multiple materials |
107
+ | 18 | Fur | 37 | Skin/lips | 56 | Asphalt |
108
+
109
+ </details>
110
+
111
+ ## Usage
112
+
113
+ ### Loading the Dataset
114
+
115
+ ```python
116
+ from datasets import load_dataset
117
+
118
+ dataset = load_dataset("AllanK24/apple-dms-materials-v2")
119
+
120
+ # Access splits
121
+ train_ds = dataset["train"] # 33,118 samples
122
+ val_ds = dataset["validation"] # 4,138 samples
123
+ test_ds = dataset["test"] # 4,140 samples
124
+
125
+ # View a sample
126
+ sample = train_ds[0]
127
+ sample["image"].show() # RGB image
128
+ sample["label"].show() # Segmentation mask
129
+ ```
130
+
131
+ ### Training with SegFormer / Mask2Former
132
+
133
+ ```python
134
+ from transformers import SegformerForSemanticSegmentation, SegformerImageProcessorFast
135
+ import json
136
+ from huggingface_hub import hf_hub_download
137
+
138
+ # Load class info
139
+ class_info_path = hf_hub_download(
140
+ repo_id="AllanK24/apple-dms-materials-v2",
141
+ filename="class_info.json",
142
+ repo_type="dataset",
143
+ )
144
+ with open(class_info_path) as f:
145
+ class_info = json.load(f)
146
+
147
+ id2label = {int(k): v for k, v in class_info["id2label"].items()}
148
+ label2id = class_info["label2id"]
149
+ num_labels = class_info["num_labels"]
150
+
151
+ # Initialize model
152
+ model = SegformerForSemanticSegmentation.from_pretrained(
153
+ "nvidia/segformer-b2-finetuned-ade-512-512",
154
+ num_labels=num_labels,
155
+ id2label=id2label,
156
+ label2id=label2id,
157
+ ignore_mismatched_sizes=True,
158
+ )
159
+
160
+ # Initialize processor
161
+ processor = SegformerImageProcessorFast.from_pretrained(
162
+ "nvidia/segformer-b2-finetuned-ade-512-512"
163
+ )
164
+
165
+ # Apply transforms
166
+ def transforms(batch):
167
+ images = [x.convert("RGB") for x in batch["image"]]
168
+ labels = [x for x in batch["label"]]
169
+ return processor(images=images, segmentation_maps=labels, return_tensors="pt")
170
+
171
+ train_ds.set_transform(transforms)
172
+ ```
173
+
174
+ ## Stratification Method
175
+
176
+ The split was created using a two-level stratified sampling approach:
177
+ 1. **Dominant class extraction** – For each image, the material class with the most pixels (excluding "No label") is identified.
178
+ 2. **First split** – Images are stratified into 80% train vs 20% eval using `StratifiedShuffleSplit`.
179
+ 3. **Second split** – The 20% eval pool is stratified 50/50 into validation and test.
180
+ 4. **Rare class handling** – Classes with <5 total images go directly to train; classes with <2 images in the eval pool are randomly assigned between val/test.
181
+
182
+ Seed: `42` (for reproducibility).
183
+
184
+ ## Source & Preparation
185
+
186
+ - **Original dataset**: [Apple DMS](https://github.com/apple/ml-dms-dataset) with images from [Open Images V7](https://storage.googleapis.com/openimages/web/index.html)
187
+ - **Original split** (v1): [AllanK24/apple-dms-materials](https://huggingface.co/datasets/AllanK24/apple-dms-materials)
188
+ - **Preparation pipeline**: Download → resize/align (`prepare_images.py`) → validate (`check_images.py`, 41,385/41,396 passed) → stratified re-split
189
+
190
+ ## Citation
191
+
192
+ ```bibtex
193
+ @article{upchurch2022dense,
194
+ title={Dense Material Segmentation with Context-Aware Network},
195
+ author={Upchurch, Paul and Niu, Ransen},
196
+ year={2022},
197
+ url={https://machinelearning.apple.com/research/dense-material-segmentation}
198
+ }
199
+ ```
200
+
201
+ ## License
202
+
203
+ Released under the [Apple Sample Code License (ASCL)](https://developer.apple.com/sample-code/license/apple-sample-code-license/). Source images are from Open Images V7 (primarily CC BY 2.0). See the [original repository](https://github.com/apple/ml-dms-dataset) for full licensing details.