Skip to content

Improve data type conversion performance in convert_to_numpy#4934

Merged
bhashemian merged 3 commits intoProject-MONAI:devfrom
gigony:improve_conversion_perf
Aug 19, 2022
Merged

Improve data type conversion performance in convert_to_numpy#4934
bhashemian merged 3 commits intoProject-MONAI:devfrom
gigony:improve_conversion_perf

Conversation

@gigony
Copy link
Copy Markdown
Contributor

@gigony gigony commented Aug 18, 2022

Signed-off-by: Gigon Bae [email protected]

#4900

Description

Improve type conversion(convert_to_numpy()) performance by converting to contiguous array first.

# Without patch
  Thread elapsed time (cucim loader) : 14.059558755951002
    type: <class 'monai.data.meta_tensor.MetaTensor'>, shape: (3, 60797, 34007), dtype: torch.float32

# With patch
  Thread elapsed time (cucim loader) : 10.268190009985119
    type: <class 'monai.data.meta_tensor.MetaTensor'>, shape: (3, 60797, 34007), dtype: torch.float32

test code

from contextlib import ContextDecorator
from time import perf_counter

import monai
from monai.transforms import LoadImage

loader_cucim = LoadImage(
    reader=monai.data.wsi_reader.WSIReader, backend="cucim", image_only=True)


class Timer(ContextDecorator):
    def __init__(self, message):
        self.message = message
        self.end = None

    def elapsed_time(self):
        self.end = perf_counter()
        return self.end - self.start

    def __enter__(self):
        self.start = perf_counter()
        return self

    def __exit__(self, exc_type, exc, exc_tb):
        if not self.end:
            self.elapsed_time()
        print("{} : {}".format(self.message, self.end - self.start))


image_file = "/home/gbae/repo/cucim/notebooks/input/006388_0.tif"

with Timer("  Thread elapsed time (cucim loader)") as timer:
    image = loader_cucim(image_file)
print(f"    type: {type(image)}, shape: {image.shape}, dtype: {image.dtype}")

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • 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 --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@bhashemian bhashemian enabled auto-merge (squash) August 18, 2022 23:56
@wyli
Copy link
Copy Markdown
Contributor

wyli commented Aug 19, 2022

/build

@bhashemian bhashemian merged commit 99a0d91 into Project-MONAI:dev Aug 19, 2022
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.

5 participants