Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
46c34cd
Implement CuCIM wrapper transfrom
bhashemian Sep 12, 2021
fe09a19
Implement CuCIMd and RandCuCIMd
bhashemian Sep 12, 2021
920ea4e
Update init
bhashemian Sep 12, 2021
751f154
Update docs
bhashemian Sep 12, 2021
4a942e2
Order imports
bhashemian Sep 12, 2021
86767ce
Update RandCuCIM and RandCuCIMd to be randomly applied
bhashemian Sep 13, 2021
f45968c
Merge branch 'dev' into cucim-transform
bhashemian Sep 13, 2021
c9b3198
Add optional_import
bhashemian Sep 13, 2021
97eb1d8
Merge branch 'cucim-transform' of github.com:drbeh/MONAI into cucim-t…
bhashemian Sep 13, 2021
64c11ee
Update docs and docstring
bhashemian Sep 13, 2021
d433a22
Update cucim api for monai
bhashemian Sep 13, 2021
f9b690d
Merge branch 'dev' into cucim-transform
bhashemian Sep 13, 2021
2c260b9
Fix docs
bhashemian Sep 13, 2021
4e7c137
Update imports
bhashemian Sep 13, 2021
2500e09
Remove type checking for cupy.ndarray
bhashemian Sep 14, 2021
6b4505a
Merge branch 'dev' into cucim-transform
bhashemian Sep 14, 2021
da45518
Merge branch 'dev' into cucim-transform
bhashemian Sep 14, 2021
1715212
Update cuCIM exposed API
bhashemian Sep 14, 2021
3ca5d88
Update cucim transfom calls
bhashemian Sep 15, 2021
fca930d
fix typo
bhashemian Sep 15, 2021
299e9b7
Merge branch 'dev' into cucim-transform
bhashemian Sep 15, 2021
22a3ec9
Rename prob to apply_prob
bhashemian Sep 15, 2021
b996567
Add unittests for CuCIM tranform
bhashemian Sep 15, 2021
628b139
Add unittests for CuCIMDict transform
bhashemian Sep 15, 2021
e464c13
Add unittests for RandCuCIM transform
bhashemian Sep 16, 2021
41553ea
Add unittests for RandCuCIMDict transform
bhashemian Sep 16, 2021
71d6311
Merge branch 'dev' into cucim-transform
bhashemian Sep 16, 2021
1f6b6e2
Fix docstrigs
bhashemian Sep 16, 2021
a6c9c48
Merge branch 'dev' into cucim-transform
wyli Sep 16, 2021
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
Next Next commit
Implement CuCIM wrapper transfrom
Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
  • Loading branch information
bhashemian committed Sep 12, 2021
commit 46c34cdbd9c05a7597862efebb5db7773de1d78d
38 changes: 36 additions & 2 deletions monai/transforms/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import sys
import time
import warnings
from typing import Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union
from typing import TYPE_CHECKING, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union

import numpy as np
import torch
Expand All @@ -40,7 +40,12 @@
PILImageImage, has_pil = optional_import("PIL.Image", name="Image")
pil_image_fromarray, _ = optional_import("PIL.Image", name="fromarray")
cp, has_cp = optional_import("cupy")
cp_ndarray, _ = optional_import("cupy", name="ndarray")

if TYPE_CHECKING:
from cupy import ndarray as cp_ndarray
else:
cp_ndarray, _ = optional_import("cupy", name="ndarray")


__all__ = [
"Identity",
Expand Down Expand Up @@ -1101,3 +1106,32 @@ def __call__(self, img: torch.Tensor):
raise ValueError("img must be PyTorch Tensor, consider converting img by `EnsureType` transform first.")

return img.to(self.device, **self.kwargs)


class CuCIM:
"""
Wrap cuCIM transform, defined based on the transform name and args.
CuCIM transforms only work with CuPy arrays, so this transform expects input data to be `cupy.ndarray`.
Users can call `ToCuPy` transform to convert a numpy array or torch tensor to cupy array.

"""

def __init__(self, name: str, *args, **kwargs) -> None:
"""
Args:
name: The transform name in CuCIM package.
args: parameters for the CuCIM transform.
kwargs: parameters for the CuCIM transform.

"""
super().__init__()
transform, _ = optional_import("cucim.transforms", name=name)
self.trans = transform(*args, **kwargs)

def __call__(self, data: cp_ndarray):
"""
Args:
img: CuPy array for the cuCIM transform.

"""
return self.trans(data)