with Google Colab

(Jahifu) #21

data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True), 2)
in colab this piece of code is taking about half an hour tell me how to do in less time?

(Bhoomit Vasani) #22

I’m adding modified Google Colab compatible notebooks here:

(abdullah) #23

Hi thanks but this doesnt work for it wont import fastai.transforms

(danny iskandar) #24

thank you for this. the thing have to wait a few minutes to install the fastai + dataset.
I wonder once I set it up, can I just share the notebook and people does not have to download the fastai + dataset?

(danny iskandar) #25

Hi Wiliam thank you for doing this. Do you see any advantage using Kaggle vs google colab for fastai?

also I wonder why do you need to modify the dataset and the way it was structure? can we just leave it as is?


(Marc Kelechava) #26

I’m planning to attempt working through the course just in Colab as well. I was able to get the first lesson imports running in a colab notebook with a few minor changes, and without pip installing fastai.

I have the notebook set to Python 2 and using their GPU. I began by running the first 3 blocks of the official course nb (i.e. new cells in a fresh nb, using the first 3 cells from the official lesson1 nb)

Then in order to upload the models - I downloaded (or cloned) the course github locally, then used this block of upload code to bring in files to colab, so they can be imported in the nb (separate cells for each below, see *** note below before attempting this):

from google.colab import files
src = list(files.upload().values())[0]
import vgg16

from google.colab import files
src = list(files.upload().values())[0]
import vgg16bn

from google.colab import files
src = list(files.upload().values())[0]
import utils

***Note - before doing this, Google colab uses the v2 of Keras, so I made some minor adjustments to the files prior to uploading.

In (on your machine) change line 42 to this: from keras.regularizers import l2, l1
and change line 45 to this: from keras.layers import deserialize as layer_from_config

in (on your machine) change line 177 in the fine tune function to this: self.ft(batches.num_classes)
and change line 213 in fit function to this:

self.model.fit_generator(batches, samples_per_epoch=batches.samples, nb_epoch=nb_epoch,
validation_data=val_batches, nb_val_samples=val_batches.samples)

OK, now you can go use those little upload script cells to bring the altered files in the notebook. Finally run this in a cell:

from utils import plots

Doing that got the next section of the official notebook code to work for me (also change batch size to 4 instead of 64 when you first run it). I realize I could probably just import fastai with pip but I kinda like having it by hand with manually uploaded files so I know it will be reproducible, and then I know where the dependencies are causing issues when things like Keras change versions.

edit! also important to actually bring the zip data into your colab environment if you do it this way. can be achieved like this:

!wget && unzip -qq -d data/

you’ll then see the data in the colab file browser; also make sure to adjust path (from the official code) by running a cell with: path = “data/dogscats/”

(Code Matter) #27

Sorry for hijacking this thread as I am not able to find button to create new post.
I have been trying to use crestle to create an instance but its stuck for over an hour. I refreshed couple of times but it doesn’t move forward. Any idea how to solve this issue? crestle

(Won Seob Seo) #28

as abdullah said this failed in importing fastai.transforms. (I ran !pip3 install “fastai<1”) and then the usual importing.

NameError                                 Traceback (most recent call last)
<ipython-input-8-94ce375e95cb> in <module>()
      1 from fastai.imports import *
----> 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/ in <module>()
      3 from enum import IntEnum
----> 5 def scale_min(im, targ, interpolation=cv2.INTER_AREA):
      6     """ Scales the image so that the smallest axis is of size targ.

NameError: name 'cv2' is not defined


Hi @bhoomit,

Using your notebook, I am getting “module ‘torch’ has no attribute ‘float32’” error at
from fastai.transforms import *.

Any suggestions? Thanks.

(Fadhli Ismail) #30

I dont think you can really get it run faster on Colab. I guess Colab only give us access to the least amount of GPU. Maybe you can try with more GPU on Google Cloud Platform.

(douglas smith) #31

i have gotten part of lesson1 working on colab:

as of 10-12-18 :slight_smile:

used alot of this code:

i do have some type-errors being thrown, if anyone can suggest a fix. tia

update: found this linked on wiki and wish i has seen it two weeks ago. first heard of from announcement of new version-1 … on twitter… my mistake for not reading up first

only use conda for courses and not pip …

really enjoying the videos… thanks

(SA) #32

Can we run the ML courses on Kaggle?

(Bhoomit Vasani) #33

Reset your runtime and try again. It happened to me too and reseting runtime solved it.