What do the other arguments print out ( np.array(list(subject['affine'])), epoch, params['epoch_dir'])?
Although your image dimension look strange, I assume nib.Nifti1Image should handle it.
Could you try to debug your code line by line? E.g. I’m not sure if nib.Nifti1Image takes images in this shape or without the batch dimension, so you could try to call image = image.squeeze() before casting it.