Datasets:
Dataset Viewer
image
imagewidth (px) 720
720
| mask
imagewidth (px) 720
720
| case_id
stringclasses 10
values |
|---|---|---|
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
||
21405_176
|
||
21405_176
|
||
21405_176
|
||
21405_176
|
||
21405_176
|
||
21405_176
|
||
21405_176
|
||
21405_176
|
||
21405_178
|
||
21405_178
|
||
21405_178
|
||
21405_178
|
||
21405_178
|
||
21405_178
|
||
21405_178
|
||
21405_182
|
||
21405_182
|
||
21405_182
|
||
21405_182
|
||
21405_182
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_187
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_192
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_188
|
||
21405_156
|
||
21405_156
|
||
21405_156
|
End of preview. Expand
in Data Studio
PSU-MIPL AFB Bronchoscopy Dataset
Dataset Description
The PSU-MIPL AFB (Autofluorescence Bronchoscopy) dataset contains bronchoscopy images for lesion segmentation tasks. The dataset includes both lesion frames (with pathological tissue) and normal frames (healthy tissue).
- Task: Binary segmentation (lesion vs. background)
- Modality: Autofluorescence bronchoscopy
- Format: JPG images with corresponding binary masks
- Total samples: 685 images (208 lesion, 477 normal)
Dataset Structure
psu-mipl-afb/
βββ train_lesion/
β βββ images/ # 97 lesion images
β βββ masks/ # 97 corresponding masks
βββ train_normal/
β βββ images/ # 223 normal images
β βββ masks/ # 223 empty masks (background only)
βββ validation_lesion/
β βββ images/ # 58 lesion images
β βββ masks/ # 58 corresponding masks
βββ validation_normal/
β βββ images/ # 139 normal images
β βββ masks/ # 139 empty masks
βββ test_lesion/
β βββ images/ # 53 lesion images
β βββ masks/ # 53 corresponding masks
βββ test_normal/
βββ images/ # 115 normal images
βββ masks/ # 115 empty masks
Data Splits
| Split | Lesion | Normal | Total |
|---|---|---|---|
| Train | 97 | 223 | 320 |
| Validation | 58 | 139 | 197 |
| Test | 53 | 115 | 168 |
| Total | 208 | 477 | 685 |
Usage
Quick Start
from huggingface_hub import snapshot_download
from pathlib import Path
from PIL import Image
# Download dataset
dataset_path = snapshot_download(
repo_id="Angelou0516/psu-mipl-afb",
repo_type="dataset"
)
# Load a sample
img_path = Path(dataset_path) / "train_lesion" / "images" / "21405_156_21405_156_1780.jpg"
mask_path = Path(dataset_path) / "train_lesion" / "masks" / "21405_156_21405_156_1780.jpg"
image = Image.open(img_path).convert('RGB')
mask = Image.open(mask_path).convert('L')
Loading Lesion Samples Only
For SAM/SAM2 evaluation or tasks requiring non-empty masks:
from pathlib import Path
from PIL import Image
from huggingface_hub import snapshot_download
# Download dataset
dataset_path = Path(snapshot_download(
repo_id="Angelou0516/psu-mipl-afb",
repo_type="dataset"
))
# Load lesion samples from test split
split = "test"
images_dir = dataset_path / f"{split}_lesion" / "images"
masks_dir = dataset_path / f"{split}_lesion" / "masks"
samples = []
for img_path in sorted(images_dir.glob("*.jpg")):
mask_path = masks_dir / img_path.name
if mask_path.exists():
samples.append({
'image': Image.open(img_path).convert('RGB'),
'mask': Image.open(mask_path).convert('L'),
'filename': img_path.name
})
print(f"Loaded {len(samples)} lesion samples") # 53 samples
PyTorch Dataset Class
import torch
from torch.utils.data import Dataset, DataLoader
from pathlib import Path
from PIL import Image
from huggingface_hub import snapshot_download
class AFBDataset(Dataset):
def __init__(self, split='train', category=None, transform=None):
# Download dataset
dataset_path = Path(snapshot_download(
repo_id="Angelou0516/psu-mipl-afb",
repo_type="dataset"
))
self.transform = transform
self.samples = []
# Determine which categories to load
categories = [category] if category else ['lesion', 'normal']
for cat in categories:
images_dir = dataset_path / f"{split}_{cat}" / "images"
masks_dir = dataset_path / f"{split}_{cat}" / "masks"
for img_path in sorted(images_dir.glob("*.jpg")):
mask_path = masks_dir / img_path.name
if mask_path.exists():
self.samples.append({
'image_path': img_path,
'mask_path': mask_path,
'category': cat
})
def __len__(self):
return len(self.samples)
def __getitem__(self, idx):
sample = self.samples[idx]
image = Image.open(sample['image_path']).convert('RGB')
mask = Image.open(sample['mask_path']).convert('L')
if self.transform:
image = self.transform(image)
mask = self.transform(mask)
return {
'image': image,
'mask': mask,
'category': sample['category']
}
# Example usage
dataset = AFBDataset(split='train', category='lesion')
dataloader = DataLoader(dataset, batch_size=4, shuffle=True)
Balanced Sampling (Equal Lesion/Normal per Batch)
import numpy as np
from torch.utils.data import Sampler
class BalancedSampler(Sampler):
def __init__(self, dataset, batch_size=8, shuffle=True, seed=42):
if batch_size % 2 != 0:
raise ValueError("batch_size must be even")
self.batch_size = batch_size
self.samples_per_category = batch_size // 2
self.shuffle = shuffle
self.seed = seed
# Get indices for each category
self.lesion_indices = [
i for i, s in enumerate(dataset.samples)
if s['category'] == 'lesion'
]
self.normal_indices = [
i for i, s in enumerate(dataset.samples)
if s['category'] == 'normal'
]
self.num_batches = min(
len(self.lesion_indices) // self.samples_per_category,
len(self.normal_indices) // self.samples_per_category
)
def __iter__(self):
rng = np.random.RandomState(self.seed)
if self.shuffle:
lesion_shuffled = rng.permutation(self.lesion_indices).tolist()
normal_shuffled = rng.permutation(self.normal_indices).tolist()
else:
lesion_shuffled = self.lesion_indices.copy()
normal_shuffled = self.normal_indices.copy()
batch_indices = []
for i in range(self.num_batches):
lesion_batch = lesion_shuffled[
i * self.samples_per_category:(i + 1) * self.samples_per_category
]
normal_batch = normal_shuffled[
i * self.samples_per_category:(i + 1) * self.samples_per_category
]
batch = lesion_batch + normal_batch
if self.shuffle:
rng.shuffle(batch)
batch_indices.extend(batch)
return iter(batch_indices)
def __len__(self):
return self.num_batches * self.batch_size
# Example usage
dataset = AFBDataset(split='train', category=None) # Load both
sampler = BalancedSampler(dataset, batch_size=8, shuffle=True)
dataloader = DataLoader(dataset, batch_size=8, sampler=sampler)
for batch in dataloader:
# Each batch has 4 lesion + 4 normal samples
images = batch['image']
masks = batch['mask']
categories = batch['category']
Important Notes
Lesion vs Normal Frames
- Lesion frames (208 total): Contain pathological tissue with segmentation masks
- Normal frames (477 total): Contain healthy tissue with empty masks (background only)
Recommended Usage
For SAM/SAM2 Evaluation:
- Use only lesion samples (
category='lesion') - Normal frames have empty masks and will cause errors with prompt-based models
For Training:
- Use both lesion and normal samples (
category=None) - Use balanced sampling to ensure equal representation
- Helps models distinguish between healthy and pathological tissue
Citation
If you use this dataset, please cite:
@article{chang2024esfpnet,
title={ESFPNet: Efficient Stage-Wise Feature Pyramid on Mix Transformer for Deep Learning-Based Cancer Analysis in Endoscopic Video},
author={Chang, Qi and Ahmad, Danish and Toth, Jennifer and Bascom, Rebecca and Higgins, William E},
journal={Journal of Imaging},
volume={10},
number={8},
pages={191},
year={2024},
publisher={MDPI}
}
License
CC-BY-4.0
Links
- Paper: ESFPNet on MDPI
- Institution: Penn State University, MIPL Lab
- Downloads last month
- 17