F
File size: 10,973 Bytes
0814bfe
bbd3b86
 
 
 
 
 
 
 
 
 
0814bfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbd3b86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
---
license: unknown
tags:
- medical-imaging
- cystoscopy
- bladder-cancer
- cancer-detection
- histological-grade
pretty_name: Unified Cystoscopy Cancer Detection (Dataset F)
size_categories:
- 10K<n<100K
dataset_info:
  features:
  - name: image
    dtype: image
  - name: cancer_label
    dtype:
      class_label:
        names:
          '0': non_cancer
          '1': cancer
  - name: grade_label
    dtype:
      class_label:
        names:
          '0': low_grade
          '1': high_grade
          '2': not_applicable
  - name: subclass_label
    dtype:
      class_label:
        names:
          '0': malignant
          '1': non_malignant
          '2': normal
          '3': landmark
          '4': foreign_body
  - name: source_dataset
    dtype: string
  - name: original_filename
    dtype: string
  - name: patient_id
    dtype: int32
  - name: imaging_type
    dtype:
      class_label:
        names:
          '0': WLI
          '1': NBI
          '2': BLC
  - name: target3
    dtype:
      class_label:
        names:
          '0': malignant
          '1': non_malignant
          '2': non_roi
  - name: track_id
    dtype: string
  - name: cv_fold
    dtype: int64
  splits:
  - name: train
    num_bytes: 5493071831
    num_examples: 10067
  - name: validation
    num_bytes: 853196271
    num_examples: 2157
  - name: test
    num_bytes: 979011150
    num_examples: 2152
  download_size: 7325138684
  dataset_size: 7325279252
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
  - split: validation
    path: data/validation-*
  - split: test
    path: data/test-*
---

# Unified Cystoscopy Cancer Detection (Dataset F)

## Dataset Description

