# Exception occured during image io error

**URL:** https://discourse.itk.org/t/exception-occured-during-image-io-error/5259
**Category:** Beginner Questions
**Tags:** python, simpleitk
**Created:** [August 12, 2022, 9:36pm UTC](https://discourse.itk.org/t/exception-occured-during-image-io-error/5259 "2022-08-12T21:36:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mahesh\_bhosale](https://discourse.itk.org/user_avatar/discourse.itk.org/mahesh_bhosale/32/2880_2.png) [@mahesh\_bhosale](https://discourse.itk.org/u/mahesh_bhosale)
#### Post date: [August 12, 2022, 9:36pm UTC](https://discourse.itk.org/t/exception-occured-during-image-io-error/5259/1 "2022-08-12T21:36:43Z")

</div>

Hi,

I have been trying to load the predicted segmentation mask, which is a 3d PyTorch tensor saved as a nifty file, but I am getting below error. I am actually able to load the image volumes stored in a similar manner but not sure what’s causing this issue while saving the segmentation mask.  
 ![image](https://discourse.itk.org/uploads/default/original/2X/4/4d67a6a2f82aeb5912f3e146f23e8d7bcb5e6792.png)  
Below is how I save the numpy array to nii.gz file.

```auto
       
        pred = nibabel.Nifti1Image(pred.numpy(), affine=np.eye(4))
       
        nibabel.save(pred, fnames[1])

```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [August 15, 2022, 12:50pm UTC](https://discourse.itk.org/t/exception-occured-during-image-io-error/5259/2 "2022-08-15T12:50:25Z")

</div>

What is `dtype` of `pred.numpy()`? Maybe pass `pred.numpy().astype('uint8')` instead?
