I followed the object detection notebook with a custom dataloader and I get the following error
getters = [lambda o: o,
lambda o: df_png['bbox'].loc[df_png.isin([str(o).split('/')[-1].
replace('.png','_mask.png')]).any(axis=1)].values[0][0],
lambda o: df_png['bbox'].loc[df_png.isin([str(o).split('/')[-1].
replace('.png','_mask.png')]).any(axis=1)].values[0][1]
]
#Datablock and dataloader
def label_func(x):
print(x)
return path/'masks'/f'{x.stem}_mask.png'
#batch_tfms = [*aug_transforms()]
batch_tfms = [Rotate(), Flip(), Dihedral(), Normalize.from_stats(*imagenet_stats)]
def get_dls(bs, size):
if size==0:
db = DataBlock(blocks = (ImageBlock, BBoxBlock, BBoxLblBlock),
splitter = FuncSplitter(func),
get_items = get_image_files,
getters = getters,
# batch_tfms = batch_tfms
)
else:
db = DataBlock(blocks = (ImageBlock, BBoxBlock, BBoxLblBlock),
splitter = FuncSplitter(func),
get_items = get_image_files,
getters = getters,
# batch_tfms = batch_tfms,
item_tfms = [Resize(size, method='pad'),]
)
return db.dataloaders('/home/fabiog/jupyter/all_images', bs=bs)
> TypeError Traceback (most recent call last)
> /tmp/ipykernel_4357/465355952.py in <module>
> ----> 1 learn.fit_one_cycle(10, slice(1e-5, 1e-4))
>
> ~/jupyter/env_jupyter/lib/python3.7/site-packages/fastai/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
> 111 scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
> 112 'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
> --> 113 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
> 114
> 115 # Cell
>
> ~/jupyter/env_jupyter/lib/python3.7/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
>
> ~/jupyter/env_jupyter/lib/python3.7/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()
>
> ~/jupyter/env_jupyter/lib/python3.7/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):
>
> ~/jupyter/env_jupyter/lib/python3.7/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()
>
> ~/jupyter/env_jupyter/lib/python3.7/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
>
> ~/jupyter/env_jupyter/lib/python3.7/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):
>
> ~/jupyter/env_jupyter/lib/python3.7/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()
>
> ~/jupyter/env_jupyter/lib/python3.7/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):
>
> ~/jupyter/env_jupyter/lib/python3.7/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):
>
> ~/jupyter/env_jupyter/lib/python3.7/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()
>
> ~/jupyter/env_jupyter/lib/python3.7/site-packages/fastai/learner.py in _do_one_batch(self)
> 170
> 171 def _do_one_batch(self):
> --> 172 self.pred = self.model(*self.xb)
> 173 self('after_pred')
> 174 if len(self.yb):
>
> ~/jupyter/env_jupyter/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
> 1049 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
> 1050 or _global_forward_hooks or _global_forward_pre_hooks):
> -> 1051 return forward_call(*input, **kwargs)
> 1052 # Do not call functions when jit is used
> 1053 full_backward_hooks, non_full_backward_hooks = [], []
>
> TypeError: forward() takes 2 positional arguments but 3 were given
now if i add n_inp=1 i get the following error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_4357/465355952.py in <module>
----> 1 learn.fit_one_cycle(10, slice(1e-5, 1e-4))
~/jupyter/env_jupyter/lib/python3.7/site-packages/fastai/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
111 scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
112 'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
--> 113 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
114
115 # Cell
~/jupyter/env_jupyter/lib/python3.7/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
~/jupyter/env_jupyter/lib/python3.7/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()
~/jupyter/env_jupyter/lib/python3.7/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):
~/jupyter/env_jupyter/lib/python3.7/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()
~/jupyter/env_jupyter/lib/python3.7/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
~/jupyter/env_jupyter/lib/python3.7/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):
~/jupyter/env_jupyter/lib/python3.7/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()
~/jupyter/env_jupyter/lib/python3.7/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):
~/jupyter/env_jupyter/lib/python3.7/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):
~/jupyter/env_jupyter/lib/python3.7/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()
~/jupyter/env_jupyter/lib/python3.7/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')
~/jupyter/env_jupyter/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
1049 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1050 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1051 return forward_call(*input, **kwargs)
1052 # Do not call functions when jit is used
1053 full_backward_hooks, non_full_backward_hooks = [], []
~/jupyter/Practical-Deep-Learning-for-Coders-2.0/Computer Vision/imports/metrics.py in forward(self, output, bbox_tgts, clas_tgts)
146 n_classes = clas_preds.size(2)
147 return sum([self._one_loss(cp, bp, ct, bt)
--> 148 for (cp, bp, ct, bt) in zip(clas_preds, bbox_preds, clas_tgts, bbox_tgts)])/clas_tgts.size(0)
149
150 class SigmaL1SmoothLoss(nn.Module):
~/jupyter/Practical-Deep-Learning-for-Coders-2.0/Computer Vision/imports/metrics.py in <listcomp>(.0)
146 n_classes = clas_preds.size(2)
147 return sum([self._one_loss(cp, bp, ct, bt)
--> 148 for (cp, bp, ct, bt) in zip(clas_preds, bbox_preds, clas_tgts, bbox_tgts)])/clas_tgts.size(0)
149
150 class SigmaL1SmoothLoss(nn.Module):
~/jupyter/Practical-Deep-Learning-for-Coders-2.0/Computer Vision/imports/metrics.py in _one_loss(self, clas_pred, bbox_pred, clas_tgt, bbox_tgt)
131 bbox_pred = bbox_pred[bbox_mask]
132 bbox_tgt = bbox_tgt[matches[bbox_mask]]
--> 133 bb_loss = self.reg_loss(bbox_pred, bbox_to_activ(bbox_tgt, self.anchors[bbox_mask]))
134 else: bb_loss = 0.
135 matches.add_(1)
~/jupyter/env_jupyter/lib/python3.7/site-packages/torch/nn/functional.py in smooth_l1_loss(input, target, size_average, reduce, reduction, beta)
2983 reduce=reduce,
2984 reduction=reduction,
-> 2985 beta=beta,
2986 )
2987 if not (target.size() == input.size()):
~/jupyter/env_jupyter/lib/python3.7/site-packages/torch/overrides.py in handle_torch_function(public_api, relevant_args, *args, **kwargs)
1258 raise TypeError("no implementation found for '{}' on types that implement "
1259 '__torch_function__: {}'
-> 1260 .format(func_name, [type(arg) for arg in overloaded_args]))
1261
1262 has_torch_function = _add_docstr(
TypeError: no implementation found for 'torch.nn.functional.smooth_l1_loss' on types that implement __torch_function__: [<class 'fastai.torch_core.TensorImage'>, <class 'fastai.vision.core.TensorBBox'>]