第0课:https://github.com/fastai/course-v3/blob/master/nbs/dl1/00_notebook_tutorial.ipynb
Jupyter Notebook的两种模式:Edit(绿色)和Command(蓝色)
按Esc键,切换到Command模式,按Enter键,进入所选Cell的Edit模式
在Cell外单击,切换到Command模式,在Cell内点击(Code Cell需要单击,Markdown Cell需要双击),切换到Edit模式
Jupyter Notebook每120秒自动保存,在Command模式下按s键手动保存,个人更习惯直接Ctrl+s进行保存
右上角查看Kernel的运行状态:Kernel Busy(实心圆●)或Kernel Idle(空心圆○)
Command模式下的快捷键
0+0:Restart Kernel
m:Convert cell to Markdown
y:Convert cell to Code
o:Toggle between hide or show output
Shift+Up/Down:选中多个cell(然后可以运行、复制、粘贴、合并这些cell)
Shift+M:合并选中的cell
Jupyter Notebook可以创建Terminal
Code Cell中的特殊用法
使用?function-name
、??function-name
、doc(function-name)
,可以查看文档
使用!
可以使用linux命令,并且使用{var_name}
可以直接引用python定义的变量,例如
folder = 'imagenet'
!ls -l {folder}
Line Magics
%matplotlib inline
%reload_ext autoreload
%autoreload 2
%matplotlib inline:This command ensures that all matplotlib plots will be plotted in the output cell within the notebook and will be kept in the notebook when saved.
%reload_ext autoreload, %autoreload 2:Reload all modules before executing a new line. If a module is edited, it is not necessary to rerun the import commands, the modules will be reloaded automatically.
%timeit:Runs a line a ten thousand times and displays the average time it took to run it.(似乎不太常用)
第1课:https://github.com/fastai/course-v3/blob/master/nbs/dl1/lesson1-pets.ipynb
untar_data
函数原型
Signature: untar_data(url:str, fname:Union[pathlib.Path, str]=None, dest:Union[pathlib.Path, str]=None, data=True, force_download=False) -> pathlib.Path
使用了参数:类型=默认值
的格式,Union[XXX, XXX]
表示或
path.ls()
返回一个list,包含了该目录下的所有文件的完整路径
查看learn.fit_one_cycle
的文档可知,默认的学习率为0.003
max_lr:Union[float, Collection[float], slice]=slice(None, 0.003, None)
learn.unfreeze()
learn.fit_one_cycle(3, max_lr=slice(1e-6,1e-4))
unfreeze后运行lr_find,选择的学习率为1e-6,然后取unfreeze前使用的学习率(默认为3e-3)的约1/10,此处为1e-4,然后令max_lr=slice(1e-6,1e-4)