I want to apply the learning of Lesson3 to gland segmentation. The dataset is comming from https://warwick.ac.uk/fac/sci/dcs/research/tia/glascontest/about/
But I am getting this error, but I don’t know why ? Everything before this step works fine.
learn.lr_find()
The error
--------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
1 learn.loss_func=CrossEntropyFlat()
----> 2 learn.lr_find()
/usr/local/lib/python3.6/dist-packages/fastai/train.py in lr_find(learn, start_lr, end_lr, num_it, stop_div, **kwargs)
28 cb = LRFinder(learn, start_lr, end_lr, num_it, stop_div)
29 a = int(np.ceil(num_it/len(learn.data.train_dl)))
---> 30 learn.fit(a, start_lr, callbacks=[cb], **kwargs)
31
32 def to_fp16(learn:Learner, loss_scale:float=512., flat_master:bool=False)->Learner:
/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in fit(self, epochs, lr, wd, callbacks)
160 callbacks = [cb(self) for cb in self.callback_fns] + listify(callbacks)
161 fit(epochs, self.model, self.loss_func, opt=self.opt, data=self.data, metrics=self.metrics,
--> 162 callbacks=self.callbacks+callbacks)
163
164 def create_opt(self, lr:Floats, wd:Floats=0.)->None:
/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in fit(epochs, model, loss_func, opt, data, callbacks, metrics)
92 except Exception as e:
93 exception = e
---> 94 raise e
95 finally: cb_handler.on_train_end(exception)
96
/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in fit(epochs, model, loss_func, opt, data, callbacks, metrics)
82 for xb,yb in progress_bar(data.train_dl, parent=pbar):
83 xb, yb = cb_handler.on_batch_begin(xb, yb)
---> 84 loss = loss_batch(model, xb, yb, loss_func, opt, cb_handler)
85 if cb_handler.on_batch_end(loss): break
86
/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in loss_batch(model, xb, yb, loss_func, opt, cb_handler)
20
21 if not loss_func: return to_detach(out), yb[0].detach()
---> 22 loss = loss_func(out, *yb)
23
24 if opt is not None:
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
487 result = self._slow_forward(*input, **kwargs)
488 else:
--> 489 result = self.forward(*input, **kwargs)
490 for hook in self._forward_hooks.values():
491 hook_result = hook(self, input, result)
/usr/local/lib/python3.6/dist-packages/fastai/layers.py in forward(self, input, target)
117 def forward(self, input:Tensor, target:Tensor) -> Rank0Tensor:
118 n,c,*_ = input.shape
--> 119 return super().forward(input.view(n, c, -1), target.view(n, -1))
120
121 class MSELossFlat(nn.MSELoss):
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py in forward(self, input, target)
865 def forward(self, input, target):
866 return F.cross_entropy(input, target, weight=self.weight,
--> 867 ignore_index=self.ignore_index, reduction=self.reduction)
868
869
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
1920 if size_average is not None or reduce is not None:
1921 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 1922 return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
1923
1924
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
1773 if target.size()[1:] != input.size()[2:]:
1774 raise ValueError('Expected target size {}, got {}'.format(
-> 1775 out_size, target.size()))
1776 input = input.contiguous().view(n, c, 1, -1)
1777 target = target.contiguous().view(n, 1, -1)
ValueError: Expected target size (4, 101656), got torch.Size([4, 101007])