Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • medai/software/mednet
1 result
Show changes
Showing
with 100 additions and 44 deletions
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Aggregated datamodule composed of Montgomery, Shenzhen, Indian, and TBX11k
"""Aggregated DataModule composed of Montgomery, Shenzhen, Indian, and TBX11k
datasets (cross-validation fold 5).
This remix dataset combines ``fold-5`` from Montgomery, Shenzhen, and Indian
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Aggregated datamodule composed of Montgomery, Shenzhen, Indian, and TBX11k
"""Aggregated DataModule composed of Montgomery, Shenzhen, Indian, and TBX11k
datasets (cross-validation fold 6).
This remix dataset combines ``fold-6`` from Montgomery, Shenzhen, and Indian
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Aggregated datamodule composed of Montgomery, Shenzhen, Indian, and TBX11k
"""Aggregated DataModule composed of Montgomery, Shenzhen, Indian, and TBX11k
datasets (cross-validation fold 7).
This remix dataset combines ``fold-7`` from Montgomery, Shenzhen, and Indian
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Aggregated datamodule composed of Montgomery, Shenzhen, Indian, and TBX11k
"""Aggregated DataModule composed of Montgomery, Shenzhen, Indian, and TBX11k
datasets (cross-validation fold 8).
This remix dataset combines ``fold-8`` from Montgomery, Shenzhen, and Indian
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Aggregated datamodule composed of Montgomery, Shenzhen, Indian, and TBX11k
"""Aggregated DataModule composed of Montgomery, Shenzhen, Indian, and TBX11k
datasets (cross-validation fold 9).
This remix dataset combines ``fold-9`` from Montgomery, Shenzhen, and Indian
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Aggregated datamodule composed of Montgomery, Shenzhen, Indian, and TBX11k
"""Aggregated DataModule composed of Montgomery, Shenzhen, Indian, and TBX11k
datasets (v2-others-vs-atb).
This remix dataset combines the ``default`` split from Montgomery, Shenzhen,
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""NIH CXR14 (relabeled) datamodule for computer-aided diagnosis (cardiomegaly
"""NIH CXR14 (relabeled) DataModule for computer-aided diagnosis (cardiomegaly
split).
Database reference: [NIH-CXR14-2017]_
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""NIH CXR14 (relabeled) datamodule for computer-aided diagnosis.
"""NIH CXR14 (relabeled) DataModule for computer-aided diagnosis.
Database reference: [NIH-CXR14-2017]_
"""
......@@ -63,7 +63,7 @@ class RawDataLoader(_BaseRawDataLoader):
)
def sample(self, sample: tuple[str, list[int]]) -> Sample:
"""Loads a single image sample from the disk.
"""Load a single image sample from the disk.
Parameters
----------
......@@ -72,10 +72,9 @@ class RawDataLoader(_BaseRawDataLoader):
where to find the image to be loaded, and an integer, representing the
sample label.
Returns
-------
The sample representation
The sample representation.
"""
file_path = sample[0] # default
if self.idiap_file_organisation:
......@@ -103,7 +102,7 @@ class RawDataLoader(_BaseRawDataLoader):
return tensor, dict(label=sample[1], name=sample[0]) # type: ignore[arg-type]
def label(self, sample: tuple[str, list[int]]) -> list[int]:
"""Loads a single image sample label from the disk.
"""Load a single image sample label from the disk.
Parameters
----------
......@@ -112,16 +111,26 @@ class RawDataLoader(_BaseRawDataLoader):
where to find the image to be loaded, and an integer, representing the
sample label.
Returns
-------
The integer labels associated with the sample
list[int]
The integer labels associated with the sample.
"""
return sample[1]
def make_split(basename: str) -> DatabaseSplit:
"""Returns a database split for the NIH CXR-14 database."""
"""Return a database split for the NIH CXR-14 database.
Parameters
----------
basename
Name of the .json file containing the split to load.
Returns
-------
An instance of DatabaseSplit.
"""
return JSONDatabaseSplit(
importlib.resources.files(__name__.rsplit(".", 1)[0]).joinpath(basename)
......@@ -129,7 +138,7 @@ def make_split(basename: str) -> DatabaseSplit:
class DataModule(CachingDataModule):
"""NIH CXR14 (relabeled) datamodule for computer-aided diagnosis.
"""NIH CXR14 (relabeled) DataModule for computer-aided diagnosis.
This dataset was extracted from the clinical PACS database at the National
Institutes of Health Clinical Center (USA) and represents 60% of all their
......@@ -172,6 +181,11 @@ class DataModule(CachingDataModule):
* fibrosis
* edema
* consolidation
Parameters
----------
split_filename
Name of the .json file containing the split to load.
"""
def __init__(self, split_filename: str):
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""NIH CXR14 (relabeled) datamodule (``default`` protocol).
"""NIH CXR14 (relabeled) DataModule (``default`` protocol).
* Training samples: 98637
* Validation samples: 6350
......
......@@ -11,7 +11,15 @@ from ..padchest.datamodule import make_split as make_padchest_split
class DataModule(ConcatDataModule):
"""Aggregated dataset composed of NIH CXR14 relabeld and PadChest
(normalized) datasets."""
(normalized) datasets.
Parameters
----------
cxr14_split_filename
Name of the .json file from crx14 containing the split to load.
padchest_split_filename
Name of the .json file from padchest containing the split to load.
"""
def __init__(self, cxr14_split_filename: str, padchest_split_filename):
cxr14_loader = CXR14Loader()
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Aggregated dataset composed of NIH CXR14 relabeld and PadChest (normalized)
datasets (no-tb-idiap split)."""
"""Aggregated dataset composed of NIH CXR14 relabeld and PadChest (normalized) datasets (no-tb-idiap split)."""
from mednet.config.data.nih_cxr14_padchest.datamodule import DataModule
......
......@@ -41,7 +41,7 @@ class RawDataLoader(_BaseRawDataLoader):
)
def sample(self, sample: tuple[str, int | list[int]]) -> Sample:
"""Loads a single image sample from the disk.
"""Load a single image sample from the disk.
Parameters
----------
......@@ -50,10 +50,9 @@ class RawDataLoader(_BaseRawDataLoader):
where to find the image to be loaded, and an integer, representing the
sample label.
Returns
-------
The sample representation
The sample representation.
"""
# N.B.: PadChest images are encoded as 16-bit grayscale images
image = PIL.Image.open(os.path.join(self.datadir, sample[0]))
......@@ -70,7 +69,7 @@ class RawDataLoader(_BaseRawDataLoader):
return tensor, dict(label=sample[1], name=sample[0]) # type: ignore[arg-type]
def label(self, sample: tuple[str, int | list[int]]) -> int | list[int]:
"""Loads a single image sample label from the disk.
"""Load a single image sample label from the disk.
Parameters
----------
......@@ -79,16 +78,26 @@ class RawDataLoader(_BaseRawDataLoader):
where to find the image to be loaded, and an integer, representing the
sample label.
Returns
-------
The integer labels associated with the sample
list[int]
The integer labels associated with the sample.
"""
return sample[1]
def make_split(basename: str) -> DatabaseSplit:
"""Returns a database split for the NIH CXR-14 database."""
"""Return a database split for the NIH CXR-14 database.
Parameters
----------
basename
Name of the .json file containing the split to load.
Returns
-------
An instance of DatabaseSplit.
"""
return JSONDatabaseSplit(
importlib.resources.files(__name__.rsplit(".", 1)[0]).joinpath(basename)
......@@ -322,6 +331,11 @@ class DataModule(CachingDataModule):
* vertebral degenerative changes
* vertebral fracture
* volume loss
Parameters
----------
split_filename
Name of the .json file containing the split to load.
"""
def __init__(self, split_filename: str):
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis.
"""Shenzhen DataModule for computer-aided diagnosis.
Database reference: [MONTGOMERY-SHENZHEN-2014]_
"""
......@@ -27,7 +27,14 @@ database."""
class RawDataLoader(_BaseRawDataLoader):
"""A specialized raw-data-loader for the Shenzhen dataset."""
"""A specialized raw-data-loader for the Shenzhen dataset.
Parameters
----------
config_variable
Key to search for in the configuration file for the root directory of this
database.
"""
datadir: str
"""This variable contains the base directory where the database raw data is
......@@ -41,7 +48,7 @@ class RawDataLoader(_BaseRawDataLoader):
)
def sample(self, sample: tuple[str, int]) -> Sample:
"""Loads a single image sample from the disk.
"""Load a single image sample from the disk.
Parameters
----------
......@@ -50,10 +57,9 @@ class RawDataLoader(_BaseRawDataLoader):
where to find the image to be loaded, and an integer, representing the
sample label.
Returns
-------
The sample representation
The sample representation.
"""
# N.B.: Image.convert("L") is required to normalize grayscale back to
# normal (instead of inverted).
......@@ -72,7 +78,7 @@ class RawDataLoader(_BaseRawDataLoader):
return tensor, dict(label=sample[1], name=sample[0]) # type: ignore[arg-type]
def label(self, sample: tuple[str, int]) -> int:
"""Loads a single image sample label from the disk.
"""Load a single image sample label from the disk.
Parameters
----------
......@@ -81,16 +87,26 @@ class RawDataLoader(_BaseRawDataLoader):
where to find the image to be loaded, and an integer, representing the
sample label.
Returns
-------
The integer label associated with the sample
int
The integer label associated with the sample.
"""
return sample[1]
def make_split(basename: str) -> DatabaseSplit:
"""Returns a database split for the Shenzhen database."""
"""Return a database split for the Shenzhen database.
Parameters
----------
basename
Name of the .json file containing the split to load.
Returns
-------
An instance of DatabaseSplit.
"""
return JSONDatabaseSplit(
importlib.resources.files(__name__.rsplit(".", 1)[0]).joinpath(basename)
......@@ -98,7 +114,7 @@ def make_split(basename: str) -> DatabaseSplit:
class DataModule(CachingDataModule):
"""Shenzhen datamodule for computer-aided diagnosis.
"""Shenzhen DataModule for computer-aided diagnosis.
The standard digital image database for Tuberculosis was created by the National
Library of Medicine, Maryland, USA in collaboration with Shenzhen No.3 People’s
......@@ -129,6 +145,11 @@ class DataModule(CachingDataModule):
* Grayscale, encoded as a single plane tensor, 32-bit floats,
square with varying resolutions, depending on the input image
* Labels: 0 (healthy), 1 (active tuberculosis)
Parameters
----------
split_filename
Name of the .json file containing the split to load.
"""
def __init__(self, split_filename: str):
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis (cross validation fold 0).
"""Shenzhen DataModule for computer-aided diagnosis (cross validation fold 0).
Database reference: [MONTGOMERY-SHENZHEN-2014]_
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis (cross validation fold 1).
"""Shenzhen DataModule for computer-aided diagnosis (cross validation fold 1).
Database reference: [MONTGOMERY-SHENZHEN-2014]_
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis (cross validation fold 2).
"""Shenzhen DataModule for computer-aided diagnosis (cross validation fold 2).
Database reference: [MONTGOMERY-SHENZHEN-2014]_
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis (cross validation fold 3).
"""Shenzhen DataModule for computer-aided diagnosis (cross validation fold 3).
Database reference: [MONTGOMERY-SHENZHEN-2014]_
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis (cross validation fold 4).
"""Shenzhen DataModule for computer-aided diagnosis (cross validation fold 4).
Database reference: [MONTGOMERY-SHENZHEN-2014]_
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis (cross validation fold 5).
"""Shenzhen DataModule for computer-aided diagnosis (cross validation fold 5).
Database reference: [MONTGOMERY-SHENZHEN-2014]_
......
# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch>
#
# SPDX-License-Identifier: GPL-3.0-or-later
"""Shenzhen datamodule for computer-aided diagnosis (cross validation fold 6).
"""Shenzhen DataModule for computer-aided diagnosis (cross validation fold 6).
Database reference: [MONTGOMERY-SHENZHEN-2014]_
......