Glad it worked.
Since your predict method was similar to what I use, I went backwards to see what could be the change. I looked at the loss functions in GitHub and noticed they were all ‘flat’. I felt changing your loss to something that uses ‘flat’ would work and it did (note, you can still write your custom loss functions)…
While I was debugging the code to understand why, I noticed another thread:
Image Classifier learn.predict(img) and Image Classifier learn.predict(img). It looks like FastAI v2 needs the ‘flat’ data, which your loss function would not provide.