Am o problemă cu privire la formarea Pytorch modele. Încerc să-mi antrenez Pytorch model folosind dicom date și nifti GT cu toate Acestea, dimensiunea de greutate de fișier este ridicol de mic pentru modelul de formare nu este efectuată în mod normal.
Am folosit modelul de rețea Unet++
Cred că există o problemă cu date de încărcător. Dar eu nu pot fixe se...
Aș aprecia dacă m-ați putea ajuta.
Formatul de fișier imagine Raw este dicom și GT format de imagine este nifti
în 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
și Tren de Cod este
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()