Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dtype to ToCupy #2950

Merged
merged 6 commits into from
Sep 15, 2021
Merged

Add dtype to ToCupy #2950

merged 6 commits into from
Sep 15, 2021

Conversation

bhashemian
Copy link
Member

@bhashemian bhashemian commented Sep 14, 2021

Description

This PR allow ToCupy transform define the expected output dtype.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests.
  • In-line docstrings updated.

Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
@Nic-Ma
Copy link
Contributor

Nic-Ma commented Sep 14, 2021

Hi @drbeh ,

Thanks for your enhancement.
May I know your use case for this ToCupy transform? I think cuCIM already outputs data in cupy array?

Thanks.

@bhashemian
Copy link
Member Author

bhashemian commented Sep 14, 2021

Hi @drbeh ,

Thanks for your enhancement.
May I know your use case for this ToCupy transform? I think cuCIM already outputs data in cupy array?

Thanks.

Hi @Nic-Ma, you're right! cuCIM output data in the cupy array but it also expect the input data to be in cupy.ndarray and in specific data type (if needed). We already have conversion to cupy.ndarray (ToCupy) and this PR add the ability to define dtype for that array.

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Sep 14, 2021

Hi @drbeh ,

I see, could you please help provide the program of cuCIM loading part? I am a little bit confused by it also expects the input data to be in cupy.ndarray, I thought cuCIM reads data from file names.

Thanks.

@bhashemian
Copy link
Member Author

Hi @drbeh ,

I see, could you please help provide the program of cuCIM loading part? I am a little bit confused by it also expects the input data to be in cupy.ndarray, I thought cuCIM reads data from file names.

Thanks.

That's a good point. I see where the confusion come from. cuCIM team has developed several transforms that we are going to use them in MONAI in conjunction with other transforms (for instance the torch.Tensor based transforms) via a CuCIM wrapper (#2932). Thus, although cucim has data loading capabilities, a user can use transforms independently.

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Sep 15, 2021

OK, I see, thanks for your explanation.
Maybe you can use CastToType transform before ToCupy transform to achieve expected dtype?
I think it's better to make the ToCupy API align with ToTensor and ToNumpy, etc.
@wyli @rijobro What do you guys think?

Thanks in advance.

Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
@bhashemian
Copy link
Member Author

OK, I see, thanks for your explanation.
Maybe you can use CastToType transform before ToCupy transform to achieve expected dtype?
I think it's better to make the ToCupy API align with ToTensor and ToNumpy, etc.
@wyli @rijobro What do you guys think?

Thanks in advance.

Thank you @Nic-Ma for your suggestion. What you are saying would work but will create a redundant copy of the image.
For instance if we have a numpy.ndarray of np.uint8 and use ToCupy, it creates a cupy.ndarray with dtype np.uint8. Then if we call CastToType(np.float32), it will create another cupy.ndarray with dtype np.float32.

This is not efficient specially for large images.I believe we should change the ToTensor and ToNumpy to include dtype too.

@bhashemian
Copy link
Member Author

@Nic-Ma @wyli , I'd really appreciate your help in reviewing the cucim related PRs since we are depending on them for cucim integration and digital pathology performance optimization, which is supposed to be done by the end of the week,

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Sep 15, 2021

Hi @drbeh ,

OK, I see your point, as I said in #2926 (comment), to avoid to add more and more args, I will submit a PR to support kwargs directly soon.

Thanks.

@Nic-Ma
Copy link
Contributor

Nic-Ma commented Sep 15, 2021

Submitted ticket to track it: #2951
Thanks for raising this topic.

@bhashemian
Copy link
Member Author

Submitted ticket to track it: #2951
Thanks for raising this topic.

@Nic-Ma specifically for ToCupy it only supports dtype and does not support device, so don't you think that can we have this one without kwargs and only with dtype?

monai/transforms/utility/dictionary.py Outdated Show resolved Hide resolved
monai/utils/type_conversion.py Outdated Show resolved Hide resolved
monai/utils/type_conversion.py Outdated Show resolved Hide resolved
monai/utils/type_conversion.py Outdated Show resolved Hide resolved
tests/test_to_cupy.py Show resolved Hide resolved
Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
@bhashemian
Copy link
Member Author

Hi @Nic-Ma, thank you very much for your constructive comment. I have applied all of them. Please let me know if there is anything else. thanks

@bhashemian bhashemian enabled auto-merge (squash) September 15, 2021 04:15
monai/utils/type_conversion.py Outdated Show resolved Hide resolved
@bhashemian bhashemian disabled auto-merge September 15, 2021 04:17
Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
@bhashemian bhashemian enabled auto-merge (squash) September 15, 2021 04:19
@bhashemian bhashemian merged commit ff9c80f into Project-MONAI:dev Sep 15, 2021
@bhashemian bhashemian deleted the update-tocupy branch September 15, 2021 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants