Label_delim Error with ImageDataBunch.from_df when used with Float labels (regression task)

Hi there! I am trying to use ImageDataBunch loading from a dataframe for a regression task but I get:

TypeError: __init__() got an unexpected keyword argument 'label_delim'

This is in a clean environment with fastai==1.0.46 and pandas==0.24.1.

You can repoduce by running:

labels = np.ones(10)
fn = [str(i) for i in range(10)]
df = pd.DataFrame(data={'name':fn, 'label': labels})
data = ImageDataBunch.from_df('', df, label_col='label', fn_col='name')

This code works (returns pathing error since images in path do not exist) if labels are cast as int but then the learner becomes a classifier. Any float columns passed to the label_col returns the same error, so it is not possible to use .from_df with ImageDataBunch for regression.

Here is the error stack:

1 Like

Hi, try to pass label_cls = FloatList to the .from_df() method.

Thanks for the reply! This does not fix it unfortunately.

You can’t use a factory method of DataBunch to create a DataBunch for regression with floats, you have to use the data block API.

1 Like

Hey, try this:
data = (ImageList
.from_df(path=‘path_train’,df=‘df’)
.split_by_rand_pct()
.label_from_df(cols=1,label_cls=FloatList)
.transform(get_transforms(), size=(224,224))
.databunch()
.normalize(imagenet_stats))

1 Like

thank you , that solve me problem ,thank you

I am having the same problem. I am trying to do a regression task (input data is images and labels are floats) using a csv file that relates the image file name to the label. I tried ImageDataBunch.from_csv and I tried importing the csv as a dataframe and ImageDataBunch.from_df.

As you pointed out, I can’t use DataBunch for regression with floats so I tried it with ImageList as suggested by Yin Huang. However, I get:

TypeError: init() missing 1 required keyword-only argument: ‘after_open’

relating to the .from_df(). I even tried adding an after_open arguement (with a function that does nothing) but I got the exact same error. I also tried importing the data as a PointsItemList as suggested in https://docs.fast.ai/tutorial.inference.html#A-regression-example
but I get the same TypeError saying that I’m missing a required keyword-only argument of "after_open’

Has anyone else encountered this or know what I should do?

p.s. I’m running fastai 1.0.51 using a Jupyter Notebook through Gradient on PaperSpace