Dataset for regression CNN

For anyone interested in playing with a set of images to be used to infer a single number I have made a dataset.

475 images:https://www.dropbox.com/sh/c5lzbo0l225oh9b/AAC8cxdVo6Z9kqluJI_cHRjka?dl=0
1423 images:https://www.dropbox.com/sh/65ib9v4vjym8ook/AABZzp1o_h5NC5KX8tN8OkwCa?dl=0

Each link has a csv file that has the image name and the correct y value

The 1423 images are random croppings of the 475 images.

I have a number of images that need a single number generated from the images. The number is the y coordinate of a feature in the image.
Here is an example of an image:


The number to be inferred is the y location of that line. in this case it is 60. Here is the image with a horizontal line drawn at y=60:

I’m gonna work on using cnn with a new head and new loss function to try to predict the correct number.

2 Likes

Do you have an example implementation of a regression cnn that achieves this? I am looking at a similar regression problem (predicting some height in pictures). Would be very appreciated!

Sure.

The key was to create the data bunch properly. once that was done the library took care of everything else.

I have a CSV that lists the image name and the float number i am trying to predict.
making the csv correct format was tricky. some tips: the filename column should not contain the extension. the y column has to be a float.
my csv has 2 columns, “filename” and “y_coordinate”

df = pd.read_csv(filename)
data = (ImageItemList.from_df(df, path, col='filename', suffix=".png")
        .random_split_by_pct()
        .label_from_df('y_coordinate')
        .databunch()
       )

once you have the data bunch you can use a normal create_cnn like i did:

learn = create_cnn(data, arch, metrics=metrics)

3 Likes

thanks, this actually worked, though I got extremely strange validation scores all over the place while training (but ending up in a good place in the end). Have you seen similar behaviour?

2 little things, maybe you can edit your post: it is actually cols not col, and I also had to specify the folder because otherwise there was a ‘./’ added in the middle of the path (though that seems a bug in fastai?)

Thanks again!

ah, and metrics always crashed the code, so I had to remove metrics. Did accuracy and error rate work for you? Did you use other metrics you wrote yourself?
(fastai 1.0.28)

Yes!. I got strange loss numbers on validation while training but ended up with what seemed like good numbers though I don’t have the experience at this point to judge if the loss numbers i was getting were good…

As for the metrics I probably passed in None or possibly didn’t even execute that exact line.

As for col vs cols maybe it worked for me because the first column was the image name and the second was the target…I’ll take a look and report back.

How can I create a neural network having in out as image and a numerical data to predict a one value numerical output