MONAI framework is very slow while computing stain normalisation #5943
-
Hello, I am new to MONAI framework and I am working on stain normalization approach to generate images similar to target image using MONAI framework. Here is the implementation, I found from MONAI blog : from future import annotations import numpy as np from monai.transforms.transform import Transform [docs] Args: Note:
""" def init( def _deconvolution_extract_stain(self, image: np.ndarray) -> np.ndarray:
def call(self, image: np.ndarray) -> np.ndarray:
[docs] Performs stain deconvolution of the source image using the ExtractHEStains Args: Note:
""" def init( def call(self, image: np.ndarray) -> np.ndarray:
For me when I am running on a folder which contains 5400 webp tiles it is taking around half an hour. I have more than 2000 such folders and it takes at least a month to complete this procedure. Could u please let me know if there is anything I could do to speed up the process. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 13 replies
-
Hi @drbeh, could you please help take a look at this issue? |
Beta Was this translation helpful? Give feedback.
-
Hi @VinayMushunuri, You are right, this implementation is based on numpy but we do have a cupy implementation that is way faster than numpy.
from tranforms import CuCIM
normalizer = CuCIM(
name="normalize_colors_pca",
source_intensity=240.0,
alpha=1.0,
beta=0.345,
ref_stain_coeff=((0.5626, 0.2159), (0.7201, 0.8012), (0.4062, 0.5581)),
ref_max_conc=(1.9705, 1.0308),
image_type="intensity",
channel_axis=0,
)
normalized_image = normalizer(image) or simply: from tranforms import CuCIM
normalizer = CuCIM(name="normalize_colors_pca")
normalized_image = normalizer(image) |
Beta Was this translation helpful? Give feedback.
-
Hello @drbeh, |
Beta Was this translation helpful? Give feedback.
-
Also I found a bug in cucim.core.operations.color.stain_normalizer In line 123 and 131 it is returning cp.round(image) but ccording to cupy the correct syntax is cp.round_(image). It threw an error here for me, so please find this once. |
Beta Was this translation helpful? Give feedback.
-
A couple of questions regarding performance of the cuCIM implementation: Assuming you are using CuPy<11 it may help to also define the environment variable: |
Beta Was this translation helpful? Give feedback.
Hi @VinayMushunuri,
You are right, this implementation is based on numpy but we do have a cupy implementation that is way faster than numpy.
For you to use the cupy-based version, there are two options:
You can use them directly or use it in MONAI via
CuCIM
orCuCIMd
wrapper.