Skip to content

Commit

Permalink
feat: Add CARE dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeschamps committed Oct 20, 2024
1 parent 209170c commit 046c343
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .napari-hub/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
18 changes: 15 additions & 3 deletions src/careamics_napari/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
57 changes: 55 additions & 2 deletions src/careamics_napari/sample_data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"})]

Expand Down Expand Up @@ -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()
21 changes: 21 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 046c343

Please sign in to comment.