Skip to content

Commit

Permalink
Feature/update transforms (#293)
Browse files Browse the repository at this point in the history
* off by one

* add non-dict resize

* fix configs

* delete resize

---------

Co-authored-by: Benjamin Morris <[email protected]>
  • Loading branch information
benjijamorris and Benjamin Morris authored Sep 25, 2023
1 parent 6ca7278 commit a9be90c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 179 deletions.
35 changes: 12 additions & 23 deletions configs/data/im2im/gan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
# GANs use Tanh as final activation, target has to be in range [-1,1]
Expand Down Expand Up @@ -82,12 +79,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
# GANs use Tanh as final activation, target has to be in range [-1,1]
Expand Down Expand Up @@ -118,11 +112,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${source_col}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${source_col}
# input to synthetic image generation model is a semantic segmentation
Expand Down Expand Up @@ -153,12 +145,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
# GANs use Tanh as final activation, target has to be in range [-1,1]
Expand Down
30 changes: 12 additions & 18 deletions configs/data/im2im/labelfree.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ transforms:
C: 5
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
- _target_: monai.transforms.NormalizeIntensityd
Expand Down Expand Up @@ -81,12 +78,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
- _target_: monai.transforms.NormalizeIntensityd
Expand All @@ -104,6 +98,9 @@ transforms:
C: 5
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${source_col}
- _target_: monai.transforms.NormalizeIntensityd
Expand All @@ -130,12 +127,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
- _target_: monai.transforms.NormalizeIntensityd
Expand Down
30 changes: 12 additions & 18 deletions configs/data/im2im/omnipose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: cyto_dl.models.im2im.utils.omnipose.OmniposePreprocessd
label_keys: ${target_col}
dim: ${spatial_dims}
Expand Down Expand Up @@ -84,12 +81,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: cyto_dl.models.im2im.utils.omnipose.OmniposePreprocessd
label_keys: ${target_col}
dim: ${spatial_dims}
Expand All @@ -111,6 +105,9 @@ transforms:
C: 5
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${source_col}
- _target_: monai.transforms.NormalizeIntensityd
Expand All @@ -137,12 +134,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: cyto_dl.models.im2im.utils.omnipose.OmniposePreprocessd
label_keys: ${target_col}
dim: ${spatial_dims}
Expand Down
30 changes: 12 additions & 18 deletions configs/data/im2im/segmentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
- _target_: monai.transforms.NormalizeIntensityd
Expand Down Expand Up @@ -86,12 +83,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
- _target_: monai.transforms.NormalizeIntensityd
Expand All @@ -115,6 +109,9 @@ transforms:
C: 5
- _target_: monai.transforms.AddChanneld
keys: ${source_col}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${source_col}
- _target_: monai.transforms.NormalizeIntensityd
Expand All @@ -141,12 +138,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${data.columns}
- _target_: monai.transforms.NormalizeIntensityd
Expand Down
30 changes: 12 additions & 18 deletions configs/data/im2im/skoots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: cyto_dl.models.im2im.utils.SkootsPreprocessd
label_keys: ${target_col}
dim: ${spatial_dims}
Expand Down Expand Up @@ -84,12 +81,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: cyto_dl.models.im2im.utils.SkootsPreprocessd
label_keys: ${target_col}
dim: ${spatial_dims}
Expand All @@ -111,6 +105,9 @@ transforms:
C: 5
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: monai.transforms.ToTensord
keys: ${source_col}
- _target_: monai.transforms.NormalizeIntensityd
Expand All @@ -137,12 +134,9 @@ transforms:
C: 0
- _target_: monai.transforms.AddChanneld
keys: ${data.columns}
- _target_: cyto_dl.image.transforms.Resized
keys:
- ${source_col}
- ${target_col}
scale_factor: 0.25
spatial_dims: ${spatial_dims}
- _target_: monai.transforms.Zoomd
keys: ${data.columns}
zoom: 0.25
- _target_: cyto_dl.models.im2im.utils.SkootsPreprocessd
label_keys: ${target_col}
dim: ${spatial_dims}
Expand Down
2 changes: 1 addition & 1 deletion cyto_dl/image/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .contrastadjust import ContrastAdjustd
from .multiscale_cropper import RandomMultiScaleCropd
from .project import MaxProjectd
from .resize import Resized
from .resize import Resize, Resized
from .save import Save, Saved

try:
Expand Down
2 changes: 1 addition & 1 deletion cyto_dl/image/transforms/multiscale_cropper.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _get_max_start_indices(self, image_dict: Dict):
max_start_indices = np.minimum(max_start_indices_img, max_start_indices)
if np.any(max_start_indices < 0):
raise ValueError(f"Crop size {roi_size} is too large for image size {shape}")
return max_start_indices
return max_start_indices + 1 # range doesn't include end

def generate_slices(self, image_dict: Dict) -> Dict:
"""Generate dictionary of slices at all scales starting at random point."""
Expand Down
82 changes: 0 additions & 82 deletions cyto_dl/image/transforms/resize.py

This file was deleted.

0 comments on commit a9be90c

Please sign in to comment.