Thank you for your kind response. Here What i did so far. Can you please highlight the mistake.
Here is my code and folder organization.
(upload://pr9pSRiQKjIGy9X03dr2BAlfY4F.png) ![Presentation4|690x388]
patient_dir = “D:\Brats2020\”
l_patnt =os.listdir(patient_dir)
#print(l_patnt)
class Brats2022(Dataset):
def init(self,patient_dir):
self.patient_dir = patient_dir
def __len__(self):
    return len(self.patient_dir)

def __getitem__(self, index):
    #return self.patient_dir[index]
    patient_dir = self.patient_dir[index]
    volumes = []
    patient_id = os.path.split(patient_dir)[-1]
    volume_path = os.path.join(patient_dir,patient_id + "_" + "seg"+".nii.gz")
    volume_seg = nib.load(volume_path)
    volu_im = volume_seg.get_fdata()
    np_arr = np.array(volu_im)
    data_transform = transforms.ToTensor()
    return data_transform(np_arr)