How to customize LabelList class

Hi is there any way to customize the LabelList class returned by Label_from<> method.I can customize the below the ImageList class but not sure how to customize the label list class so as to override its method.

data_test = (RSNAobjectItemList.from_df(train_df , path=path2)
.split_by_rand_pct(0.15,seed=42)
.label_from_func(get_y_func)

    .transform(tfms, size=284)
    .add_test(test_fnames)
    .databunch(path=path2, bs=56)
    #.add_test(test_fnames)
    .normalize(imagenet_stats)
   
   )

Yup, if you check the source here you’ll notice you can pass it the label_cls keyword. So if you created a MyCustomImageList you can pass that here:

.label_from_func(get_y_func, label_cls=MyCustomImageList)

@LaurentH is correct that you can use label_cls to use custom labels. But this is not to actually set a custom LabelList, just a custom label class.
If you do really want a custom LabelList not just a custom label (if unsure you probably want a custom label) then you can set the RSNAobjectItemList._label_list attribute. Note though that many of the methods on LabelList just delegate to the respective methods on your ItemList, so check you can’t just override stuff there.

1 Like