diff options
| author | Vineet Kumar <git@vineetk.net> | 2026-04-20 10:28:06 -0400 |
|---|---|---|
| committer | Vineet Kumar <git@vineetk.net> | 2026-04-20 10:28:06 -0400 |
| commit | 3d5c9e1658ea8c8b06d9acaeff847647b58fa63a (patch) | |
| tree | f51942ca20f82e1711fe3024482941c92616c4ea /dataset.py | |
| parent | 9dd8b3007e79f0634f868d405f5e7c48917305fd (diff) | |
increase resolution to 384px and soften oversampler weights
- Default img_size changed from 224 to 384 (already plumbed through
build_transforms/build_dataloaders, just needed passing from main.py)
- WeightedRandomSampler now uses sqrt(1/count) instead of 1/count to
reduce over-prediction of minority classes against visually similar
majority class (Healthy vs Mild NPDR)
- Default batch size reduced 64->32 to accommodate larger images
- 4-epoch warmup-only test: macro F1 0.45, weighted F1 0.74, kappa 0.62
already exceeding previous 22-epoch best on all metrics
Diffstat (limited to 'dataset.py')
| -rw-r--r-- | dataset.py | 6 |
1 files changed, 4 insertions, 2 deletions
| @@ -126,10 +126,12 @@ def build_dataloaders( | |||
| 126 | val_ds = DRDataset(val_paths, val_labels, transform=build_transforms(use_clahe, training=False, img_size=img_size)) | 126 | val_ds = DRDataset(val_paths, val_labels, transform=build_transforms(use_clahe, training=False, img_size=img_size)) |
| 127 | test_ds = DRDataset(test_paths, test_labels, transform=build_transforms(use_clahe, training=False, img_size=img_size)) | 127 | test_ds = DRDataset(test_paths, test_labels, transform=build_transforms(use_clahe, training=False, img_size=img_size)) |
| 128 | 128 | ||
| 129 | # Per-sample weights: inverse of class frequency so all classes are seen equally | 129 | # Per-sample weights: sqrt-inverse-frequency for moderate class balancing. |
| 130 | # Full inverse (1/count) causes over-prediction of minorities; sqrt gives a | ||
| 131 | # softer boost that retains enough majority-class signal. | ||
| 130 | labels_arr = np.array(train_labels) | 132 | labels_arr = np.array(train_labels) |
| 131 | class_counts = np.bincount(labels_arr, minlength=5) | 133 | class_counts = np.bincount(labels_arr, minlength=5) |
| 132 | class_sample_weights = 1.0 / class_counts.astype(float) | 134 | class_sample_weights = 1.0 / np.sqrt(class_counts.astype(float)) |
| 133 | sample_weights = class_sample_weights[labels_arr] | 135 | sample_weights = class_sample_weights[labels_arr] |
| 134 | sampler = WeightedRandomSampler( | 136 | sampler = WeightedRandomSampler( |
| 135 | weights=torch.from_numpy(sample_weights).float(), | 137 | weights=torch.from_numpy(sample_weights).float(), |
