WSIGridProcessor
histolytics.wsi.wsi_processor.WSIGridProcessor ¶
Source code in src/histolytics/wsi/wsi_processor.py
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 |
|
__init__ ¶
__init__(slide_reader: SlideReader, grid: GeoDataFrame, nuclei: GeoDataFrame, pipeline_func: Callable, tissue: GeoDataFrame = None, nuclei_classes: Dict[str, int] = None, tissue_classes: Dict[str, int] = None, batch_size: int = 8, num_workers: int = 8, pin_memory: bool = True, shuffle: bool = False, drop_last: bool = False)
Context manager for processing WSI grid cells.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slide_reader
|
SlideReader
|
SlideReader instance. |
required |
grid
|
GeoDataFrame
|
A grid GeoDataFrame containing rectangular grid cells. |
required |
nuclei
|
GeoDataFrame
|
A GeoDataFrame containing nuclei data. |
required |
tissue
|
GeoDataFrame
|
A GeoDataFrame containing tissue data. |
None
|
nuclei_classes
|
Dict[str, int]
|
A dictionary mapping nuclei class names to integers. |
None
|
tissue_classes
|
Dict[str, int]
|
A dictionary mapping tissue class names to integers. |
None
|
batch_size
|
int
|
The batch size for processing. |
8
|
num_workers
|
int
|
The number of worker processes. |
8
|
pin_memory
|
bool
|
Whether to pin memory for faster GPU transfer. |
True
|
shuffle
|
bool
|
Whether to shuffle the data. |
False
|
drop_last
|
bool
|
Whether to drop the last incomplete batch. |
False
|
Examples:
>>> from tqdm import tqdm
>>> from histolystics.wsi.wsi_processor import WSIGridProcessor
>>>
>>> # ... initialize reader, grid_gdf etc.
>>> crop_loader = WSIGridProcessor(
... slide_reader=reader, # SlideReader object
... grid=grid_gdf, # GeoDataFrame containing grid cells
... nuclei=nuc_gdf, # GeoDataFrame containing nuclei data
... nuclei_classes=nuclei_classes, # Mapping of nuclei class names to integers
... pipeline_func=partial(chromatin_feats, metrics=("chrom_area", "chrom_nuc_prop")),
... batch_size=8,
... num_workers=8,
... pin_memory=False,
... shuffle=False,
... drop_last=False,
... )
>>>
>>> crop_feats = []
>>> with crop_loader as loader:
>>> with tqdm(loader, unit="batch", total=len(loader)) as pbar:
>>> for batch_idx, batch in enumerate(pbar):
>>> crop_feats.append(batch)
Source code in src/histolytics/wsi/wsi_processor.py
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 |
|
__enter__ ¶
Enter the context manager and initialize the dataset and loader.
Source code in src/histolytics/wsi/wsi_processor.py
__exit__ ¶
Exit the context manager and clean up resources.
Source code in src/histolytics/wsi/wsi_processor.py
__iter__ ¶
Make the class iterable.
__next__ ¶
__len__ ¶
Get the total number of batches.
get_single_item ¶
Get a single item by index without batching.