How to cast fastai Image to a Pytorch Tensor?

Hello everyone!

I am trying to extract features of an image from ResNet50 model. Kindly refer the image below

I have removed the top layer of classification and the ReLU, BatchNorm1D and Dropout layers just preceding that so that I can obtain a 512 length feature vector for my images.

But when I do that and try to make a forward pass, I need to convert the datatype of the image from a to a tensor. Otherwise I cannot make the forward pass as seen in the screenshot below.

Can someone please explain a way to cast a fastai Image to a PyTorch tensor?

Thanks for your time.

With Regards,

try x.px or

1 Like

Thanks Julian! It worked…