FastAI in Machine Learning

FastAI is a Machine Learning library used for Deep Learning tasks. It helps by providing top-level components that can be easily used to achieve cutting edge results. In this article, I will walk you through a tutorial on FastAI in Machine Learning using Python.

Introduction to FastAI in Machine Learning

The FastAI library is created for two main goals:

  1. to be approachable
  2. rapidly productive

FastAI aims to provide high-level components to researchers who use low-level components that can be used to build new approaches. The best part about this library is that it does all of this without substantial components in ease of use, flexibility, and performance.

Also, Read – 100+ Machine Learning Projects Solved and Explained.

FastAI is built on Pytorch, NumPy, PIL, pandas, and a few other libraries. To achieve its goals, it does not aim to hide the lower levels of its foundation. Using this machine learning library, we can directly interact with the underlying PyTorch primitive models.

By using the FastAI library in Machine Learning, we can easily build and train advanced neural network models using transfer learning with very few lines of code. In the section below, I’ll show you an example of this library.

FastAI Tutorial

In this section, I’ll walk you through an example of how to use the FastAI Machine Learning Library on a very popular task within the Machine Learning community that is about classifying dogs and cats.

To use this library, you need to run these three commands below in your command prompt or terminal:

!pip install fastai
!pip install fastbook --upgrade
!pip install -Uqq fastbook

After executing the above commands we need to prepare the environment to work on this library, which we can easily do by importing the fastbook library and passing the setup_book() function:

import fastbook

Now let’s import the necessary libraries and the dataset that we need to work on in this tutorial:

from import *
path = untar_data(URLs.PETS)

In FastAI, untar_data is a very powerful convenience function to download files from a URL. We are using the PETS dataset here which includes 37 categories of pets with roughly around 200 images of each class. Now let’s determine the labels:

def is_cat(x):
  return x[0].isupper()

Now I will use the ImageDataLoader function which raps around several data loaders for the problems of computer vision:

Final Step: Making Predictions

Now let’s train the model and make predictions:

Image is of a Cat: True.
Probability image is a cat: 1.000000
dog and cat classification

I hope you liked this article on FastAI tutorial in Machine Learning. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal

Coder with the ♥️ of a Writer || Data Scientist | Solopreneur | Founder

Articles: 998

Leave a Reply