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


Window10 : cannot import name 'as_tensor'
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
Lesson 1 Discussion ✅
(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.


(Vasiliy K.) #11

Still can’t step over this error. I already have torchtext 0.2.3 installed via pip (running all on local Ubuntu machine) in conda env, but got this:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in
----> 1 from fastai.imports import *

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/init.py in
----> 1 from .basic_train import *
2 from .callback import *
3 from .callbacks import *
4 from .core import *
5 from .basic_data import *

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/basic_train.py in
1 "Provides basic training and validation with Learner"
----> 2 from .torch_core import *
3 from .basic_data import *
4 from .callback import *
5

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/torch_core.py in
1 “Utility functions to help deal with tensors”
----> 2 from .imports.torch import *
3 from .core import *
4
5 AffineMatrix = Tensor

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/imports/init.py in
1 from .core import *
----> 2 from .torch import *

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/imports/torch.py in
1 import torch, torch.nn.functional as F
2 from torch import ByteTensor, DoubleTensor, FloatTensor, HalfTensor, LongTensor, ShortTensor, Tensor
----> 3 from torch import nn, optim, as_tensor
4 from torch.utils.data import BatchSampler, DataLoader, Dataset, Sampler, TensorDataset

ImportError: cannot import name ‘as_tensor’


(Jonathan Mills) #12

Has anyone had this error (or solved it) using Crestle?


(Karthik) #13

Thanks, this worked for me.


(Ajish Anil) #14

im using jupyter notebook on windows. Can you specify the command usning conda or pip