Creating labels for Object Category List

I am not sure how to create labels for ObjectCategoryList, but had an issue with labelling
i am following docs:
Screenshot%20from%202018-12-21%2014-18-00
Screenshot%20from%202018-12-21%2014-14-13

This is how img2bbox[0] looks like:
Screenshot%20from%202018-12-21%2015-58-30
It tries to index PosixPath which does not support indexing ? If instead of passing a list of PosixPaths, i pass list of image names as in docs, it searches for PosixPaths . I’ve converted everything as shown in docs (COCO example), but still it provides this error. What does it expect ?

TypeError: 'PosixPath' object does not support indexing
When creating ObjectItemList it throws TypeError: 'float' object is not iterable. Even after using pdb, the reason is not known.

Docs aren’t much clear as to on which dim it expectslist( coordinates of bboxes) and list (labels) .

@sgugger I think not many ppl have worked with ObjectCategoryList. Could you please shed some light ? What does it actually expect ?

Nohting more than the example in data block docs that you seem to be using. Your dictionary img2bbox should map filenames to labels, not Path object to file names.

I did what you said (used filenames instead of PosixPath object)

Here is img2bbox from the docs:
Screenshot%20from%202018-12-24%2019-22-17
Screenshot%20from%202018-12-24%2019-22-25

Here is mine (single object detection):

Screenshot%20from%202018-12-24%2019-20-24
Screenshot%20from%202018-12-24%2019-23-46

Made it identical, and the error what I get from creating datablock:

  1. When I do src.show_batch(), i get:
    IndexError: too many indices for tensor of dimension 1

  2. How do we do the same for add_test, I also have labels for objects in folder.

Now it’s completely identical, converted form of single object classification:
Screenshot%20from%202018-12-25%2010-10-41

Screenshot%20from%202018-12-25%2010-50-57

I am not passing ndarray, it’s a dict containing nested list same as docs.

Error: TypeError: can't convert np.ndarray of type numpy.object_. The only supported types are: double, float, float16, int64, int32, and uint8.

I had the same issue, in my case it was coming from the fact that all labels had the same number of bbox and classes, the function array (line 240 from core.py) that is called in label_from_list (line 219 of data_block.py) doesn´t return the expected array.
When all items have the same number of labels you get this : [[[list([109.0, 69.0, 482.0, 285.0])] [‘a class’]]…], while you should have [[list([[27.0, 57.0, 978.0, 732.0]]) list([‘a class’])]

1 Like

Hi,
I’m also getting the same error while implementing object detection using fastai 0.7. I have 2 classes in my dataset. Were you able to fix this error?
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
in ()
----> 1 learn.lr_find(lrs/1000,1.)
2 learn.sched.plot(1)

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in lr_find(self, start_lr, end_lr, wds, linear, **kwargs)
    328         layer_opt = self.get_layer_opt(start_lr, wds)
    329         self.sched = LR_Finder(layer_opt, len(self.data.trn_dl), end_lr, linear=linear)
--> 330         self.fit_gen(self.model, self.data, layer_opt, 1, **kwargs)
    331         self.load('tmp')
    332 

/usr/local/lib/python3.6/dist-packages/fastai/learner.py in fit_gen(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, best_save_name, use_clr, use_clr_beta, metrics, callbacks, use_wd_sched, norm_wds, wds_sched_mult, use_swa, swa_start, swa_eval_freq, **kwargs)
    232             metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, fp16=self.fp16,
    233             swa_model=self.swa_model if use_swa else None, swa_start=swa_start,
--> 234             swa_eval_freq=swa_eval_freq, **kwargs)
    235 
    236     def get_layer_groups(self): return self.models.get_layer_groups()

/usr/local/lib/python3.6/dist-packages/fastai/model.py in fit(model, data, n_epochs, opt, crit, metrics, callbacks, stepper, swa_model, swa_start, swa_eval_freq, **kwargs)
    127             batch_num += 1
    128             for cb in callbacks: cb.on_batch_begin()
--> 129             loss = model_stepper.step(V(x),V(y), epoch)
    130             avg_loss = avg_loss * avg_mom + loss * (1-avg_mom)
    131             debias_loss = avg_loss / (1 - avg_mom**batch_num)

/usr/local/lib/python3.6/dist-packages/fastai/model.py in step(self, xs, y, epoch)
     50         if self.fp16: self.m.zero_grad()
     51         else: self.opt.zero_grad()
---> 52         loss = raw_loss = self.crit(output, y)
     53         if self.loss_scale != 1: assert(self.fp16); loss = loss*self.loss_scale
     54         if self.reg_fn: loss = self.reg_fn(output, xtra, raw_loss)

<ipython-input-106-9420521a9bbe> in ssd_loss(pred, targ, print_it)
     36     lcs,lls = 0.,0.
     37     for b_c,b_bb,bbox,clas in zip(*pred,*targ):
---> 38         loc_loss,clas_loss = ssd_1_loss(b_c,b_bb,bbox,clas,print_it)
     39         lls += loc_loss
     40         lcs += clas_loss

<ipython-input-106-9420521a9bbe> in ssd_1_loss(b_c, b_bb, bbox, clas, print_it)
     20 
     21 def ssd_1_loss(b_c,b_bb,bbox,clas,print_it=False):
---> 22     bbox,clas = get_y(bbox,clas)
     23     a_ic = actn_to_bb(b_bb, anchors)
     24     overlaps = jaccard(bbox.data, anchor_cnr.data)

<ipython-input-106-9420521a9bbe> in get_y(bbox, clas)
      1 def get_y(bbox,clas):
      2     bbox = bbox.view(-1,4)/sz
----> 3     bb_keep = ((bbox[:,2]-bbox[:,0])>0).nonzero()[:,0]
      4     return bbox[bb_keep],clas[bb_keep]
      5 

IndexError: too many indices for tensor of dimension 1