Hi ! thanks for you reply!
Currently i’m getting this:
RuntimeError Traceback (most recent call last)
in
17 exp_lr_scheduler = lr_scheduler.StepLR(optimizer_ft, step_size=75, gamma=0.1)
18
—> 19 model = train_model(model, optimizer_ft, exp_lr_scheduler, num_epochs=100)
in train_model(model, optimizer, scheduler, num_epochs)
62 # track history if only in train
63 with torch.set_grad_enabled(phase == ‘train’):
—> 64 outputs = model(inputs)
65 loss = calc_loss(outputs, labels, metrics)
66
F:\aaa\Anaconda3\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
545 result = self._slow_forward(*input, **kwargs)
546 else:
→ 547 result = self.forward(*input, **kwargs)
548 for hook in self._forward_hooks.values():
549 hook_result = hook(self, input, result)
~\Desktop\graph_rec_png\pytorch-unet\pytorch_unet_cable.py in forward(self, x)
44
45 x = self.upsample(x)
—> 46 x = torch.cat([x, conv3], dim=1)
47
48 x = self.dconv_up3(x)
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 23 and 32 in dimension 2 at C:/w/1/s/tmp_conda_3.7_055457/conda/conda-bld/pytorch_1565416617654/work/aten/src\THC/generic/THCTensorMath.cu:71
I’m using as the example to load my images 1024x1024 gay scale images in png format. The idea is to feed them into the Unet here in the example Unet
from torch.utils.data import Dataset, DataLoader
from torchvision import transforms, datasets, models
class SimDataset(Dataset):
def init(self, image_paths, mask_paths , transform=None):
self.image_paths = image_paths
self.mask_paths = mask_paths
def transforms(self, image, mask):
#img = img.resize((wsize, baseheight), PIL.Image.ANTIALIAS)
image = image.resize((64, 64), PIL.Image.NEAREST)
mask = mask.resize((64, 64), PIL.Image.NEAREST)
image = TF.to_tensor(image)
mask = TF.to_tensor(mask)
#mask = np.array(mask)
#mask = np.moveaxis(mask,2,0)
#mask = torch.from_numpy(np.array(mask))
#mask = mask.unsqueeze(0)
#mask = mask.unsqueeze(0)
return [image, mask]
def __getitem__(self, index):
image = Image.open(self.image_paths[index])
mask = Image.open(self.mask_paths[index])
x, y = self.transforms(image, mask)
return x, y
def __len__(self):
return len(self.image_paths)
The training loop would be as the one in that example (I used this model to train successfully a multi-class segmentation problem)
Thanks for any suggestion !