kbressem / transforms

WIP monai transforms
Apache License 2.0
1 stars 0 forks source link

MulticlassSegNrrdToOneHotd converts label from float32 to float64 #6

Open markus-hinsche opened 1 year ago

markus-hinsche commented 1 year ago

It should stay with the same dtype it receives

kbressem commented 1 year ago

I think this is a bug in monai.utils.type_conversion.convert_data_type. If you refer to the __call__ function of MulticlassSegNrrdToOneHot, convert_data_typeis the first and last function called.

def __call__(
        self, image: NdarrayOrTensor, label: NdarrayOrTensor, label_meta_dict: dict
    ) -> Tuple[NdarrayOrTensor, Dict]:
        """
        ...
        """
        label, dtype, _ = convert_data_type(label, np.ndarray) 

        ...

        one_hot, *_ = convert_data_type(one_hot, dtype)
        return (one_hot, label_meta_dict)

Here dtype is the datatype of the image (e.g. float32), which I save and then use to re-cast the one-hot image to said type.