Regression to single number

I am playing with a model that uses

data = (ImageItemList.from_csv(DATA,‘train_labels_cleaned.csv’, folder=‘train’, suffix=’.tif’)

train_labels_cleaned.csv is rows containing an image filename and a label of 0 or 1. As expected, data helps create a resnet model that uses cross entorpy loss between the two classes.

Instead, I would like to experiment with the same resnet model using regression loss, interpreting the 1s and 0s as numerical values rather than classes.

I tried replacing ImageItemList with PointsItemList. However the above statement barfs in PointsItemList.init() at ds.items[0].reshape(-1). ds.items[0] is a single Int. Though it has length 1, it can’t be reshaped.

Should PointsItemList be able to handle a scalar target (a bug)? Or do I need to define my own versions of PointsItemList, PointsLabelList, and PointsProcessor? Or some other approach entirely?

Please guide me toward the best way to handle this situation. Thanks!

1 Like

Ah, I just found a forum post and Medium article that addresses this issue. would stlll like to know the “recommended solution”. Thanks.

Just pass label_cls=FloatList. The Points classes are for points, so two coordinates, and more specifically ImagePoints (when you need to apply data augmentation to the points the same way as the image). For all other regression problems, FloatList is the label class you need.

1 Like

Thank you. That was a very simple answer and it just works. I only had to write a couple of custom metrics to interpret the regression prediction as class choices.

That said, and with true appreciation for all your good work, it concerns me that I typically spend hours reading docs, searching the forum, tracing source code, and experimenting to accomplish any operation that happens to be off the main track. In this case, many of the forum posts had workarounds that were off the mark. It seem that only you and a few others have enough global knowledge of the fastai library to come up with the ‘secret recipe’.

I don’t have a solution, and maybe I am an atypically dense and lazy user. But I know that you and Jeremy will not be around forever to respond to questions, so the library will need to become more accessible to typical users of every level. Perhaps we could start putting together a “cookbook database” of common off-the-usual-track uses and their best solutions.

Something else that would help me is a comprehensive list of all the hooks/procedure overrides/classes to subclass - every option to change the library’s default behavior. I know that you and Jeremy have put a lot of time and thought into how to provide fine control. But I have a hard time both discovering and correctly implementing the right ones. A list that explains what they are, what they do, when you would use them, and a couple of examples would greatly accelerate my learning and allow me be more self-directed. I would be be interested in editing such a list for clarity and usability, but don’t have the global understanding to make the first draft.

Thanks again for your good work.


The docs can certainly be improved, and some are even already outdated. The API has moved a lot since the beginning of the course to get to the (almost) stable point we are at now and I’m hopeful there will be more docs/tutorials/resources as we go forward (especially with part 2 of the course).


Hi, Pomo –

Have you made your way through course-v3? If not, you may consider doing so, as a lot of mysteries may be solved by watching Jeremy talk through and work with the library.

If you’d rather not, consider using the fastai video viewer. In the bottom-left corner, you can search the transcripts for possible solutions to your issues. You wouldn’t know the term “FloatList” beforehand to search for it, but Jeremy specifically mentions the label_cls=FloatList trick that Sylvain just mentioned for regression problems in Lesson 6 here. One way about it would have been to search for “regression” instead.

Of course, better docs will help the library mature, but the only way that happens sooner rather than later is more users get a hold of it, play with it, break it, and then write more complete docs for those who follow.

1 Like

On the same topic @sgugger can you please recommend me how can I create a DataBunch if I want to make a regression problem with 2 points (2 ImagePoints).
I am trying to convert 8th lesson of 2nd course from last year to the new library.
In the task of training system to locate largest Bounding box.

So, far despite of all my experiments I was not able to do it properly.