File size: 3,776 Bytes
cc26392
e4b8150
 
f889757
e4b8150
f889757
 
 
 
e4b8150
 
f889757
cc26392
e4b8150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: cc-by-nc-4.0
task_categories:
  - image-segmentation
tags:
  - glass-surface-detection
  - segmentation
  - reflection
  - computer-vision
pretty_name: Glass Surface Detection (GSD)
size_categories:
  - 1K<n<10K
---

# Glass Surface Detection (GSD) Dataset

Dataset from the CVPR 2021 paper:

> **Rich Context Aggregation with Reflection Prior for Glass Surface Detection**  
> Jiaying Lin, Zebang He, Rynson W.H. Lau  
> *Proceedings of CVPR 2021*  
> Project page: https://jiaying.link/cvpr2021-gsd/

## Dataset Summary

GSD is a large-scale benchmark for glass surface detection in the wild. The dataset contains three splits:

- **train** — 2,710 images with full annotations (mask, reflection, edge). This is the split used to train GlassNet.
- **extra** — 579 additional images with mask and edge annotations but no reflections. Not used to train GlassNet.
- **test** — 813 images with mask annotations for evaluation.

## Dataset Structure

| Split | Images | Masks | Reflections | Edges |
|-------|-------:|------:|------------:|------:|
| train | 2,710  | 2,710 | 2,710       | 2,710 |
| extra |   579  |   579 | —           |   579 |
| test  |   813  |   813 | —           | —     |

### Fields

- **image_id** — original filename stem (e.g. `glass_0001`), unique within each split
- **image** — RGB photograph containing glass surfaces
- **mask** — binary segmentation mask (white = glass)
- **reflections** — RGB reflection image paired with the scene (train only; `None` otherwise)
- **edge** — edge annotation map (train and extra only; `None` for test)

## Usage

```python
from datasets import load_dataset

ds = load_dataset("garrying/GSD")
sample = ds["train"][0]
sample["image_id"]     # original filename stem, e.g. "glass_0001"
sample["image"]        # PIL Image
sample["mask"]         # PIL Image (binary mask)
sample["reflections"]  # PIL Image (None for extra/test)
sample["edge"]         # PIL Image (None for test)
```

## Converting Back to Raw Files

A helper script [`parquet_to_raw.py`](parquet_to_raw.py) is included in this repository to convert the dataset back to a folder of raw image files:

```bash
# download the script
huggingface-cli download garrying/GSD parquet_to_raw.py --repo-type dataset --local-dir .

# convert all splits to raw PNG files
python parquet_to_raw.py --repo garrying/GSD --out GSD
```

Output layout:
```
GSD/
  train/  image/  mask/  reflections/  edge/  metadata.jsonl
  extra/  image/  mask/  edge/          metadata.jsonl
  test/   image/  mask/  metadata.jsonl
```

## Pretrained Model

A pretrained **GlassNet** checkpoint (`GSD.pth`) is available in the companion model repository:

👉 [garrying/GSD-GlassNet](https://huggingface.co/garrying/GSD-GlassNet)

### Inference

```bash
# download the checkpoint
huggingface-cli download garrying/GSD-GlassNet GSD.pth --local-dir .

# run inference
python infer.py
```

## Model Architecture

**GlassNet** uses a ResNeXt-101 backbone with:

- **DenseContrastModule** — multi-scale dilated convolutions (rates 1/2/4/8) with pairwise feature subtraction to capture cross-context contrast
- **SELayer** — grouped squeeze-and-excitation for context-aware channel reweighting
- **RefNet** — a lightweight U-Net-style decoder that jointly predicts the binary glass mask and reconstructs the reflection image as auxiliary output
- **CRF post-processing** — dense CRF refinement of predicted masks at inference time

## Citation

```bibtex
@inproceedings{GSD:2021,
    title     = {Rich Context Aggregation with Reflection Prior for Glass Surface Detection},
    author    = {Lin, Jiaying and He, Zebang and Lau, Rynson W.H.},
    booktitle = {Proc. CVPR},
    year      = {2021}
}
```

## Contact

jiayinlin5-c@my.cityu.edu.hk