I switched my work over to FastAI2 last week and today got called on to use the first model to provide predictions on live data…and found it was a struggle as most of the info here on predictions is buried in long threads with reams of obsolete code (i.e. last summer).
Thus, I’d like to make some new, how to threads to keep up with the best practice way to accomplish a given task in v2 now that’s its closer to launch.
here’s an example of what you get right now in v2:
But what everyone usually wants is :
category prediction / confidence of that prediction / file name of what was processed for that prediction?
Thanks to help from @muellerzr and esp @vijayabhaskar we have the following code snippet to decompress this into much more readable/actionable results:
preds = learn.get_preds(dl=dls.test)
for index,item in enumerate(preds):
prediction = dls.categorize.decode(np.argmax(item)).upper()
confidence = max(item)
percent = float(confidence)
print(f"{prediction} {percent*100:.2f}% confidence. Image = {dls.test_ds.items[index].name}")
note the image path might not work exactly…I had to change to Image = {dl2.items[index].name}")
Related questions to help make v2 predictions as usable as possible:
1 - are heatmaps going to be supported so we can see esp for failure cases?
2 - Are resize and normalize transforms automatically done when we call get_preds?
3 - Is predict() for one item and get_preds for a batch?
4 - Can we feed the results from get_preds into show batch to be able to visualize the images and results?
I did browse the source code but there’s zero comments so I don’t know what things like with_input are supposed to mean, nor rm_type_transforms.
Anyway some more definitive tutorials and best practices for actually employing the models would help everyone as people pay dl practictioners to get results from their models and not just to build models for model building sake.