I’m trying to build a conv neural net to guess the age of someone based on their picture, using the UTK faces dataset. I did it once, a while ago when I was getting into deep learning for the first time and I remember getting pretty decent results. I lost that file and I am attempting to replicate this result. Unfortunately, I’m getting garbage!
I’ve been trying for hours and hours, and my neural net ALWAYS spits a number between 29 years and 30 years for some reason (I’m guessing it’s the average age in the dataset). I have no idea why!
I’ve tried changing the arch to resnet 34 and resnet 50, adding more linear layers, adding dropout and batchnorm, changing image size to 192 and to 224, training only the last few layers vs training all layers, setting the loss to F.mse_loss and F.l1_loss.
I’m always getting numbers between 29 and 30.
The strange thing is that I remember doing this a while ago with the old fast.ai, and getting pretty good results very quickly. And then coming up with custom loss functions so that it’s not that bad guessing 90 when the age is 80, but it’s pretty bad guessing 11 when the age is 1, and doing pretty well on the test set.
Just guessing, but could it be that the output is between - infinity to infinity, but your regression prediction needs to be between 0 to 90?
Maybe you need to squish the output
age = F.sigmoid(current_output) * (max_age_value - min_age_value) + min_age_value
I have the same result while trying to predict the age of somebody based on their ches x rays. While it is hard even for a experienced radiologist it is not that difficult to predict whether someone is <20 or < 60 or >60 and still I get a more or less constant prediction every time.
The predicted age is nowhere near the mean or median age of the sample so that is much more interesting.
I’m very much interested what other people are suggesting here
Nope, didn’t work when adding label_cls=FloatList to label_from_func. Still getting that everyone is aged 29 years old
I even tried dividing into 6 categories: baby (0-3), kid (4-13), teenager (14-20), young_adult (21-39), adult (40-69), elder_adult (70+) and got, after 3 epochs with resnet18, 84% accuracy! And the errors are mostly understandable: saying a 43 year-old is a young adult, etc.
But directly doing regression on the age… that’s too hard for the neural net somehow, so it just guesses 29 for everyone.
SOLVED!!! Finally, after so many hours, it was really dumb: My model was spitting things of shape (bs,1) and fast.ai was spitting things of shape (bs), which, together with broadcasting, was getting garbage.
So it’s solved now. I don’t know how to help others not to fall into the same trap.
I implented your model but somehow I’m still stuck with numbers in a very narrow range. Now it actually predicts the same for every image, lol. I have a l1_loss of 7-8 which shouldnt be too bad.
Hey @mraggi , thanks for your work here. It really helped me in my project.
I am very new to DL and have two questions on your work:
a. learn.split : If I understand it correctly, the choice you made is an arbitrary one and I can choose different splits and different number of splits as well.
b. Prediction on a single image: I am really struggling here. If I use factory method of cnn_learner, learn.predict is quite simply applied to image. But when I am using your method of “Learner”, I am getting some weird errors such as "Attribute Error: ’Tensor’ object has no attribute 'apply_tfms’