ERROR : data.show_batch "RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #3 'mat2' in call to _th_addmm_out"

Here’s the code and the output I did until the error :slight_smile:

image

Please help me in resolving this error .

!pip uninstall torch torchvision -y
!pip install torch==1.4.0 torchvision==0.5.0

Put these two line at the top of the notebook and run it. Restart the runtime and you are good to go. torch updated the release version on 21 april and fastai v1.0.60 became incompatable. although fastai has fixed the issue to make it compatable but unless someboday has installed fastai from source itself, getting the fixed changes is difficult. fastai need to create another relaese with updated changes

9 Likes

A big Thanks to you from my side


This is working as expected now.

Hi your solution works. But can you tell me if I need to reinstall everytime I reopen the file in colab or I do runtime

1 Like

Very interesting application. Where did you get the dataset from? I can certainly use this for my own garden. Thanks.

From here https://www.kaggle.com/c/plant-pathology-2020-fgvc7

1 Like

The default version on fastai in colab is v1.0.60 which is not compatable with torch v1.5.0. So everytime you would start a new notebook the default libraries get loaded and we see the error. To fix it we are downgreading torch. last week fastai also release version v1.0.61 which is now compatable with torch v1.5.0, so now insted of downgrading torch we can upgrade fastai and thing would start working with few warnings. You can upgrade fastai using:

!curl https://course.fast.ai/setup/colab | bash

we would be able to use fastai without doing all this only if google updates the default library of fastai. We don’t know how long it will take. You can use this command to check which fastai and torch version being used.

import torch
import fastai
print(torch.__version__)
print(fastai.__version__)
1 Like

I ran this code. I am not getting this error anymore:

RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #3 'mat2' in call to _th_addmm_out

However, this new error has come up now. Do you know how to fix it @rajnishrobin ?

It would be great to be able to use the solution you suggested, as although !pip install torch==1.4.0 torchvision==0.5.0 works, your solution is a lot quicker alternative.

There are no version of torch 1.4.0. Getting error of no version

The problem here is your images are being loaded as FP64 tensors instead of FP32 tensors. Not sure what’s causing it though.

Try, pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

you can simply add: ,label_cls=FloatList at the end of ImageList like below:

data = (ImageList.from_df(traindf, path=path, cols=“name”,
folder=“train”, suffix=".jpg",label_cls=FloatList)

          .label_from_df(cols="aim")
          .transform(tfms, size=size))