1 fastai简易练习
from fastai.vision import *
path = untar_data(URLs.MNIST_SAMPLE)
data = ImageDataBunch.from_folder(path)
这是用来加载数据的,但是我在使用的过程中出现了无法下载的情况,于是我用浏览器直接下载,然后解压之后,在使用ImageDataBunch来加载数据。fastai的一个方便的地方是可以很容易的实现加载数据和做数据增强。
-
Learner.lr_find进行学习率范围搜搜,可以帮助我们选择比较好的学习率。 -
Learner.fit_one_cycle使用1轮策略来提高我们模型的训练速度。 -
Learner.to_fp16这个会将我们的模型转化为16位定点类型,来实现在混合精度下的训练。
class Learner[source][test]
Learner(data:DataBunch,model:Module,opt_func:Callable='Adam',loss_func:Callable=None,metrics:Collection[Callable]=None,true_wd:bool=True,bn_wd:bool=True,wd:Floats=0.01,train_bn:bool=True,path:str=None,model_dir:PathOrStr='models',callback_fns:Collection[Callable]=None,callbacks:Collection[Callback]=<factory>,layer_groups:ModuleList=None,add_time:bool=True,silent:bool=None)
在基础训练中重要的类是Learner。
通过 pip 安装
通过下列三步可以用 pip 安装 fastai,要严格安装顺序执行。
- 安装每日编译 nightly 的 PyTorch,注意 cuda 的版本要和你自己的系统保持一致,比如在 CUDA 9.2 上安装:
pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cu92/torch_nightly.html
pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cu92/torch_nightly.html
- 安装定制的 torchvision,这个版本是在 nightly-pytorch 上编译的:
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ torchvision==0.2.1.post2
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ torchvision==0.2.1.post2
- 安装 fastai:
pip install fastai
有些时候,上面的命令会试图安装 torch-0.4.1,这时候可以使用下面的命令:
pip uninstall torchvision fastai
pip install --no-deps torchvision
pip install fastai
pip uninstall torchvision fastai
pip install --no-deps torchvision
pip install fastai
安装完毕,大家愉快的体验 fastai 的新特性吧!











网友评论