Hello everyone,
I am trying to follow the example in the data_block section of the Documentation (link related to object detection.
I ran the following lines of code:
coco = untar_data(URLs.COCO_TINY)
images, lbl_bbox = get_annotations(coco/‘train.json’)
img2bbox = dict(zip(images, lbl_bbox))
get_y_func = lambda o:img2bbox[o.name]
data = (ObjectItemList.from_folder(coco)
.split_by_rand_pct()
.label_from_func(get_y_func)
.transform(get_transforms(), tfm_y=True)
.databunch(bs=16, collate_fn=bb_pad_collate))
Then I want to do a basic fitting:
learn = cnn_learner(data, models.resnet18, metrics=accuracy)
learn.fit(1)
I get the following error and stack trace:
<ipython-input-30-8587f3539821> in <module>
----> 1 learn.fit(1)
~\.conda\envs\gputest\lib\site-packages\fastai\basic_train.py in fit(self, epochs, lr, wd, callbacks)
200 callbacks = [cb(self) for cb in self.callback_fns + listify(defaults.extra_callback_fns)] + listify(callbacks)
201 self.cb_fns_registered = True
--> 202 fit(epochs, self, metrics=self.metrics, callbacks=self.callbacks+callbacks)
203
204 def create_opt(self, lr:Floats, wd:Floats=0.)->None:
~\.conda\envs\gputest\lib\site-packages\fastai\basic_train.py in fit(epochs, learn, callbacks, metrics)
99 for xb,yb in progress_bar(learn.data.train_dl, parent=pbar):
100 xb, yb = cb_handler.on_batch_begin(xb, yb)
--> 101 loss = loss_batch(learn.model, xb, yb, learn.loss_func, learn.opt, cb_handler)
102 if cb_handler.on_batch_end(loss): break
103
~\.conda\envs\gputest\lib\site-packages\fastai\basic_train.py in loss_batch(model, xb, yb, loss_func, opt, cb_handler)
28
29 if not loss_func: return to_detach(out), yb[0].detach()
---> 30 loss = loss_func(out, *yb)
31
32 if opt is not None:
TypeError: __call__() takes 3 positional arguments but 4 were given
I tried on a bigger dataset of my own, and I get the same results. What seems to be the problem? Thank you all for your help!