Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions synapse_net/inference/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
import warnings
from glob import glob
from typing import Dict, Optional, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union

# # Suppress annoying import warnings.
# with warnings.catch_warnings():
Expand Down Expand Up @@ -85,6 +85,7 @@ def get_prediction(
model: Optional[torch.nn.Module] = None,
verbose: bool = True,
with_channels: bool = False,
channels_to_normalize: Optional[List[int]] = [0],
Copy link
Contributor

@constantinpape constantinpape Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional implies that this value can be None. What happens if it is None?
I think in this case all channels should be normalized (independently).
I would also set this as the default, and for the cristae model pass channels_to_normalize=[0].

mask: Optional[np.ndarray] = None,
) -> np.ndarray:
"""Run prediction on a given volume.
Expand All @@ -99,6 +100,7 @@ def get_prediction(
tiling: The tiling configuration for the prediction.
verbose: Whether to print timing information.
with_channels: Whether to predict with channels.
channels_to_normalize: List of channels to normalize. Defaults to 0.
mask: Optional binary mask. If given, the prediction will only be run in
the foreground region of the mask.

Expand All @@ -120,8 +122,10 @@ def get_prediction(
# We standardize the data for the whole volume beforehand.
# If we have channels then the standardization is done independently per channel.
if with_channels:
input_volume = input_volume.astype(np.float32, copy=False)
# TODO Check that this is the correct axis.
input_volume = np.stack([torch_em.transform.raw.normalize(input_volume[0]), input_volume[1]], axis=0)
for ch in channels_to_normalize:
input_volume[ch] = torch_em.transform.raw.normalize(input_volume[ch])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this at normalize.

else:
input_volume = torch_em.transform.raw.standardize(input_volume)

Expand Down