CastToType not working possibly

Hi,
i am modifying the “clara_mri_seg_brain_tumors_br16_full_amp_v1” example for my example training.
My datasets are 16 bit nifti: both images and labels. One choice is to convert all the images to float. I was looking to useCastToType to convert int16 to float32. i have the below in the pre_transforms:

        {
            "name": "LoadNifti",
            "args": {
                "fields": [
                    "image"
                ],
                "dtype": "int16"
            }
        },

        {
            "name": "LoadNifti",
            "args": {
                "fields": [
                    "label"
                ],
                "dtype": "int16"
            }
        },

       {
            "name": "CastToType",
            "args":{
                "fields": "image",
                "dtype": "float32"
            }
        },

        {
            "name": "ConvertToChannelsFirst",
            "args": {
                "fields": [
                    "image",
                    "label"
                ]
            }
        },


]
I think i may be doing something wrong because there is runtime error.
ValueError: int16 should be floating point type
2021-01-11 12:23:35,543 - ChainTransformer - ERROR - Error occurred while applying <class ‘ai4med.components.transforms.load_nifti.LoadNifti’> to following data dict.
2021-01-11 12:23:35,543 - ChainTransformer - ERROR - Key: image, Value: b’/workspace/data/resampled/64_cube/train/images/CTAWHS_0028_0000.nii.gz’
2021-01-11 12:23:35,543 - ChainTransformer - ERROR - Key: label, Value: b’/workspace/resampled/64_cube/train/labels/CTAWHS_0028.nii.gz’
2021-01-11 12:23:35,544 - ChainTransformer - ERROR - Key: ID, Value: 5
2021-01-11 12:23:35,544 - ChainTransformer - ERROR - Key: image.shape_format, Value: b’none’
2021-01-11 12:23:35,544 - ChainTransformer - ERROR - Asked to stop training since training is impossible now
Any suggestions?
thanks

Hi
I am not sure why you needed to do this. loadnifti used nibabel lib which should be able to open your files. The dtype parameter is used to cast the numpy
Could you simply try the transformations without dtype parameters as they should default to float32.

Thanks for reply. As you know the medical image range is such that 16 bit is enough. So, to convert and store as float, the file size will increase, besides adding one more task :-). Storage is cheap no doubt but when we have a large dataset size, it inefficient.
Hope it is clearer?
Best regards
Krishnan

Hi
I totally get your use case and 100% agree you should not store duplication of the data. that is why we have transformations and have caching to speed training up.

That is not what I was asking, Sorry for not being clear. I was simply asking why you needed to manually do these conversions in separate transformations. I thing load nifti transform with default type = float32 should do the trick.
Could you just try that and may be use the save as nifti transform to confirm your data was opened correctly ?

Hi,
Thanks for reply. Could you kindly let me know how could i do
" I thing load nifti transform with default type = float32 should do the trick."

do you mean that in the above code snippet(which i shared) i should change dtype from int16 to float32?
Thank you,
Krishnan

You are Correct either change it or remove it all together since the default is float32.

Did that do the trick ?

To double check please use the saveasnifti transform as shown here clara-train-examples/trn_BYOC_transform.json at master · NVIDIA/clara-train-examples · GitHub
to save your volumes/ cropped volumes after all transformations just to make sure they were opened correctly