📝 Deep Learning Lesson 1 Notes

如何使用Colab


这是fast.ai v3 课程使用Colab的快速入门指南

如何你不是第一次使用,请参看returning to work 指南

注意: 这是免费服务但不是随时都提供,而且你需要额外工作保存你的实验。务必仔细阅读colab说明理解服务的局限性.

Step 1: Accessing Colab

  1. 首先,登陆谷歌账户here.

  2. 然后, 前往 Colab Welcome Page 并点击 ‘Github’. 在 ‘Enter a GitHub URL or search by organization or user’ 一栏填写 ‘fastai/course-v3’. 你将看到所有课程notebooks,点击一个你感兴趣的.

  1. 在你运行前,需要告知Colab你希望使用GPU. 你可以点击 ‘Runtime’ tab 选择 ‘Change runtime type’. 在随后打开的窗口下拉菜单里选择‘GPU’,或者在edit中选择Notebook settings中选择GPU 然后点击 ‘Save’.

Step 2: Configuring your notebook instance

  1. 在你开始使用notebook前, 你需要安装必须的软件包。你可以用以下代码,运行第一个Cell
!pip install numpy==1.15
# then restart the runtime, open a new cell to run the following
!curl -s https://course.fast.ai/setup/colab | bash

  1. 然后,你会看到一个跳出窗口说 ‘Warning: This notebook was not authored by Google’; 你选中’Reset all runtimes before running’, 然后点击‘Run Anyway’.

  1. 在新窗口中点击 ‘Yes’.

Step 3: Saving your notebook

如果你是从github打开notebook,你需要将实验存入Google Drive. 你可以点击 ‘File’ 再点击 ‘Save’. 你可以看到以下窗口,然后点击‘SAVE A COPY IN DRIVE’


这将打开一个新 tab 含有相同文件位于你的Google Drive. 如果你希望保存后继续工作,那么直接在这个新tab中工作就可以. 你的notebook将被保存在一个叫 Colab Notebooks的文件夹位于你的Google Drive中.

Step 4: Saving your data files

如果你希望改写你的文件,你需要允许你的Colaboratory instance读取和改写你的 Google Drive. 你只需要在每一个notebook的第一个Cell中写入以下代码

from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
root_dir = "/content/gdrive/My Drive/"
base_dir = root_dir + 'fastai-v3/'

现在,你的 Google Drive 变成了一个文件系统允许标准python读写文件. 不要忘记给所有notebook的根目录地址前加上 base_dir . 例如, 在 lesson2-download.ipynb 5th cell, 做一下修改

path = Path(base_dir + 'data/bears')
dest = path/folder
dest.mkdir(parents=True, exist_ok=True)

More help

更多问题可以在 fast.ai forum 提出。

Colab

1 Like

I have a problem on google cloud instance I cannot do git pull it say permission denied, not sure why, I am owner of the project and still not working. How to setup git on google cloud instance right so that it works and so that I can do git pull.
Thank you

Marijan, where are you calling git pull from? It works fine for me after changing into this directory:

cd tutorials/fastai/course-v3

Can you confirm that you are calling this from your fastai instance and not locally? (Do you see

jupyter@my-fastai-instance:

in your terminal?)

yes I can confirm that I am in cd tutorials/fastai/course-v3 and I can see jupyter@my-fastai-instance:

but when I go git pull it said permission denied.

@PoonamV Does that give me the freedom to first give the dimensions as 224 x 224 , find the learning rate corresponding to that from learn.lr_find() and then unfreeze the layers , change the dimension back again to whatever I want and then train the unfreezed layers? Because I feel that when the dimensions are reduced, a lot of information goes missing which may be very crucial for certain specific classifications…

2 Likes

Very nicely done. Which tool did you use for the mindmap?

@leovcld, great job!!
I wonder whether you have also done mindmaps to the rest lesson 2-7!
If yes, could we share them too? thanks.

Thank you so much.

Very helpful. Thanks!!

Two things:

  1. create_cnn is now deprecated.
    learn = create_cnn(data, models.resnet34, metrics=error_rate)
    should now be
    learn = cnn_learner(data, models.resnet34, metrics=error_rate)

  2. doc(interp.plot_top_losses) throws an error.

2 Likes

My lesson 1 notes with some added clarifications. Hope some will find it helpful.

3 Likes

If I click it’s not opening the link.

I updated the link. Pls try now.

1 Like

Always remember to do an update on the fast.ai library and course repo.

conda install -c fastai fastai for the library update

git pull for the course repo update.

چرخ گوشت صنعتی

Have question regarind len(data.valid_ds)==len(losses)==len(idxs) on the first lesson. What is data.valid_ds?


These all show 0.00 probability… I think there might be a bug in the code or am I missing something

1 Like

Hi. I’m a bit confused about my resnet34 learning speeds. On a sagemaker p2.xlarge instance, running cell 13 of the notebook learn.fit_one_cycle(4), I’m finding each epoch takes about 1 minute. But in the lesson 1 video, it’s only shown as taking 29 seconds per epoch. I believe that the fastai docs suggest using this same p2.xlarge instance type, and Jeremy mentions a cost of $1/hour which is about right. If I upgrade to a p3.2xlarge instance I get times of around 32 seconds per epoch. Still slower than the lesson 1 video, and at a much higher cost of ~$4/hour. Any ideas why I should be seeing this performance gap?

data is your ImageDataBunch object.
data.valid_ds is referring to the validation dataset that is present in your ImageDataBunch object.
Similarly data.train_ds refers to the training data set.

1 Like

Hi All
In regards to the “Results” section of the lesson 1 where we are checking the results,I was just wondering where we do (len(data.valid_ds)==len(losses)==len(idxs), if it comes true, does it mean all our training data sets items are in the top losses? if so doesn’t that mean our training was not worthy?

No, it’s ensuring that each of these objects have the same length. If they had different lengths, then it means that there was a problem somewhere.

1 Like