-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from funkelab/v0.0.3
Add demo video and interactivity
- Loading branch information
Showing
16 changed files
with
547 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
include LICENSE | ||
include README.md | ||
|
||
include src/napari_cellulus/sample_data/*.npy | ||
include src/napari_cellulus/napari.yaml | ||
recursive-exclude * __pycache__ | ||
recursive-exclude * *.py[co] |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
__version__ = "0.1.0" | ||
|
||
from .sample_data import tissue_net_sample | ||
from .load_sample_data import load_fluo_c2dl_huh7_sample | ||
|
||
__all__ = ("tissue_net_sample",) | ||
__all__ = ("load_fluo_c2dl_huh7_sample",) |
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,25 @@ | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
|
||
FLUO_C2DL_HUH7_SAMPLE_PATH = ( | ||
Path(__file__).parent / "sample_data/Fluo-C2DL-Huh7-sample.npy" | ||
) | ||
|
||
|
||
def load_fluo_c2dl_huh7_sample(): | ||
raw = np.load(FLUO_C2DL_HUH7_SAMPLE_PATH) | ||
num_samples = raw.shape[0] | ||
indices = np.random.choice(np.arange(num_samples), 5, replace=False) | ||
raw = raw[indices] | ||
|
||
return [ | ||
( | ||
raw, | ||
{ | ||
"name": "Raw", | ||
"metadata": {"axes": ["s", "c", "y", "x"]}, | ||
}, | ||
"image", | ||
) | ||
] |
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,48 @@ | ||
import torch | ||
|
||
|
||
class Model(torch.nn.Module): | ||
""" | ||
This class is a wrapper on the model object returned by cellulus. | ||
It updates the `forward` function and handles cases when the input raw | ||
image is not (S, C, (Z), Y, X) type. | ||
""" | ||
|
||
def __init__(self, model, selected_axes): | ||
super().__init__() | ||
self.model = model | ||
self.selected_axes = selected_axes | ||
|
||
def forward(self, raw): | ||
if "s" in self.selected_axes and "c" in self.selected_axes: | ||
pass | ||
elif "s" in self.selected_axes and "c" not in self.selected_axes: | ||
|
||
raw = torch.unsqueeze(raw, 1) | ||
elif "s" not in self.selected_axes and "c" in self.selected_axes: | ||
pass | ||
elif "s" not in self.selected_axes and "c" not in self.selected_axes: | ||
raw = torch.unsqueeze(raw, 1) | ||
return self.model(raw) | ||
|
||
@staticmethod | ||
def select_and_add_coordinates(outputs, coordinates): | ||
selections = [] | ||
# outputs.shape = (b, c, h, w) or (b, c, d, h, w) | ||
for output, coordinate in zip(outputs, coordinates): | ||
if output.ndim == 3: | ||
selection = output[:, coordinate[:, 1], coordinate[:, 0]] | ||
elif output.ndim == 4: | ||
selection = output[ | ||
:, coordinate[:, 2], coordinate[:, 1], coordinate[:, 0] | ||
] | ||
selection = selection.transpose(1, 0) | ||
selection += coordinate | ||
selections.append(selection) | ||
|
||
# selection.shape = (b, c, p) where p is the number of selected positions | ||
return torch.stack(selections, dim=0) | ||
|
||
def set_infer(self, p_salt_pepper, num_infer_iterations, device): | ||
self.model.eval() | ||
self.model.set_infer(p_salt_pepper, num_infer_iterations, device) |
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 |
---|---|---|
@@ -1,23 +1,17 @@ | ||
name: napari-cellulus | ||
display_name: Cellulus | ||
display_name: napari-cellulus | ||
contributions: | ||
commands: | ||
- id: napari-cellulus.tissue_net_sample | ||
python_name: napari_cellulus.sample_data:tissue_net_sample | ||
title: Load sample data from Cellulus | ||
- id: napari-cellulus.fluo_n2dl_hela_sample | ||
python_name: napari_cellulus.sample_data:fluo_n2dl_hela_sample | ||
title: Load sample data from Cellulus | ||
- id: napari-cellulus.load_fluo_c2dl_huh7_sample | ||
python_name: napari_cellulus.load_sample_data:load_fluo_c2dl_huh7_sample | ||
title: Load sample data | ||
- id: napari-cellulus.Widget | ||
python_name: napari_cellulus.widget:Widget | ||
title: Cellulus | ||
sample_data: | ||
- command: napari-cellulus.tissue_net_sample | ||
display_name: TissueNet | ||
key: tissue_net_sample | ||
- command: napari-cellulus.fluo_n2dl_hela_sample | ||
display_name: Fluo-N2DL-HeLa | ||
key: fluo_n2dl_hela_sample | ||
- command: napari-cellulus.load_fluo_c2dl_huh7_sample | ||
display_name: Fluo-C2DL-Huh7 | ||
key: load_fluo_c2dl_huh7_sample | ||
widgets: | ||
- command: napari-cellulus.Widget | ||
display_name: Cellulus |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.