TypeError: no implementation found for 'torch.nn.functional.smooth_l1_loss' on types that implement __torch_function__: [<class 'fastai.torch_core.TensorImage'>, <class 'fastai.vision.core.TensorBBox'>]

I am trying to use the fastai library to build a machine learning model for object detection. I’m not an expert in machine learning, so I searched online and found this tutorial at object detection tutorial but when I used Google colab to run it, I got error saying: TypeError: no implementation found for ‘torch.nn.functional.smooth_l1_loss’ on types that implement torch_function : [<class ‘fastai.torch_core.TensorImage’>, <class ‘fastai.vision.core.TensorBBox’>] And I’ve also tried a 2018 version of the same tutorial before but ran into the same problem. Does anyone know what’s going on?

3 Likes

I had to do this to get it working:

TensorImage.register_func(torch.nn.functional.smooth_l1_loss, TensorImage, TensorBBox)
TensorMultiCategory.register_func(TensorMultiCategory.mul, TensorMultiCategory, TensorImage)
TensorImage.register_func(torch.nn.functional.binary_cross_entropy_with_logits, TensorImage, TensorMultiCategory)

There is an issue currently because of named tensors as of pytorch 1.8(ish?)

5 Likes

This seems to have fixed the problem! Thank you so much!

2 Likes

Thanks. I had same issue!

3 Likes

Where should I paste this code?

as mentioned by @thatgeeman here
I in my case changed:

loss_func = nn.BCEWithLogitsLoss()
loss = loss_func(activs, y)

to

loss = loss_func(TensorBase(activs), TensorBase(y))
1 Like

Thank you - this worked. Chapter 6 / mgupta70’s response was where I was having an issue.