Hi Jordi. This is a cool project, and one that is close to my kitchen and heart! 90% accuracy seems very good for a single photo. As you noted, the other 10% might kill you.
When showing the results, I would like to show which are the mushroom classes that use to be confused by the predicted class, but I didn’t found a way to do it.
You are very close to what you ask for. I did this a year ago with imagenet categories, so please forgive me if my memory is not entirely accurate.
This cnn model outputs activations for the 43 classes. fastai automagically applies softmax activation and nll_loss to these activations. I am not sure how well this invisible process is documented, but you can see it by tracing fastai with a debugger.
So first define your own loss function that does the same as fastai and assign it to learn.loss_func. This assignment prevents fastai from automatically deducing the correct activation and loss functions. In your loss function, between softmax and nll_loss, you will find the probabilities for each class. Then you can list the probabilities of the most likely classes.
Note that these class probabilities are relative to each other. They will tell you, given the image, which classes are most likely, but they will not tell you that there is no mushroom present of any class. For that, you would need to train with sigmoid activation and set a threshold. I make this comment only because it is a recurring question on the forums that has not been clearly and definitively addressed.
Thanks for sharing this project!