Skip to content

Commit

Permalink
Merge pull request #307 from iamrjgs/iamrjgs-patch-1
Browse files Browse the repository at this point in the history
Extract lambda to named function in monai transforms for dataloader
  • Loading branch information
surajpaib authored Nov 14, 2024
2 parents e447a6f + 3d2014e commit 029da30
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fmcib/preprocessing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def preprocess(image, spatial_size=(50, 50, 50)):
return T(image)


def image_as_tensor(x):
return x["image_path"].as_tensor()


def get_transforms(spatial_size=(50, 50, 50), precropped=False):
if precropped:
return monai_transforms.Compose(
Expand All @@ -20,7 +24,7 @@ def get_transforms(spatial_size=(50, 50, 50), precropped=False):
monai_transforms.NormalizeIntensityd(keys=["image_path"], subtrahend=-1024, divisor=3072),
monai_transforms.SelectItemsd(keys=["image_path"]),
monai_transforms.SpatialPadd(keys=["image_path"], spatial_size=spatial_size),
torchvision.transforms.Lambda(lambda x: x["image_path"].as_tensor()),
torchvision.transforms.Lambda(image_as_tensor),
]
)
else:
Expand All @@ -39,7 +43,7 @@ def get_transforms(spatial_size=(50, 50, 50), precropped=False):
monai_transforms.SelectItemsd(keys=["image_path"]),
monai_transforms.Transposed(keys=["image_path"], indices=(0, 3, 2, 1)),
monai_transforms.SpatialPadd(keys=["image_path"], spatial_size=spatial_size),
torchvision.transforms.Lambda(lambda x: x["image_path"].as_tensor()),
torchvision.transforms.Lambda(image_as_tensor),
]
)

Expand Down

0 comments on commit 029da30

Please sign in to comment.