-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fcmae' into normalization_roi
- Loading branch information
Showing
7 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from pathlib import Path | ||
|
||
from iohub.ngff import open_ome_zarr | ||
from lightning.pytorch import LightningDataModule | ||
from monai.transforms import Compose, MapTransform | ||
from torch.utils.data import DataLoader | ||
|
||
from viscy.data.hcs import ChannelMap, SlidingWindowDataset | ||
|
||
|
||
class CTMCv1DataModule(LightningDataModule): | ||
""" | ||
Autoregression data module for the CTMCv1 dataset. | ||
Training and validation datasets are stored in separate HCS OME-Zarr stores. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
train_data_path: str | Path, | ||
val_data_path: str | Path, | ||
train_transforms: list[MapTransform], | ||
val_transforms: list[MapTransform], | ||
batch_size: int = 16, | ||
num_workers: int = 8, | ||
channel_name: str = "DIC", | ||
) -> None: | ||
super().__init__() | ||
self.train_data_path = train_data_path | ||
self.val_data_path = val_data_path | ||
self.train_transforms = train_transforms | ||
self.val_transforms = val_transforms | ||
self.channel_map = ChannelMap(source=channel_name, target=channel_name) | ||
self.batch_size = batch_size | ||
self.num_workers = num_workers | ||
|
||
def setup(self, stage: str) -> None: | ||
if stage != "fit": | ||
raise NotImplementedError("Only fit stage is supported") | ||
self._setup_fit() | ||
|
||
def _setup_fit(self) -> None: | ||
train_plate = open_ome_zarr(self.train_data_path) | ||
val_plate = open_ome_zarr(self.val_data_path) | ||
train_positions = [p for _, p in train_plate.positions()] | ||
val_positions = [p for _, p in val_plate.positions()] | ||
self.train_dataset = SlidingWindowDataset( | ||
train_positions, | ||
channels=self.channel_map, | ||
z_window_size=1, | ||
transform=Compose(self.train_transform), | ||
) | ||
self.val_dataset = SlidingWindowDataset( | ||
val_positions, | ||
channels=self.channel_map, | ||
z_window_size=1, | ||
transform=Compose(self.val_transform), | ||
) | ||
|
||
def train_dataloader(self) -> DataLoader: | ||
return DataLoader( | ||
self.train_dataset, | ||
batch_size=self.batch_size, | ||
num_workers=self.num_workers, | ||
persistent_workers=bool(self.num_workers), | ||
shuffle=True, | ||
) | ||
|
||
def val_dataloader(self) -> DataLoader: | ||
return DataLoader( | ||
self.val_dataset, | ||
batch_size=self.batch_size, | ||
num_workers=self.num_workers, | ||
persistent_workers=bool(self.num_workers), | ||
shuffle=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters