2019 redux: lesson1.ipynb in Google Colab


(Tom Hale) #1

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>()
      1 
----> 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
      4 
      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 *
      4 
      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
      5 

/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>()
     59 
     60 
---> 61 class Field(RawField):
     62     """Defines a datatype together with instructions for converting to Tensor.
     63 

/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.


#2

Not sure but it looks as though you are applying versions of fastai notebooks with the incorrect versions of the fastai library reacon library version 1 would suit based on the version required.


(Tom Hale) #3

@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?


(Yijin) #4

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.


#5

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.


(Tom Hale) #6

@RogerS49 I’m not using conda. It’s not installed on Colab. Surely there is a pip freeze requrements.txt somewhere?


(Tom Hale) #7

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

(Vaibhav Singh) #8

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


(spectralLight) #9

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.


#10

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