Skip to content
Snippets Groups Projects
Commit dd4dd5d1 authored by Daniel CARRON's avatar Daniel CARRON :b: Committed by André Anjos
Browse files

Moved nih_cxr14_re configs to data

parent c569f55b
No related branches found
No related tags found
1 merge request!6Making use of LightningDataModule and simplification of data loading
......@@ -471,10 +471,10 @@ mc_ch_in_pc_rgb = "ptbench.data.mc_ch_in_pc.rgb"
# (with radiological signs)
mc_ch_in_pc_rs = "ptbench.configs.datasets.mc_ch_in_pc_RS.default"
# NIH CXR14 (relabeled)
nih_cxr14 = "ptbench.configs.datasets.nih_cxr14_re.default"
nih_cxr14_cm = "ptbench.configs.datasets.nih_cxr14_re.cardiomegaly"
nih_cxr14 = "ptbench.data.nih_cxr14_re.default"
nih_cxr14_cm = "ptbench.data.nih_cxr14_re.cardiomegaly"
# NIH CXR14 / PadChest aggregated dataset
nih_cxr14_pc_idiap = "ptbench.configs.datasets.nih_cxr14_re_pc.idiap"
nih_cxr14_pc_idiap = "ptbench.data.nih_cxr14_re_pc.idiap"
# PadChest
padchest_idiap = "ptbench.data.padchest.idiap"
padchest_tb_idiap = "ptbench.data.padchest.tb_idiap"
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
def _maker(protocol, size=512):
import torchvision.transforms as transforms
from ....data.nih_cxr14_re import dataset as raw
from .. import make_dataset as mk
# ImageNet normalization
normalize = transforms.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
)
return mk(
[raw.subsets(protocol)],
[transforms.Resize((size, size))],
[transforms.RandomHorizontalFlip()],
[transforms.ToTensor(), normalize],
)
......@@ -72,9 +72,27 @@ def _loader(context, sample):
return make_delayed(sample, _raw_data_loader)
dataset = JSONDataset(
json_dataset = JSONDataset(
protocols=_protocols,
fieldnames=("data", "label"),
loader=_loader,
)
"""NIH CXR14 (relabeled) dataset object."""
def _maker(protocol, size=512):
import torchvision.transforms as transforms
from .. import make_dataset
# ImageNet normalization
normalize = transforms.Normalize(
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
)
return make_dataset(
[json_dataset.subsets(protocol)],
[transforms.Resize((size, size))],
[transforms.RandomHorizontalFlip()],
[transforms.ToTensor(), normalize],
)
......@@ -11,6 +11,38 @@ First 40 images with cardiomegaly.
* See :py:mod:`ptbench.data.nih_cxr14_re` for dataset details
"""
from clapper.logging import setup
from .. import return_subsets
from ..base_datamodule import BaseDataModule
from . import _maker
dataset = _maker("cardiomegaly")
logger = setup(__name__.split(".")[0], format="%(levelname)s: %(message)s")
class Fold0Module(BaseDataModule):
def __init__(
self,
train_batch_size=1,
predict_batch_size=1,
drop_incomplete_batch=False,
multiproc_kwargs=None,
):
super().__init__(
train_batch_size=train_batch_size,
predict_batch_size=predict_batch_size,
drop_incomplete_batch=drop_incomplete_batch,
multiproc_kwargs=multiproc_kwargs,
)
def setup(self, stage: str):
self.dataset = _maker("cardiomegaly")
(
self.train_dataset,
self.validation_dataset,
self.extra_validation_datasets,
self.predict_dataset,
) = return_subsets(self.dataset)
datamodule = Fold0Module
......@@ -10,6 +10,38 @@ protocol)
* See :py:mod:`ptbench.data.nih_cxr14_re` for dataset details
"""
from clapper.logging import setup
from .. import return_subsets
from ..base_datamodule import BaseDataModule
from . import _maker
dataset = _maker("default")
logger = setup(__name__.split(".")[0], format="%(levelname)s: %(message)s")
class DefaultModule(BaseDataModule):
def __init__(
self,
train_batch_size=1,
predict_batch_size=1,
drop_incomplete_batch=False,
multiproc_kwargs=None,
):
super().__init__(
train_batch_size=train_batch_size,
predict_batch_size=predict_batch_size,
drop_incomplete_batch=drop_incomplete_batch,
multiproc_kwargs=multiproc_kwargs,
)
def setup(self, stage: str):
self.dataset = _maker("default")
(
self.train_dataset,
self.validation_dataset,
self.extra_validation_datasets,
self.predict_dataset,
) = return_subsets(self.dataset)
datamodule = DefaultModule
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment