DataBlock for Image Regression fastai v2

I’m trying to do image regression with fastai v2 but some parts about building the DataBlock i didn’t understand yet.
I’ve already achieved this goal using the fastai v1 earlier, now im trying to do the same, using fastai v2, the code using v1 was:

Data = ( ImageList
 .from_df(path=path, df=dataset)
 .split_by_rand_pct()
 .label_from_df(cols=1, label_csl=FloatList)
 .transform(get_transforms(do_flip=false), size(224,398))
 .databunch()
 .normalize(imagenet_stats))

I want to do the equivalent above, but using the DataBlock of fastai v2.
The objective is to receive image as input and predict a continuos value using a dataframe which first column is the imagePath and the second column the continuous value.

Thank you.

@leozitor You should definitley go through Chapter 6 of Fastbook which explains how to build a datablock , debugging it etc. and also its usage for a Regression example.

But you’re looking at something like this…

dls = DataBlock(
    blocks=(ImageBlock, PointBlock),
    get_x=ColReader(x_column, pref='', suff=''), 
    get_y=ColReader(y_column),
    splitter=RandomSplitter(),
    batch_tfms=[*aug_transforms(size=(224,398)), 
                Normalize.from_stats(*imagenet_stats)]
).dataloaders(df)
3 Likes

It really worked,
from the code you sent i just changed the:
blocks=(ImageBlock, PointBlock)
to
blocks=(ImageBlock, RegressionBlock)
and it worked exactly how I was expecting !

Thank you

2 Likes