Platform: Colab ✅

try: path = untar_data('URL_FROM_URLS'); This is a Path not a name of variable (like Path('./rossman.tgz')

But the correct answer to extract files from rossmann.tgz is linux comman:

!tar xvzf rossmann.tgz -C data/rossmann
1 Like

Hi ,

Thanks for the answer, but I am still getting the error.
can you please help me.

Invalid URL ‘rossman.tgz.tgz’: No schema supplied.

Below is the colab github link

Thanks and Regards,
Subho

That’s my mistake. I didn’t read it carefully. untar_data is used only for URLs, to extract your data by the path you need to use Linux command (make sure you have rossmann.tgz file in your colab, and folder data/rossmann/):

!tar xvzf rossmann.tgz -C data/rossmann

I used resnet34 and resnet50 for transfer learning in recognizing images. I am practicing on the topic and I would like to use other pre-trained model on the same dataset.

For what I understood not every function of fastai work well with colab.

Do you know other pre-trained model that I can test with fastai?
for resnet50 I just did:

learn = cnn_learner(data, models.resnet50, metrics=[error_rate,accuracy], wd=1e-1)

testing other models requirer some different implementations in colab?

Thank you for your help

Hello,
I would like to export my notebook, so I use : learn.export(), I run the cell, there is no error.
However, I can’t find the PKL file.
Could anyone tell me where is it stored ?
Thanks a lot

Hi @SimonFR
It is in the directory that you designated as the path argument in creating the data DataBunch object that you fed into your learn Learner object, e.g.

data = ImageDataBunch.from_folder(path,...) 
path.ls()

path is usually where it is and by default is named export.pkl

HTH.
Butch

1 Like

there is this error when i tried to run camvid.ipynb notebook of lesson 3 of fastai-v3
when i tried to fit the model using
learn.fit_one_cycle(10, slice(lr), pct_start=0.9)
it throws the following error
0.00% [0/10 00:00<00:00]
epoch train_loss valid_loss accuracy time

Interrupted

RuntimeError Traceback (most recent call last)
in ()
----> 1 learn.fit_one_cycle(10, slice(lr), pct_start=0.9)

/usr/local/lib/python3.6/dist-packages/fastai/train.py in fit_one_cycle(learn, cyc_len, max_lr, moms, div_factor, pct_start, final_div, wd, callbacks, tot_epochs, start_epoch)
20 callbacks.append(OneCycleScheduler(learn, max_lr, moms=moms, div_factor=div_factor, pct_start=pct_start,
21 final_div=final_div, tot_epochs=tot_epochs, start_epoch=start_epoch))
—> 22 learn.fit(cyc_len, max_lr, wd=wd, callbacks=callbacks)
23
24 def lr_find(learn:Learner, start_lr:Floats=1e-7, end_lr:Floats=10, num_it:int=100, stop_div:bool=True, wd:float=None):

/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in fit(self, epochs, lr, wd, callbacks)
194 callbacks = [cb(self) for cb in self.callback_fns] + listify(callbacks)
195 if defaults.extra_callbacks is not None: callbacks += defaults.extra_callbacks
–> 196 fit(epochs, self, metrics=self.metrics, callbacks=self.callbacks+callbacks)
197
198 def create_opt(self, lr:Floats, wd:Floats=0.)->None:

/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in fit(epochs, learn, callbacks, metrics)
103 if not learn.data.empty_val:
104 val_loss = validate(learn.model, learn.data.valid_dl, loss_func=learn.loss_func,
–> 105 cb_handler=cb_handler, pbar=pbar)
106 else: val_loss=None
107 if cb_handler.on_epoch_end(val_loss): break

/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in validate(model, dl, loss_func, cb_handler, pbar, average, n_batch)
60 if not is_listy(yb): yb = [yb]
61 nums.append(yb[0].shape[0])
—> 62 if cb_handler and cb_handler.on_batch_end(val_losses[-1]): break
63 if n_batch and (len(nums)>=n_batch): break
64 nums = np.array(nums, dtype=np.float32)

/usr/local/lib/python3.6/dist-packages/fastai/callback.py in on_batch_end(self, loss)
305 “Handle end of processing one batch with loss.”
306 self.state_dict[‘last_loss’] = loss
–> 307 self(‘batch_end’, call_mets = not self.state_dict[‘train’])
308 if self.state_dict[‘train’]:
309 self.state_dict[‘iteration’] += 1

/usr/local/lib/python3.6/dist-packages/fastai/callback.py in call(self, cb_name, call_mets, **kwargs)
247 “Call through to all of the CallbakHandler functions.”
248 if call_mets:
–> 249 for met in self.metrics: self._call_and_update(met, cb_name, **kwargs)
250 for cb in self.callbacks: self._call_and_update(cb, cb_name, **kwargs)
251

/usr/local/lib/python3.6/dist-packages/fastai/callback.py in _call_and_update(self, cb, cb_name, **kwargs)
238 def call_and_update(self, cb, cb_name, **kwargs)->None:
239 “Call cb_name on cb and update the inner state.”
–> 240 new = ifnone(getattr(cb, f’on
{cb_name}’)(**self.state_dict, **kwargs), dict())
241 for k,v in new.items():
242 if k not in self.state_dict:

/usr/local/lib/python3.6/dist-packages/fastai/callback.py in on_batch_end(self, last_output, last_target, **kwargs)
338 if not is_listy(last_target): last_target=[last_target]
339 self.count += last_target[0].size(0)
–> 340 val = self.func(last_output, *last_target)
341 if self.world:
342 val = val.clone()

/usr/local/lib/python3.6/dist-packages/fastai/metrics.py in accuracy(input, targs)
26 input = input.argmax(dim=-1).view(n,-1)
27 targs = targs.view(n,-1)
—> 28 return (input==targs).float().mean()
29
30 def accuracy_thresh(y_pred:Tensor, y_true:Tensor, thresh:float=0.5, sigmoid:bool=True)->Rank0Tensor:

RuntimeError: The size of tensor a (11520) must match the size of tensor b (172800) at non-singleton dimension 1

how to solve this issue

same question

are you facing the similar problem?

Yes. I was able to solve it by removing metrics at all from the Learner.

Hi,
What is your experience about training and execution times in Colab? When I mount the notebook on Gdrive to save models and data, running learn.fit_one_cycle(4) takes 16 minutes. Oddly the first epoch takes 13 min, the other epochs take 1 min each. Without mounting the notebook each epoch takes 2 min.
Any idea what the reason might be?
(GPU is activated)

In general a mounted notebook runs very slow: data.show_batch(rows=3, figsize=(7,6)) has a wall time of 43 s and building the data object takes 22 s.

At this point I am thinking about not mounting the notebooks, since redownloading the data seems faster.
Have you faced similar problems?

Double check if GPU is activated. Speed also depends on data. My colab works fine in terms of sdeed.

it is showing that error if we are using accuracy as metrics
i tried running the notebook with acc_camvid as metrics and it worked fine

Hi @marceduc,
Try copying your models and data from Google drive to the directories /content/data and /content/models and run them from there. These are the default directories used by fastai (linked to /root/.fastai/data and /root/.torch/models)
They will run much faster (I read somewhere but can’t find the link). You can still use gdrive as a backup drive when you want to save your models and data since files are not preserved across sessions (I suggest zipping the data directories first before backing up to speed up the copy)

HTH.
Butch

Hi,
I was designing a model on Google Colab and my dataset consists of .tif images categorized according to the folder.
But ImageDataBunch.from_folder(path, ...) gave me an error:
cannot identify image file '/content/train/../69.tif'
So I was wondering if there is a solution to it.
Thanks for the help.

Thanks for the tip, I switched to google Cloud now, which seems way more convenient. However, in case I would work with Colab again, I would then have to download/ move the data and models to the root directory every time I ran the notebook right?

Thanks,
Best Marc

Exactly.
I run a couple of lines of code in my colab notebooks
to do that.
How much are you paying for Google cloud btw?

Best regards,
Butch

I don’t remember the prices, but you get 300 $ free credit when you sign up, so it doesn’t matter for the beginning.

Shift+Tab tooltip

Hi I cant seem to get this working in Colab Lesson 1 Jupyter?

It there a trick
Can anyone else get it to work.
get_transforms for example?

dgrl

Just wanted to add that Google Colaboratory now comes with a 2-core CPU and a Tesla T4 GPU! Along with the 12 hour runtime, Google Colab is the obvious choice for free GPU servers (Kaggle Kernels only supports 9 hour runtime, with a P100 GPU). A couple tricks to improve speed:

  • Use to_fp16() to activate mixed precision training, which is supported by Tesla T4
  • Make sure the DataBunch num_workers>0 so the dataloader is parallelized (otherwise the dataloader will be a huge bottleneck when training)