Path of images corresponding to top_losses

How do I get the file paths corresponding to the top losses. I tried using the code suggested in Lesson 2:

losses,idxs = interp.top_losses(10)
for p in data.valid_ds.x[idxs]:
print(type§)`

But the type of “p” is class ‘fastai.vision.image.Image’ which contains the actual pixels. I can’t figure out a way to get the path of the file from it.
My data set is audio files which I’ve converted to spectrograms, so rather than showing the top losses, I’d like to listen to the top losses, for which I need to get the file name change the extension and then listen to it.

2 Likes

Figured out the problem. Rather than indexing into “x”, I should index into x.items

data.valid_ds.x.items[idxs]

15 Likes

Yep. I had the same problem.
Had to debug for hours to find .items property.

1 Like

@apparle, I’m glad you worded your question the way you did. I forgot plot_top_losses existed, and came looking for a way to basically re-implement it. Good to know the x.items[idxs] trick though.