I’m trying to run
lesson1.ipynb
in Google Colab.
I’ve read through
this thread
and also
this gist
.
What is the cut-and-paste code to place in a cell at the top of
lesson1.ipynb
in order to get it to work?
If I use:
pip install fastai
I get the error:
ModuleNotFoundError: No module named 'fastai.transforms'
Trying with:
pip install fastai==0.7
I get:
mizani 0.5.3 has requirement pandas>=0.23.4, but you'll have pandas 0.22.0 which is incompatible.
plotnine 0.5.1 has requirement matplotlib>=3.0.0, but you'll have matplotlib 2.1.2 which is incompatible.
plotnine 0.5.1 has requirement pandas>=0.23.4, but you'll have pandas 0.22.0 which is incompatible.
torchvision 0.2.1 has requirement pillow>=4.1.1, but you'll have pillow 4.0.0 which is incompatible.
and then later:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-8c2b6852f90b> in <module>()
----> 2 from fastai.transforms import *
3 from fastai.conv_learner import *
4 from fastai.model import *
5 from fastai.dataset import *
/usr/local/lib/python3.6/dist-packages/fastai/transforms.py in <module>()
1 from .imports import *
----> 2 from .layer_optimizer import *
3 from enum import IntEnum
5 def scale_min(im, targ, interpolation=cv2.INTER_AREA):
/usr/local/lib/python3.6/dist-packages/fastai/layer_optimizer.py in <module>()
1 from .imports import *
----> 2 from .torch_imports import *
3 from .core import *
5 def opt_params(parm, lr, wd):
/usr/local/lib/python3.6/dist-packages/fastai/torch_imports.py in <module>()
1 import os
----> 2 import torch, torchvision, torchtext
3 from torch import nn, cuda, backends, FloatTensor, LongTensor, optim
4 import torch.nn.functional as F
5 from torch.autograd import Variable
/usr/local/lib/python3.6/dist-packages/torchtext/__init__.py in <module>()
----> 1 from . import data
2 from . import datasets
3 from . import utils
4 from . import vocab
/usr/local/lib/python3.6/dist-packages/torchtext/data/__init__.py in <module>()
2 from .dataset import Dataset, TabularDataset
3 from .example import Example
----> 4 from .field import RawField, Field, ReversibleField, SubwordField, NestedField, LabelField
5 from .iterator import (batch, BucketIterator, Iterator, BPTTIterator,
6 pool)
/usr/local/lib/python3.6/dist-packages/torchtext/data/field.py in <module>()
---> 61 class Field(RawField):
62 """Defines a datatype together with instructions for converting to Tensor.
/usr/local/lib/python3.6/dist-packages/torchtext/data/field.py in Field()
116 # numeric type.
117 dtypes = {
--> 118 torch.float32: float,
119 torch.float: float,
120 torch.float64: float,
AttributeError: module 'torch' has no attribute 'float32'
Pardon me if this has already been asked and answered - I did search and still came up empty handed.
@RogerS49 the pip install fastai
would have given me version 1.0.39, but as you can see above I have an issue with that also.
Have you tried running lesson1.ipnb
recently?
Just to confirm, you are trying to run the lesson1.ipynb (cats v dogs) for the 2017/18 version (v2) of the course? Note that the 2018/19 version (v3) should have their videos available online soon, so it might be better / easier to wait for that, and try to use fastai library v1 for it.
If you do mean to run the 2017/18 course, then as @RogerS49 mentioned, you need a different version of fastai, namely the older (pre-release) v0.7, with all its older dependencies including older pytorch torchvision etc. I am not familiar with Google Colab, but you should probably refer to this thread for fastai v0.7 setup.
AFAICT pandas 23 is part of the new set up and pandas 22 was the version for V2
mizani 0.5.3 has requirement pandas>=0.23.4, but you’ll have pandas 0.22.0 which is incompatible. plotnine 0.5.1 has requirement matplotlib>=3.0.0, but you’ll have matplotlib 2.1.2 which is incompatible. plotnine 0.5.1 has requirement pandas>=0.23.4, but you’ll have pandas 0.22.0 which is incompatible. torchvision 0.2.1 has requirement pillow>=4.1.1, but you’ll have pillow 4.0.0 which is incompatible.
So it seems some how you might be running v3 notebook/python environment against a v2 library thats all my observation is. Can’t be sure unless you do a conda list and compare it to the yams file.
From this answer, I used the following and successfully ran the lesson:
!pip install -q Pillow==4.1.1
!pip install -q "fastai==0.7.0"
!pip install -q torchtext==0.2.3
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
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
import os
accelerator = 'cu80' if os.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
!pip install -q image
Thanks mate, it worked for me too.
General question.
Any specific reason why, we have to use old version of fastai?
Are the notebook not updated yet? or will they be updated in the next iteration of the course? If so when will they be available?
I’m more familiar with tensorflow and keras and setting fastai and pytorch gave me more trouble than those two on colab
To run lesson1 in colab it is sufficient to only execute those 3 commands:
!pip install torchtext==0.2.3
!pip install fastai==0.7
!mkdir data && wget http://files.fast.ai/data/dogscats.zip && unzip dogscats.zip -d data/
The other commands in TomHales last post aren’t needed.
I think you will also need to restrict torch vision’s version else it will install a more recent version which has some incompatibility. The following worked for me. I saw the version numbers in the environment.yml file provided on Github. After a lot of trial and error, I was able to run all the code blocks successfully using just the following.
!pip install torchvision==0.1.9
!pip install fastai==0.7.0
!pip install torchtext==0.2.3
there is this weird error from sklearn
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-f3a299412c99> in <module>()
3 from sklearn.impute import SimpleImputer
4 imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
----> 5 from fastai.structured import *
7 from pandas_summary import DataFrameSummary
/usr/local/lib/python3.6/dist-packages/fastai/structured.py in <module>()
3 from sklearn_pandas import DataFrameMapper
----> 4 from sklearn.preprocessing import LabelEncoder, Imputer, StandardScaler
5 from pandas.api.types import is_string_dtype, is_numeric_dtype
6 from sklearn.ensemble import forest
ImportError: cannot import name 'Imputer'
I was wondering if I could find the version of sklearn used then by fastai==0.7.0
I fixed this using sed.
!sed --in-place '4 c\
from sklearn.preprocessing import LabelEncoder, StandardScaler;from sklearn.impute._base import SimpleImputer as Imputer' /usr/local/lib/python3.6/dist-packages/fastai/structured.py
Also this fix was according to this commit https://github.com/fastai/fastai/pull/2528/files