ImportError: cannot import name 'as_tensor'?


(Alankar) #1

I am running fast.ai notebooks on clouderizer.com with google colab for the Gpu. I am getting this error when I execute this line:

from fastai.imports import *

Help!

Edit: Problem Solved. Solution here


Fastai v0.7 install issues thread
#2

Hello,

I have the same issue running Fast.ai notebook directly on google colab interface.


(Kashish Mukheja) #3

Hello
Me too getting the same error !!!


#4

Hi,
The problem is: when you installed fastai dependencies you install Fastai 1.0 which is not made for courses. You need to use Fastai framework 0.7.0

Just replace the configuration code (for Google Colab) with this one, which worked for me:

!pip uninstall fastai
!pip install Pillow==4.1.1
!pip install "fastai==0.7.0"
!pip install torchtext==0.2.3
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
from os import path
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
!apt update && apt install -y libsm6 libxext6

accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu'
!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.3.0.post4-{platform}-linux_x86_64.whl torchvision
import torch
!pip install image

%matplotlib inline
from fastai.imports import *

Fastaiimports
(Rex Madden) #5

It depends if you’re trying to use the newer fast ai or the older one. It looks like you’re trying to run a notebook that relies on the older version. environment.yml doesn’t specify a version, and so it downloads the latest fastai. You can do something along the lines of pip install 'fastai<=0.7'. Or put that in the environment.yml and do a conda env update.

You’ll also need to get the right version of torchtext. See Google Colab-AttributeError: module ‘torch’ has no attribute ‘float32’


(SA) #6

Just to confirm, when you say Fastai 1.0 is not made for courses, you mean the current ML,DL1 &2 courses rely on fastai v0.7 right?
The live DL1 (v3) starting on October 22 will rely on v1.0. Correct?


(Alankar) #7

Yes the upcoming course will be based on fastai v1. The current vidoes are based on 0.7.0.


#8

I have the same issue. I am running fastai on an AWS EC2 instance (as an AMI) and I am getting this error when doing “from fastai.imports import *” on a Jupyter notebook (run on the same instance). I tried the solution linked by Alankar (pip install torchtext==0.2.3) but it hasn’t fixed it. Any ideas? Thanks in advance.


(Meet patel) #9

Thanks, this method worked for me.


(Minh D Vo) #10

Thank you so much. Your way works for me.