Dicom data training failed by pytorch
I've got a problem about training the Pytorch models. I'm trying to train my Pytorch model using dicom data and nifti GT However, the size of the weight file is ridiculously small because model training is not performed normally.
I used network model Unet++
I think there is a problem with the data loader. But I can't fixe it...
I'd appreciate it if you could help me.
Raw image file format is dicom and GT image format is nifti
in my dataloder
def __getitem__(self, index):
    image_path = self.image_paths[index]
    image_GT_path = image_path[:8]+'_'+image_path[8:12]+'.nii'
    GT_path = self.GT_paths + image_GT_path

    ds = dcmread(self.root+image_path)
    image = ds.pixel_array.astype(np.float32)
    image = torch.from_numpy(image.transpose(0,1)/255)
    image = image.unsqueeze(0)

    GT = nib.load(GT_path)
    GT = GT.get_fdata(dtype=np.float32)
    print(GT.shape)
    GT = torch.from_numpy(GT.transpose(0,1))
    GT = GT.unsqueeze(0)

    return image, GT, image_path

and Train Code is
for epoch in range(self.num_epochs):

            self.unet.train(True)
            epoch_loss = 0
            for i, (images, GT,empty) in enumerate(tqdm(self.train_loader)):
                # GT : Ground Truth

                images = images.to(self.device)
                GT = GT.to(self.device)
                
                # SR : Segmentation Result
                SR = self.unet(images)
                SR_probs = torch.sigmoid(SR)

                SR_flat = SR_probs.view(SR_probs.size(0),-1)

                GT_flat = GT.view(GT.size(0),-1)
                loss =self.criterion(SR_flat,GT_flat)

                # self.criterion=DiceLoss() #BCE not use
                # loss = self.criterion(GT,SR_probs)
                epoch_loss += loss.item()
                train_losses.append(loss.item())
                # Backprop + optimize
                self.reset_grad()
                loss.backward()
                self.optimizer.step()


Depending on what modality your images are, this might possibly be due to not converting the image data into the correct, clinically relevent, machine/vendor independent, units prior to any ML training 0-1 normalization.
Typically in dicom files, the actual raw data values aren't that - they need processing...
For instance, if you're trying to train on CT data, then the units you should be trying to train your model on are Houndsfield's (HU) numbers.  (Do a google on that, CT and dicom to get some background).
However raw CT dicom data could be little or big endian, likely needs a slope/intercept correction applied and also could need to have look up tables applied to convert it into HU numbers.  ...ie can get complicated and messy.  (again do a bit of googling ...you at least should have a bit of background on this if you're trying to do anything with medical image formats).
I'm not sure how to process nifti data, however luckily for dicom files using pydicom this conversion can be done for you by the library, using (typically) a call to pydicom.pixel_data_handlers.util.apply_modality_lut:

dcm = pydicom.dcmread(my_ct_dicom_file)
data_in_HU = pydicom.pixel_data_handlers.util.apply_voi_lut(
    dcm.pixel_array,
    dcm
)

