The stack trace error is:
UserWarning: Using a target size (torch.Size([64, 2, 4])) that is different to the input size (torch.Size([64, 8])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size. ret = func(*args, **kwargs)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_18456\2451463369.py in <module>
1 # Find a good learning rate with the learning rate finder
2
----> 3 learn.lr_find()
4 # NOTE: when running the above line an error is returned: running_mean should contain 4096 elements not 8192
5 # What is running_mean and why it should have 4096 elements?
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\callback\schedule.py in lr_find(self, start_lr, end_lr, num_it, stop_div, show_plot, suggest_funcs)
283 n_epoch = num_it//len(self.dls.train) + 1
284 cb=LRFinder(start_lr=start_lr, end_lr=end_lr, num_it=num_it, stop_div=stop_div)
--> 285 with self.no_logging(): self.fit(n_epoch, cbs=cb)
286 if suggest_funcs is not None:
287 lrs, losses = tensor(self.recorder.lrs[num_it//10:-5]), tensor(self.recorder.losses[num_it//10:-5])
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
219 self.opt.set_hypers(lr=self.lr if lr is None else lr)
220 self.n_epoch = n_epoch
--> 221 self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
222
223 def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _with_events(self, f, event_type, ex, final)
161
162 def _with_events(self, f, event_type, ex, final=noop):
--> 163 try: self(f'before_{event_type}'); f()
164 except ex: self(f'after_cancel_{event_type}')
165 self(f'after_{event_type}'); final()
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _do_fit(self)
210 for epoch in range(self.n_epoch):
211 self.epoch=epoch
--> 212 self._with_events(self._do_epoch, 'epoch', CancelEpochException)
213
214 def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _with_events(self, f, event_type, ex, final)
161
162 def _with_events(self, f, event_type, ex, final=noop):
--> 163 try: self(f'before_{event_type}'); f()
164 except ex: self(f'after_cancel_{event_type}')
165 self(f'after_{event_type}'); final()
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _do_epoch(self)
204
205 def _do_epoch(self):
--> 206 self._do_epoch_train()
207 self._do_epoch_validate()
208
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _do_epoch_train(self)
196 def _do_epoch_train(self):
197 self.dl = self.dls.train
--> 198 self._with_events(self.all_batches, 'train', CancelTrainException)
199
200 def _do_epoch_validate(self, ds_idx=1, dl=None):
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _with_events(self, f, event_type, ex, final)
161
162 def _with_events(self, f, event_type, ex, final=noop):
--> 163 try: self(f'before_{event_type}'); f()
164 except ex: self(f'after_cancel_{event_type}')
165 self(f'after_{event_type}'); final()
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in all_batches(self)
167 def all_batches(self):
168 self.n_iter = len(self.dl)
--> 169 for o in enumerate(self.dl): self.one_batch(*o)
170
171 def _do_one_batch(self):
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in one_batch(self, i, b)
192 b = self._set_device(b)
193 self._split(b)
--> 194 self._with_events(self._do_one_batch, 'batch', CancelBatchException)
195
196 def _do_epoch_train(self):
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _with_events(self, f, event_type, ex, final)
161
162 def _with_events(self, f, event_type, ex, final=noop):
--> 163 try: self(f'before_{event_type}'); f()
164 except ex: self(f'after_cancel_{event_type}')
165 self(f'after_{event_type}'); final()
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\learner.py in _do_one_batch(self)
173 self('after_pred')
174 if len(self.yb):
--> 175 self.loss_grad = self.loss_func(self.pred, *self.yb)
176 self.loss = self.loss_grad.clone()
177 self('after_loss')
<ipython-input-59-bf592cbdc4b7> in loss_fn(preds, targs, class_idxs)
1 def loss_fn(preds, targs, class_idxs):
----> 2 return L1Loss()(preds, targs.squeeze())
~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
1100 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1101 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102 return forward_call(*input, **kwargs)
1103 # Do not call functions when jit is used
1104 full_backward_hooks, non_full_backward_hooks = [], []
~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
94
95 def forward(self, input: Tensor, target: Tensor) -> Tensor:
---> 96 return F.l1_loss(input, target, reduction=self.reduction)
97
98
~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\functional.py in l1_loss(input, target, size_average, reduce, reduction)
3066 if has_torch_function_variadic(input, target):
3067 return handle_torch_function(
-> 3068 l1_loss, (input, target), input, target, size_average=size_average, reduce=reduce, reduction=reduction
3069 )
3070 if not (target.size() == input.size()):
~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\overrides.py in handle_torch_function(public_api, relevant_args, *args, **kwargs)
1353 # Use `public_api` instead of `implementation` so __torch_function__
1354 # implementations can do equality/identity comparisons.
-> 1355 result = torch_func_method(public_api, types, args, kwargs)
1356
1357 if result is not NotImplemented:
~\AppData\Local\Programs\Python\Python37\lib\site-packages\fastai\torch_core.py in __torch_function__(self, func, types, args, kwargs)
338 convert=False
339 if _torch_handled(args, self._opt, func): convert,types = type(self),(torch.Tensor,)
--> 340 res = super().__torch_function__(func, types, args=args, kwargs=kwargs)
341 if convert: res = convert(res)
342 if isinstance(res, TensorBase): res.set_meta(self, as_copy=True)
~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\_tensor.py in __torch_function__(cls, func, types, args, kwargs)
1049
1050 with _C.DisableTorchFunction():
-> 1051 ret = func(*args, **kwargs)
1052 if func in get_default_nowrap_functions():
1053 return ret
~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\functional.py in l1_loss(input, target, size_average, reduce, reduction)
3078 reduction = _Reduction.legacy_get_string(size_average, reduce)
3079
-> 3080 expanded_input, expanded_target = torch.broadcast_tensors(input, target)
3081 return torch._C._nn.l1_loss(expanded_input, expanded_target, _Reduction.get_enum(reduction))
3082
~\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\functional.py in broadcast_tensors(*tensors)
70 if has_torch_function(tensors):
71 return handle_torch_function(broadcast_tensors, tensors, *tensors)
---> 72 return _VF.broadcast_tensors(tensors) # type: ignore[attr-defined]
73
74
RuntimeError: The size of tensor a (8) must match the size of tensor b (4) at non-singleton dimension 2