From 046c343339805e14aca6792ff228bdbdc368ba87 Mon Sep 17 00:00:00 2001 From: jdeschamps <6367888+jdeschamps@users.noreply.github.com> Date: Sun, 20 Oct 2024 22:49:45 +0200 Subject: [PATCH] feat: Add CARE dataset --- .napari-hub/DESCRIPTION.md | 18 +++++++++ src/careamics_napari/napari.yaml | 18 +++++++-- src/careamics_napari/sample_data.py | 57 ++++++++++++++++++++++++++++- tests/test_samples.py | 21 +++++++++++ 4 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 tests/test_samples.py diff --git a/.napari-hub/DESCRIPTION.md b/.napari-hub/DESCRIPTION.md index 9bb33ce..f82a515 100644 --- a/.napari-hub/DESCRIPTION.md +++ b/.napari-hub/DESCRIPTION.md @@ -5,3 +5,21 @@ you wish not to do any customization for the napari hub listing. If you need some help writing a good description, check out our [guide](https://github.com/chanzuckerberg/napari-hub/wiki/Writing-the-Perfect-Description-for-your-Plugin) --> +CAREamics is a PyTorch library aimed at simplifying the use of Noise2Void and its many +variants and cousins (CARE, Noise2Noise, N2V2, P(P)N2V, HDN, muSplit etc.). + +## Why CAREamics? + +Noise2Void is a widely used denoising algorithm, and is readily available from the `n2v` +python package. However, `n2v` is based on TensorFlow, while more recent methods +denoising methods (PPN2V, DivNoising, HDN) are all implemented in PyTorch, but are +lacking the extra features that would make them usable by the community. + +The aim of CAREamics is to provide a PyTorch library reuniting all the latest methods +in one package, while providing a simple and consistent API. The library relies on +PyTorch Lightning as a back-end. In addition, we will provide extensive documentation and +tutorials on how to best apply these methods in a scientific context. + +## Installation and use + +Check out the [documentation](https://careamics.github.io/) for installation instructions and guides! diff --git a/src/careamics_napari/napari.yaml b/src/careamics_napari/napari.yaml index 28bf6ce..85d5220 100644 --- a/src/careamics_napari/napari.yaml +++ b/src/careamics_napari/napari.yaml @@ -5,13 +5,25 @@ contributions: - id: careamics-napari.make_train_widget python_name: careamics_napari.training_plugin:TrainPluginWrapper title: Train CAREamics - - id: careamics-napari.data_SEM + - id: careamics-napari.data_SEM_N2V python_name: careamics_napari.sample_data:n2v_sem_data title: Noise2Void SEM + - id: careamics-napari.data_SEM_N2N + python_name: careamics_napari.sample_data:n2n_sem_data + title: Noise2Noise SEM + - id: careamics-napari.data_U2OS_CARE + python_name: careamics_napari.sample_data:care_u2os_data + title: CARE U2OS widgets: - command: careamics-napari.make_train_widget display_name: Train CAREamics sample_data: - - command: careamics-napari.data_SEM - display_name: Download data (SEM) + - command: careamics-napari.data_SEM_N2V + display_name: Download data for N2V (SEM) key: careamics_n2v_SEM + - command: careamics-napari.data_SEM_N2N + display_name: Download data for N2N (SEM) + key: careamics_n2n_SEM + - command: careamics-napari.data_U2OS_CARE + display_name: Download data for CARE (U2OS) + key: careamics_care_U2OS diff --git a/src/careamics_napari/sample_data.py b/src/careamics_napari/sample_data.py index 58940ee..45a26cb 100644 --- a/src/careamics_napari/sample_data.py +++ b/src/careamics_napari/sample_data.py @@ -1,5 +1,6 @@ """Sample data for the careamics napari plugin.""" +import numpy as np from careamics.utils import get_careamics_home from careamics_portfolio import PortfolioManager from napari.types import LayerDataTuple @@ -36,8 +37,37 @@ def _load_sem_n2n() -> list[tuple[NDArray, dict[str, str]]]: files = [f for f in download if f.endswith("tif")] files.sort() - img_train = imread(files[2]) - img_target = imread(files[3]) + imgs_train = imread(files[1]) + img_train = imgs_train[2] + img_target = imgs_train[3] + + return [(img_train, {"name": "train"}), (img_target, {"name": "target"})] + + +def _load_u2os_care() -> list[tuple[NDArray, dict[str, str]]]: + """Download CARE U2OS data. + + Returns + ------- + list of (numpy.ndarray, dict) + List of data and layer name. + """ + root_path = get_careamics_home() + PortfolioManager().denoising.CARE_U2OS.download(root_path) + + # path to the training data + root_path = root_path / "denoising-CARE_U2OS.unzip" / "data" / "U2OS" + train_path = root_path / "train" / "low" + target_path = root_path / "train" / "GT" + + # load the training data + files_gt = list(target_path.glob("*.tif")) + files_gt.sort() + img_target = np.array([imread(f) for f in files_gt]) + + files_low = list(train_path.glob("*.tif")) + files_low.sort() + img_train = np.array([imread(f) for f in files_low]) return [(img_train, {"name": "train"}), (img_target, {"name": "target"})] @@ -88,3 +118,26 @@ def n2n_sem_data() -> LayerDataTuple: """ ntf.show_info("Downloading data might take a few minutes.") return _load_sem_n2n() + + +def care_u2os_data() -> LayerDataTuple: + """Load CARE U2OS data. + + Returns + ------- + LayerDataTuple + Data and layer name. + """ + ntf.show_info("Downloading data might take a few minutes.") + return _load_u2os_care() + + +if __name__ == "__main__": + + import napari + + # create a Viewer + viewer = napari.Viewer() + + # start UI + napari.run() diff --git a/tests/test_samples.py b/tests/test_samples.py new file mode 100644 index 0000000..0e0a64b --- /dev/null +++ b/tests/test_samples.py @@ -0,0 +1,21 @@ +import numpy as np + +from careamics_napari.sample_data import n2n_sem_data, n2v_sem_data, u2os_care_data + + +def test_n2v_sem_data(): + data = n2v_sem_data() + assert len(data) == 2 + assert all(isinstance(d, np.ndarray) for d, _ in data) + + +def test_n2n_sem_data(): + data = n2n_sem_data() + assert len(data) == 2 + assert all(isinstance(d, np.ndarray) for d, _ in data) + + +def test_u2os_care_data(): + data = u2os_care_data() + assert len(data) == 2 + assert all(isinstance(d, np.ndarray) for d, _ in data)