fastai

1、fastai简介

fastai是一款由Jeremy Howard和Rachel Thomas发起基于PyTorch的深度学习框架,旨在让机器学习不再”伟大”,更加“平易近人”,将AI的学习与使用,推广到更多人群。学习fastai,你将:

  • 不需要很复杂的数学知识,Just high school math is sufficient(高中数学水平足以)

  • 不需要很大的数据集

  • 不需要很多昂贵的机器

为能够更好的推广学习,作者基于此专门出了一套在线课程,甚至还出了一本书(《fastai与PyTorch深度学习实践指南》,实体书有售),作者也很大方的提供在线版本(https://github.com/fastai/fastbook),允许大家不花费任何资费即可学习。不过个人还是建议有条件、有兴趣的同学可以购买实体书,支持下大佬的辛勤付出。

官网文档:fastai - Vision learnerAll the functions necessary to build Learner suitable for transfer learning in computer visionicon-default.png?t=N7T8https://docs.fast.ai/vision.learner.html#cnn_learner上面是cnn_learn的函数介绍

2、使用fastai

通过谷歌的colab来快速的上手fastai。

!pip install -Uqq fastbook
import fastbook
fastbook.setup_book()

from fastbook import *
from fastai.vision.all import *

解压数据集

url = "https://course.fast.ai/datasets"
path = untar_data(URLs.PETS)/'images'

查看图像

import cv2
import matplotlib.pyplot as plt

img_path = "/root/.fastai/data/oxford-iiit-pet/images/Abyssinian_1.jpg"
img = cv2.imread(img_path)
print(img.shape)
plt.imshow(img)
plt.show()

开始训练

def is_cat(x):
    return x[0].isupper()
dls = ImageDataLoaders.from_name_func(path,get_image_files(path),valid_pct=0.2,seed=42,
                                      label_func=is_cat,item_tfms=Resize(224))
learn = cnn_learner(dls,resnet34,metrics=error_rate)
learn.fine_tune(1)

进行预测

# 上传图像
uploader = widgets.FileUpload()
uploader

img = PILImage.create(uploader.data[0])
print(img.shape)

#进行预测并打印预测结果
is_cat,a,prob = learn.predict(img)
print(is_cat)
print(a)
print(f"{prob[1].item():.2f}")
print(prob)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值