bbbc-datasets 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bbbc_datasets-0.1.0/LICENSE +21 -0
- bbbc_datasets-0.1.0/MANIFEST.in +3 -0
- bbbc_datasets-0.1.0/PKG-INFO +175 -0
- bbbc_datasets-0.1.0/README.md +145 -0
- bbbc_datasets-0.1.0/assets/header.webp +0 -0
- bbbc_datasets-0.1.0/bbbc_datasets/__init__.py +0 -0
- bbbc_datasets-0.1.0/bbbc_datasets/config.py +15 -0
- bbbc_datasets-0.1.0/bbbc_datasets/dataset_manager.py +123 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/__init__.py +0 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/base_dataset.py +230 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc003.py +40 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc004.py +60 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc005.py +40 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc006.py +54 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc008.py +35 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc010.py +39 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc024.py +70 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc027.py +64 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc028.py +34 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc029.py +35 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc032.py +44 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc033.py +36 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc034.py +52 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc035.py +42 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc038.py +88 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc039.py +41 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc046.py +100 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/bbbc050.py +47 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/cellpose.py +22 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/evican.py +0 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/isbi15.py +0 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/livecell.py +25 -0
- bbbc_datasets-0.1.0/bbbc_datasets/datasets/sartorius.py +23 -0
- bbbc_datasets-0.1.0/bbbc_datasets/utils/__init__.py +0 -0
- bbbc_datasets-0.1.0/bbbc_datasets/utils/downloader.py +33 -0
- bbbc_datasets-0.1.0/bbbc_datasets/utils/file_handler.py +0 -0
- bbbc_datasets-0.1.0/bbbc_datasets/utils/file_io.py +33 -0
- bbbc_datasets-0.1.0/bbbc_datasets.egg-info/PKG-INFO +175 -0
- bbbc_datasets-0.1.0/bbbc_datasets.egg-info/SOURCES.txt +47 -0
- bbbc_datasets-0.1.0/bbbc_datasets.egg-info/dependency_links.txt +1 -0
- bbbc_datasets-0.1.0/bbbc_datasets.egg-info/requires.txt +7 -0
- bbbc_datasets-0.1.0/bbbc_datasets.egg-info/top_level.txt +2 -0
- bbbc_datasets-0.1.0/pyproject.toml +3 -0
- bbbc_datasets-0.1.0/requirements.txt +10 -0
- bbbc_datasets-0.1.0/setup.cfg +4 -0
- bbbc_datasets-0.1.0/setup.py +28 -0
- bbbc_datasets-0.1.0/tests/__init__.py +40 -0
- bbbc_datasets-0.1.0/tests/test_dataset_loading.py +43 -0
- bbbc_datasets-0.1.0/tests/test_download.py +38 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mario Koddenbrock
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: bbbc_datasets
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: PyTorch-compatible dataset manager for BBBC datasets
|
|
5
|
+
Home-page: https://github.com/mario-koddenbrock/bbbc_datasets
|
|
6
|
+
Author: Mario Koddenbrock
|
|
7
|
+
Author-email: koddenbrock@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: torch
|
|
15
|
+
Requires-Dist: torchvision
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: tifffile
|
|
18
|
+
Requires-Dist: opencv-python
|
|
19
|
+
Requires-Dist: requests
|
|
20
|
+
Requires-Dist: matplotlib
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: description-content-type
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: requires-dist
|
|
28
|
+
Dynamic: requires-python
|
|
29
|
+
Dynamic: summary
|
|
30
|
+
|
|
31
|
+
# BBBC Datasets - PyTorch Dataset Manager
|
|
32
|
+
|
|
33
|
+
<img src="assets/header.webp" alt="Reposetory Header Image" width="400" height="200">
|
|
34
|
+
|
|
35
|
+
## 📌 Overview
|
|
36
|
+
|
|
37
|
+
This package provides a **PyTorch-compatible dataset manager** for
|
|
38
|
+
[Broad Bioimage Benchmark Collection (BBBC) datasets](https://bbbc.broadinstitute.org/image_sets).
|
|
39
|
+
|
|
40
|
+
It allows users to:
|
|
41
|
+
|
|
42
|
+
- **Download and manage BBBC datasets automatically**
|
|
43
|
+
- **Load datasets as PyTorch `Dataset` objects**
|
|
44
|
+
- **Handle 2D & 3D images properly**
|
|
45
|
+
- **Support image augmentations via `torchvision.transforms`** (#TODO)
|
|
46
|
+
|
|
47
|
+
## 🚀 Installation
|
|
48
|
+
|
|
49
|
+
### **Clone the Repository**
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/mario-koddenbrock/bbbc_datasets.git
|
|
53
|
+
cd bbbc_datasets
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### **Install Dependencies**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install -r requirements.txt
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Dependencies:
|
|
63
|
+
|
|
64
|
+
- `torch`, `torchvision` (Deep Learning Framework)
|
|
65
|
+
- `numpy`, `tifffile`, `opencv-python` (Image Handling)
|
|
66
|
+
- `requests`, `matplotlib` (Downloading & Visualization)
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 📂 Available Datasets
|
|
71
|
+
|
|
72
|
+
You can list all available datasets without downloading them:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
python examples/load_dataset.py
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Output:**
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
📂 Available BBBC Datasets:
|
|
82
|
+
- BBBC003: DIC microscopy images of mouse embryos for segmentation analysis.
|
|
83
|
+
- BBBC004: Synthetic fluorescence microscopy images of nuclei with varying clustering probabilities.
|
|
84
|
+
- BBBC005: Simulated fluorescence microscopy images with varying focus blur.
|
|
85
|
+
- BBBC006: Z-stack fluorescence microscopy images of human U2OS cells.
|
|
86
|
+
- BBBC008: Dataset: Fluorescence microscopy images of human HT29 colon cancer cells.
|
|
87
|
+
- BBBC010: Live/dead assay of C. elegans exposed to pathogens.
|
|
88
|
+
- BBBC024: 3D Synthetic HL60 Cell Line Images with Varying Clustering Probability and SNR.
|
|
89
|
+
- BBBC027: 3D Synthetic Colon Tissue Images with Varying SNR.
|
|
90
|
+
- BBBC028: Polymerized Structures in Differential Interference Contrast (DIC) Microscopy.
|
|
91
|
+
- BBBC029: Synthetic Differential Interference Contrast (DIC) Images.
|
|
92
|
+
- BBBC032: 3D Mouse Embryo Blastocyst Cells.
|
|
93
|
+
- BBBC033: 3D Mouse Trophoblast Stem Cells.
|
|
94
|
+
- BBBC034: 3D Induced Pluripotent Human Stem Cells (hiPSC).
|
|
95
|
+
- BBBC035: Simulated HL60 Cells from the Cell Tracking Challenge.
|
|
96
|
+
- BBBC038: Kaggle 2018 Data Science Bowl - Nuclei Segmentation.
|
|
97
|
+
- BBBC039: Nuclei of U2OS Cells in a Chemical Screen.
|
|
98
|
+
- BBBC046: FiloData3D - Synthetic 3D Time-Lapse Imaging of A549 Cells with Filopodia.
|
|
99
|
+
- BBBC050: Nuclei of Mouse Embryonic Cells.
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 🎨 Visualizing Dataset Samples
|
|
105
|
+
|
|
106
|
+
### **Display First Image from Each Dataset**
|
|
107
|
+
|
|
108
|
+
##### Requires downloading datasets first!
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
python examples/load_dataset.py
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 📥 Download and Load a Dataset
|
|
117
|
+
|
|
118
|
+
### **Load a Dataset as a PyTorch Dataset**
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from bbbc_datasets.datasets.bbbc004 import BBBC004
|
|
122
|
+
from torch.utils.data import DataLoader
|
|
123
|
+
|
|
124
|
+
# Load BBBC004 dataset
|
|
125
|
+
dataset = BBBC004()
|
|
126
|
+
|
|
127
|
+
# Create a DataLoader
|
|
128
|
+
dataloader = DataLoader(dataset, batch_size=4, shuffle=True)
|
|
129
|
+
|
|
130
|
+
# Iterate through data
|
|
131
|
+
for images, labels in dataloader:
|
|
132
|
+
print(f"Batch shape: {images.shape}, Labels: {labels.shape if labels is not None else 'None'}")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 🛠 Running Tests
|
|
138
|
+
|
|
139
|
+
### **Validate Dataset URLs**
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
python -m unittest tests/test_dataset_urls.py
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- **Checks if all dataset URLs are reachable** 🌍
|
|
146
|
+
|
|
147
|
+
### **Verify Dataset Loading**
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
python -m unittest tests/test_dataset_loading.py
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
- **Ensures datasets can be loaded and accessed correctly** 🛠
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 📝 Up-next
|
|
158
|
+
|
|
159
|
+
- **Thinking of what is up next**
|
|
160
|
+
- **Maybe integrating other datasets as cellpose, livecell, etc.**
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## 🙌 Contributing
|
|
165
|
+
|
|
166
|
+
Contributions are welcome! If you find issues or want to add new features, feel free to:
|
|
167
|
+
|
|
168
|
+
- **Submit a Pull Request**
|
|
169
|
+
- **Report Issues** in the GitHub Issues section
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## 📜 License
|
|
174
|
+
|
|
175
|
+
This project is licensed under the **MIT License**.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# BBBC Datasets - PyTorch Dataset Manager
|
|
2
|
+
|
|
3
|
+
<img src="assets/header.webp" alt="Reposetory Header Image" width="400" height="200">
|
|
4
|
+
|
|
5
|
+
## 📌 Overview
|
|
6
|
+
|
|
7
|
+
This package provides a **PyTorch-compatible dataset manager** for
|
|
8
|
+
[Broad Bioimage Benchmark Collection (BBBC) datasets](https://bbbc.broadinstitute.org/image_sets).
|
|
9
|
+
|
|
10
|
+
It allows users to:
|
|
11
|
+
|
|
12
|
+
- **Download and manage BBBC datasets automatically**
|
|
13
|
+
- **Load datasets as PyTorch `Dataset` objects**
|
|
14
|
+
- **Handle 2D & 3D images properly**
|
|
15
|
+
- **Support image augmentations via `torchvision.transforms`** (#TODO)
|
|
16
|
+
|
|
17
|
+
## 🚀 Installation
|
|
18
|
+
|
|
19
|
+
### **Clone the Repository**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
git clone https://github.com/mario-koddenbrock/bbbc_datasets.git
|
|
23
|
+
cd bbbc_datasets
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### **Install Dependencies**
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install -r requirements.txt
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Dependencies:
|
|
33
|
+
|
|
34
|
+
- `torch`, `torchvision` (Deep Learning Framework)
|
|
35
|
+
- `numpy`, `tifffile`, `opencv-python` (Image Handling)
|
|
36
|
+
- `requests`, `matplotlib` (Downloading & Visualization)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 📂 Available Datasets
|
|
41
|
+
|
|
42
|
+
You can list all available datasets without downloading them:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python examples/load_dataset.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Output:**
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
📂 Available BBBC Datasets:
|
|
52
|
+
- BBBC003: DIC microscopy images of mouse embryos for segmentation analysis.
|
|
53
|
+
- BBBC004: Synthetic fluorescence microscopy images of nuclei with varying clustering probabilities.
|
|
54
|
+
- BBBC005: Simulated fluorescence microscopy images with varying focus blur.
|
|
55
|
+
- BBBC006: Z-stack fluorescence microscopy images of human U2OS cells.
|
|
56
|
+
- BBBC008: Dataset: Fluorescence microscopy images of human HT29 colon cancer cells.
|
|
57
|
+
- BBBC010: Live/dead assay of C. elegans exposed to pathogens.
|
|
58
|
+
- BBBC024: 3D Synthetic HL60 Cell Line Images with Varying Clustering Probability and SNR.
|
|
59
|
+
- BBBC027: 3D Synthetic Colon Tissue Images with Varying SNR.
|
|
60
|
+
- BBBC028: Polymerized Structures in Differential Interference Contrast (DIC) Microscopy.
|
|
61
|
+
- BBBC029: Synthetic Differential Interference Contrast (DIC) Images.
|
|
62
|
+
- BBBC032: 3D Mouse Embryo Blastocyst Cells.
|
|
63
|
+
- BBBC033: 3D Mouse Trophoblast Stem Cells.
|
|
64
|
+
- BBBC034: 3D Induced Pluripotent Human Stem Cells (hiPSC).
|
|
65
|
+
- BBBC035: Simulated HL60 Cells from the Cell Tracking Challenge.
|
|
66
|
+
- BBBC038: Kaggle 2018 Data Science Bowl - Nuclei Segmentation.
|
|
67
|
+
- BBBC039: Nuclei of U2OS Cells in a Chemical Screen.
|
|
68
|
+
- BBBC046: FiloData3D - Synthetic 3D Time-Lapse Imaging of A549 Cells with Filopodia.
|
|
69
|
+
- BBBC050: Nuclei of Mouse Embryonic Cells.
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 🎨 Visualizing Dataset Samples
|
|
75
|
+
|
|
76
|
+
### **Display First Image from Each Dataset**
|
|
77
|
+
|
|
78
|
+
##### Requires downloading datasets first!
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python examples/load_dataset.py
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 📥 Download and Load a Dataset
|
|
87
|
+
|
|
88
|
+
### **Load a Dataset as a PyTorch Dataset**
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from bbbc_datasets.datasets.bbbc004 import BBBC004
|
|
92
|
+
from torch.utils.data import DataLoader
|
|
93
|
+
|
|
94
|
+
# Load BBBC004 dataset
|
|
95
|
+
dataset = BBBC004()
|
|
96
|
+
|
|
97
|
+
# Create a DataLoader
|
|
98
|
+
dataloader = DataLoader(dataset, batch_size=4, shuffle=True)
|
|
99
|
+
|
|
100
|
+
# Iterate through data
|
|
101
|
+
for images, labels in dataloader:
|
|
102
|
+
print(f"Batch shape: {images.shape}, Labels: {labels.shape if labels is not None else 'None'}")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 🛠 Running Tests
|
|
108
|
+
|
|
109
|
+
### **Validate Dataset URLs**
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python -m unittest tests/test_dataset_urls.py
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- **Checks if all dataset URLs are reachable** 🌍
|
|
116
|
+
|
|
117
|
+
### **Verify Dataset Loading**
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
python -m unittest tests/test_dataset_loading.py
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- **Ensures datasets can be loaded and accessed correctly** 🛠
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 📝 Up-next
|
|
128
|
+
|
|
129
|
+
- **Thinking of what is up next**
|
|
130
|
+
- **Maybe integrating other datasets as cellpose, livecell, etc.**
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🙌 Contributing
|
|
135
|
+
|
|
136
|
+
Contributions are welcome! If you find issues or want to add new features, feel free to:
|
|
137
|
+
|
|
138
|
+
- **Submit a Pull Request**
|
|
139
|
+
- **Report Issues** in the GitHub Issues section
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 📜 License
|
|
144
|
+
|
|
145
|
+
This project is licensed under the **MIT License**.
|
|
Binary file
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
BBBC_DATASETS = {
|
|
2
|
+
"BBBC001": {
|
|
3
|
+
"image_paths": [
|
|
4
|
+
"https://bbbc.broadinstitute.org/BBBC001/images_1",
|
|
5
|
+
"https://bbbc.broadinstitute.org/BBBC001/images_2",
|
|
6
|
+
],
|
|
7
|
+
"label_path": "https://bbbc.broadinstitute.org/BBBC001/masks",
|
|
8
|
+
"local_path": "data/BBBC001",
|
|
9
|
+
},
|
|
10
|
+
"BBBC002": {
|
|
11
|
+
"image_paths": ["https://bbbc.broadinstitute.org/BBBC002/images"],
|
|
12
|
+
"label_path": None, # No segmentation ground truth
|
|
13
|
+
"local_path": "data/BBBC002",
|
|
14
|
+
},
|
|
15
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import numpy as np
|
|
3
|
+
import tifffile as tiff
|
|
4
|
+
import torch
|
|
5
|
+
from torch.utils.data import Dataset
|
|
6
|
+
|
|
7
|
+
from tests import DATASETS # Import shared dataset list
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BBBCDataset(Dataset):
|
|
11
|
+
"""
|
|
12
|
+
PyTorch-compatible dataset for loading BBBC datasets with full 3D support.
|
|
13
|
+
|
|
14
|
+
- Supports both 2D and 3D images.
|
|
15
|
+
- Optionally applies transformations (PyTorch `torchvision.transforms`).
|
|
16
|
+
- Returns (image, label) pairs where available.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
dataset_cls: The BBBC dataset class to load.
|
|
20
|
+
transform (callable, optional): Optional transform to apply to images.
|
|
21
|
+
target_transform (callable, optional): Optional transform for labels.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, dataset_cls, transform=None, target_transform=None):
|
|
25
|
+
self.dataset = dataset_cls()
|
|
26
|
+
self.image_paths = self.dataset.get_image_paths()
|
|
27
|
+
self.label_path = self.dataset.get_label_paths()
|
|
28
|
+
|
|
29
|
+
if not self.image_paths:
|
|
30
|
+
raise RuntimeError(f"No images found in {dataset_cls.__name__}")
|
|
31
|
+
|
|
32
|
+
self.transform = transform
|
|
33
|
+
self.target_transform = target_transform
|
|
34
|
+
|
|
35
|
+
def __len__(self):
|
|
36
|
+
return len(self.image_paths)
|
|
37
|
+
|
|
38
|
+
def __getitem__(self, idx):
|
|
39
|
+
image_path = self.image_paths[idx]
|
|
40
|
+
image = self.load_image(image_path)
|
|
41
|
+
|
|
42
|
+
label = None
|
|
43
|
+
if self.label_path:
|
|
44
|
+
label = self.load_image(self.label_path)
|
|
45
|
+
|
|
46
|
+
# Apply transforms if provided
|
|
47
|
+
if self.transform:
|
|
48
|
+
image = self.transform(image)
|
|
49
|
+
if self.target_transform and label is not None:
|
|
50
|
+
label = self.target_transform(label)
|
|
51
|
+
|
|
52
|
+
return image, label
|
|
53
|
+
|
|
54
|
+
def load_image(self, image_path):
|
|
55
|
+
"""
|
|
56
|
+
Loads an image (2D or full 3D) and converts it to a PyTorch tensor.
|
|
57
|
+
"""
|
|
58
|
+
if image_path.endswith((".tif", ".tiff")):
|
|
59
|
+
img = tiff.imread(image_path) # Load 3D TIFF or 2D image
|
|
60
|
+
else:
|
|
61
|
+
img = cv2.imread(image_path, cv2.IMREAD_UNCHANGED) # Load 2D image
|
|
62
|
+
|
|
63
|
+
if img is None:
|
|
64
|
+
raise ValueError(f"Error: Could not read image {image_path}")
|
|
65
|
+
|
|
66
|
+
# Normalize grayscale images
|
|
67
|
+
img = (img - np.min(img)) / (np.max(img) - np.min(img) + 1e-8)
|
|
68
|
+
|
|
69
|
+
# Convert to tensor
|
|
70
|
+
if len(img.shape) == 2: # 2D grayscale image
|
|
71
|
+
img = torch.tensor(img, dtype=torch.float32).unsqueeze(0) # (C, H, W)
|
|
72
|
+
elif len(img.shape) == 3: # 3D volume (Z, H, W)
|
|
73
|
+
img = torch.tensor(img, dtype=torch.float32).unsqueeze(0) # (C, Z, H, W)
|
|
74
|
+
|
|
75
|
+
return img
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class DatasetManager:
|
|
79
|
+
"""
|
|
80
|
+
Manages all BBBC datasets and provides utilities.
|
|
81
|
+
|
|
82
|
+
- Lists available datasets.
|
|
83
|
+
- Loads datasets dynamically as PyTorch Datasets.
|
|
84
|
+
- Displays dataset information.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
@staticmethod
|
|
88
|
+
def list_datasets():
|
|
89
|
+
"""Prints a summary of available BBBC datasets."""
|
|
90
|
+
print("\n📂 Available BBBC Datasets:")
|
|
91
|
+
for dataset_cls in DATASETS:
|
|
92
|
+
dataset = dataset_cls()
|
|
93
|
+
print(f"- {dataset_cls.__name__}: {dataset.dataset_name}")
|
|
94
|
+
|
|
95
|
+
@staticmethod
|
|
96
|
+
def get_dataset(name, transform=None, target_transform=None):
|
|
97
|
+
"""
|
|
98
|
+
Loads a dataset by name.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
name (str): The dataset class name (e.g., "BBBC003").
|
|
102
|
+
transform: Optional image transformations.
|
|
103
|
+
target_transform: Optional label transformations.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
BBBCDataset instance.
|
|
107
|
+
"""
|
|
108
|
+
for dataset_cls in DATASETS:
|
|
109
|
+
if dataset_cls.__name__ == name:
|
|
110
|
+
return BBBCDataset(dataset_cls, transform, target_transform)
|
|
111
|
+
|
|
112
|
+
raise ValueError(
|
|
113
|
+
f"Dataset {name} not found. Use DatasetManager.list_datasets() to see available datasets."
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
# Example Usage
|
|
119
|
+
DatasetManager.list_datasets()
|
|
120
|
+
|
|
121
|
+
# Load a dataset
|
|
122
|
+
dataset = DatasetManager.get_dataset("BBBC003")
|
|
123
|
+
print(f"\nLoaded {len(dataset)} samples from BBBC003")
|
|
File without changes
|