Dataset **F** is derived from [Dataset E](https://huggingface.co/datasets/milkyroad/E)
by removing every **PUNLMP** frame and re-deriving a patient-level
train / validation / test split from scratch. It is prepared for 3-class deep
learning (malignant vs non-malignant vs non-ROI) and keeps the same per-image
schema as Dataset E (`image`, `cancer_label`, `grade_label`, `subclass_label`,
`source_dataset`, `original_filename`, `patient_id`, `imaging_type`, `target3`,
`track_id`, `cv_fold`).

- **Total images**: 14,376  (E had 14,921; 545 PUNLMP frames removed)
- **Unique patients / cases**: 209  (E had 212; the 3 PUNLMP-only source-B patients 6, 8, 29 are dropped)
- **Modalities**: White-Light Imaging (WLI), Narrow-Band Imaging (NBI), Blue-Light Cystoscopy (BLC)
- **Splits**: train / validation / test (70 / 15 / 15), patient-level with **no leakage**
- **5-fold cross-validation** on the train pool (`cv_fold` 0-4; -1 for val/test)

### Relationship to Dataset E

| | Dataset E | Dataset F |
|---|---:|---:|
| Total images | 14,921 | 14,376 |
| Patients | 212 | 209 |
| non_malignant images | 900 | 355 |
| PUNLMP frames | 545 (source-B non_malignant) | 0 (excluded) |
| Split derivation | seed 16, 14 swaps | seed 17, 12 swaps (re-searched) |

## PUNLMP Exclusion

In Dataset E, **PUNLMP** (Papillary Urothelial Neoplasm of Low Malignant Potential)
is the `histological_type` of 12 source-B videos (`milkyroad/B`), and every
source-B `non_malignant` frame in E comes from those PUNLMP videos (E patients
6, 8, 29; tracks 028, 029, 032-037, 162-165). Therefore:

```
PUNLMP frames  ==  (source_dataset == 'B') AND (target3 == 'non_malignant')
```

Removing them drops the `non_malignant` class from 900 -> 355 images, all now
coming from sources C and D. Because this makes a good patient-level split much
harder, the split is **re-derived from scratch** (Dataset F does **not** inherit
Dataset E's split assignment).

## Source Datasets

| Code | Source | Type | Images in F | Patients in F |
|------|--------|------|------------:|---------------:|
| B | Cystoscopy video dataset (stride-8 frames) | Video frames | 4,555 | 27 |
| C | CystoDS | Still cystoscopy images | 8,067 | 160 |
| D | Kaggle cystoscopy frames | Still cystoscopy frames | 1,754 | 22 |

Source-B majority-class frames (malignant + non-ROI) in E are already capped at
**60 per (patient, track)**; Dataset F's split search used `cap=None`, i.e. it
keeps E's existing 60-cap and never adds frames. Source-B `non_malignant`
(PUNLMP) frames are excluded entirely, so all 4,555 source-B images in F are
`malignant` or `non_roi`.

### Patient ID normalization (unchanged from E)

| Source | Original ID field | Normalized range | Count |
|--------|-------------------|-----------------|------:|
| B | `patient_id` (0-29) | 1-30 | 27 (3 PUNLMP-only patients dropped) |
| C | `pid` | 31-190 | 160 |
| D | `case_id` (0-25) | 191-212 | 22 |

## Label Derivation

Identical to Dataset E. See E's dataset card for the full per-source mapping.
The derived 3-class task label is:

| subclass_label | target3 |
|----------------|---------|
| malignant (0) | malignant (0) |
| non_malignant (1) | non_malignant (1) |
| normal (2) | non_roi (2) |
| landmark (3) | non_roi (2) |
| foreign_body (4) | non_roi (2) |

## Train / Validation / Test Split

Patient-level stratified split using **StratifiedGroupKFold**
(`source x dominant-class` stratification) for test, then for train/val, followed
by greedy patient-swap refinement that minimises the maximum per-class
per-split fill-ratio deviation. Hard constraints: every split contains every
class and every source; a source-floor of 4 patients per source in val and test.

A grid search over `(seed, per-track cap, source_floor)` selected the
configuration with the lowest score
(`score = max_fill_dev + penalties`):

- **Split ratio**: 70 / 15 / 15 (train / val / test)
- **Best config**: `cap=None`, `source_floor=4`, `seed=17`
- **Swaps applied**: 12
- **Max fill-ratio deviation**: 0.0047
- **No patient appears in more than one split** (verified)

### Split sizes

| Split | Images | Patients |
|-------|-------:|---------:|
| train | 10,067 | 150 |
| validation | 2,157 | 31 |
| test | 2,152 | 28 |
| **Total** | **14,376** | **209** |

### Class distribution per split

| Class | Total | Train | Val | Test |
|-------|------:|------:|----:|-----:|
| malignant | 6,515 (45.3%) | 4,562 | 975 | 978 |
| non_malignant | 355 (2.5%) | 249 | 53 | 53 |
| non_roi | 7,506 (52.2%) | 5,256 | 1,129 | 1,121 |

### Fill ratios (count / target, ideal = 1.00)

| Class | Train | Val | Test |
|-------|------:|----:|-----:|
| malignant | 1.00 | 1.00 | 1.00 |
| non_malignant | 1.00 | 1.00 | 1.00 |
| non_roi | 1.00 | 1.00 | 1.00 |

### Source x split (patients)

| Source | Train | Val | Test |
|--------|------:|----:|-----:|
| B | 19 | 4 | 4 |
| C | 117 | 23 | 20 |
| D | 14 | 4 | 4 |

### Source x split (images)

| Source | Train | Val | Test |
|--------|------:|----:|-----:|
| B | 3,402 | 447 | 706 |
| C | 5,654 | 1,224 | 1,189 |
| D | 1,011 | 486 | 257 |

### Non-malignant patient coverage

| Split | Patients | Images |
|-------|---------:|-------:|
| train | 53 | 249 |
| validation | 12 | 53 |
| test | 12 | 53 |

All `non_malignant` images in F come from sources C and D (source-B
non_malignant / PUNLMP is excluded).

## 5-Fold Cross-Validation (train pool only)

StratifiedGroupKFold on the train split (per-image `target3` stratification,
patient-level grouping, no patient in multiple folds, `seed=15`, 5 folds).

| Fold | Patients | Images | Malignant | Non-mal | Non-ROI |
|-----:|---------:|-------:|----------:|--------:|--------:|
| 0 | 27 | 2,008 | 912 | 49 | 1,047 |
| 1 | 30 | 2,017 | 912 | 50 | 1,055 |
| 2 | 33 | 1,988 | 912 | 49 | 1,027 |
| 3 | 29 | 2,055 | 913 | 50 | 1,092 |
| 4 | 31 | 1,999 | 913 | 51 | 1,035 |

The `cv_fold` column is -1 for validation and test patients.

### Note on minority-class (non-malignant) fold balance

After PUNLMP exclusion the `non_malignant` class shrinks to 355 images and
remains heavily patient-concentrated: only 53 train patients carry
non_malignant frames and a few patients dominate the count. Because
cross-validation is patient-grouped (a patient never appears in more than one
fold), high-volume patients cannot be split across folds, so the per-fold
non-malignant count varies modestly (49-51) while the majority classes stay
near-perfectly balanced (malignant spread 912-913; non-ROI spread 1,027-1,092).
Practitioners should report per-fold non-malignant counts alongside metrics and
prefer the macro-averaged F1 across all five folds over any single fold's score
when estimating minority-class performance.

## Dataset Statistics

### By target3

| Malignant | Non-malignant | Non-ROI |
|----------:|--------------:|--------:|
| 6,515 | 355 | 7,506 |

### By subclass label

| Malignant | Non-malignant | Normal | Landmark | Foreign body |
|----------:|--------------:|-------:|---------:|-------------:|
| 6,515 | 355 | 7,044 | 211 | 251 |

### By cancer label

| Total | Cancer | Non-cancer |
|------:|-------:|-----------:|
| 14,376 | 6,514 | 7,862 |

### By grade label

| High-grade | Low-grade | Not applicable |
|-----------:|----------:|---------------:|
| 2,205 | 4,309 | 7,862 |

### By imaging modality

| WLI | NBI | BLC |
|----:|----:|----:|
| 13,605 | 321 | 450 |

### By source

| B | C | D |
|---:|---:|---:|
| 4,555 | 8,067 | 1,754 |

## Features Schema

| Column | Type | Description |
|--------|------|-------------|
| `image` | Image | Cystoscopy image (decoded as PIL Image on load) |
| `cancer_label` | ClassLabel | `non_cancer` (0) / `cancer` (1) |
| `grade_label` | ClassLabel | `low_grade` (0) / `high_grade` (1) / `not_applicable` (2) |
| `subclass_label` | ClassLabel | `malignant` (0) / `non_malignant` (1) / `normal` (2) / `landmark` (3) / `foreign_body` (4) |
| `source_dataset` | string | `B`, `C`, or `D` -- original source dataset |
| `original_filename` | string | Filename in the original source dataset |
| `patient_id` | int32 | Normalized sequential patient/case ID (1-212) |
| `imaging_type` | ClassLabel | `WLI` (0) / `NBI` (1) / `BLC` (2) |
| `target3` | ClassLabel | `malignant` (0) / `non_malignant` (1) / `non_roi` (2) -- 3-class task label |
| `track_id` | string | Source-B video track ID (e.g. `008`); `NA` for sources C and D |
| `cv_fold` | int64 | 5-fold CV assignment (0-4) for train patients; -1 for val/test |

## Loading

```python
from datasets import load_dataset

ds = load_dataset("milkyroad/F")
print(ds)
# DatasetDict({
#     train: 10,067 images
#     validation: 2,157 images
#     test: 2,152 images
# })

sample = ds["train"][0]
print(sample["target3"])  # 0 (malignant), 1 (non_malignant), or 2 (non_roi)
```

## Provenance

Built from `milkyroad/E` by:
1. Dropping all PUNLMP frames (`source_dataset == 'B'` and `target3 == 'non_malignant'`).
2. Grid-searching `(seed, cap, source_floor)` for the patient-level split that
   minimises the maximum per-class per-split fill-ratio deviation, with hard
   coverage constraints.
3. Attaching a 5-fold StratifiedGroupKFold CV assignment (`seed=15`) to the
   train pool.

Selected config: `cap=None`, `source_floor=4`, `seed=17`, 12 swaps,
max fill-ratio deviation 0.0047.