I tried this method without using dataset class but still its have error. Actually I have not much expertise in coding side but I trying to be a good programmer. Here is the code for another method which I am using.
cwd = 'C:/Users/Ali ktk/.spyder-py3/dataloader/data/train/1'
#data_dir = 'C:/Users/Ali ktk/.spyder-py3/dataloader/data/test/0/ADNI_137_S_0800_MR_MPR__GradWarp__N3__Scaled_Br_20081024125416989_S56178_I123506.nii'


#cwd = os.getcwd()#return current working directory
print(cwd)
#debugger
patient_id = os.listdir('C:/Users/Ali ktk/.spyder-py3/dataloader/data/train/1') #create a list that encompasses all the images we downloaded
len(patient_id)
print(patient_id)
#

#filename = glob.glob('C:/Users/Ali ktk/.spyder-py3/dataloader/data/train/1/ADNI_137_S_0800_MR_MPR__GradWarp__N3__Scaled_Br_20081024125416989_S56178_I123506.nii' + 'C:/Users/Ali ktk/.spyder-py3/dataloader/data/train/1/ADNI_137_S_0800_MR_MPR__GradWarp__N3__Scaled_Br_20081024125416989_S56178_I123506.nii')
#print(filename)    

dataimage = [patient_id]#[patient_id, image_matrix_normalized]
for patient in patient_id:
    for root, dirs, files in os.walk(cwd + "/ADNI/" + patient):
        flag = 0 
        for file in files:
            if file.endswith(".nii"):
                print(os.path.join(root, file))
                if flag < 1:
                    datapath.append(os.path.join(root, file))
                    print(os.path.join(root, file))
                    print(flag)
                    flag = flag + 1
datapath = [patient_id, 'C:/Users/Ali ktk/.spyder-py3/dataloader/data/train/1'] #[patient_id, path]
tar_dim = [256, 256, 160]

for path in datapath:
    mri = nib.load(cwd).get_data()
    mri = (mri - mri.min())/(mri.max() - mri.min())
    mri = mri - mri.mean()
    tar_mri = ndimage.zoom(mri,[tar_dim[0]/mri.shape[0],tar_dim[1]/mri.shape[1], tar_dim[2]/mri.shape[2]], order = 1)

    print(mri)
    print(mri.mean())
    print(mri.var())
    print(tar_mri.shape)
    plt.imshow(mri[125,:,:],'gray')
    plt.show()
    
    dataimage.append(tar_mri)
    

after running this code I got below error which belongs to unsupported files
ImageFileError: Cannot work out file type of "C:/Users/Ali ktk/.spyder-py3/dataloader/data/train/1"

Please any one who already work with Nii file format help me here?