9  Introduction to fastai

9.1 What is fastai?

As mentioned in the previous chapter, we will now look at a extremely popular deep learning framework called fastai. fastai is an open-source software library for machine learning, which provides high-level APIs for deep learning applications. It is built on top of PyTorch and is designed to be easy to use and flexible, allowing developers to quickly prototype and implement their ideas. fastai provides a wide range of pre-trained models, including state-of-the-art models for computer vision, natural language processing, and recommendation systems. Additionally, fastai offers a number of useful tools and utilities for data processing and model evaluation, making it a popular choice among researchers and practitioners alike.

The creators of fastai have also created accompanying educational resources to assist in learning deep learning through the use of their framework. Both the course and book are highly recommended.

  • Here is the link to the free course: Link
  • Here is the link to the book: Link

The creators also have a peer-review paper published explaining high-level functionality and layered approach to the fastai library- Link.

9.2 Introduction to fastai API

Fig 9.1: The layered API from fastai.

The image presented above differs from the original diagram in the fastai paper, as it represents my interpretation of using fastai in various use cases. In the original paper, the “lower level API” mentioned is similar to using raw PyTorch, so in my depiction, I consider the “Application layer” as the high-level API. This is my personal interpretation of the fastai framework and how it fits into the deep learning pipeline.

fastai offers three levels of abstraction: high-level, mid-level, and low-level APIs, each catering to different use cases and levels of customization.

  • High-level API: The high-level API in fastai provides a simplified and opinionated interface for training deep learning models. It offers easy-to-use functions for tasks such as data preprocessing, model architecture selection, and hyperparameter tuning, making it suitable for users who want a streamlined and automated approach to deep learning. The high-level API in fastai also includes high-level abstractions for common deep learning tasks, such as image classification, text classification, and object detection, allowing users to quickly build complex models with just a few lines of code. Example of creating a data loader could be done using the following syntax: {Task}DataLoaders.from_{source}, where {Task} represents the specific task you are working on, such as vision, segmentation, text, or tabular, and {source} represents the data source you are using for your task.

  • Mid-level API: The mid-level API in fastai offers a balance between customization and abstraction. It provides more control over the training process compared to the high-level API, while still offering some higher-level abstractions. With the mid-level API, users can define their own custom data loaders, specify custom architectures, and configure custom training loops, allowing for more fine-grained customization of the deep learning pipeline. This makes it suitable for users who need more flexibility and control over their models while still benefiting from some abstraction and convenience. Example of creating a data loader would involve using DataBlock API. The DataBlock API provides a flexible and powerful way to define the entire data loading pipeline, including data preprocessing, splitting, and batching, all in one place.

  • Low-level API: The low-level API in fastai gives users complete control over the deep learning pipeline. It provides direct access to PyTorch’s core functionalities, such as tensors, modules, and optimizers, allowing users to build models from scratch with full customization. The low-level API is suitable for advanced users who are already familiar with PyTorch and want to leverage fastai’s utilities for additional convenience, but still need fine-grained control over every aspect of the model training process. An example of creating a data loader with fastai involves defining our own custom Dataset class and using the fastai DataLoader class as a wrapper around it.

9.3 Conclusion

In conclusion, fastai is a widely popular open-source deep learning framework built on top of PyTorch. It provides high-level APIs for machine learning tasks, making it easy to prototype and implement ideas quickly. With its three levels of abstraction - high-level, mid-level, and low-level APIs - fastai caters to different use cases and levels of customization, from automated and streamlined approaches to fine-grained control over the deep learning pipeline. Additionally, fastai offers extensive pre-trained models, educational resources, and utilities for data processing and model evaluation, making it a popular choice among researchers and practitioners. Whether you are a beginner or an advanced user, fastai provides flexibility and convenience for training deep learning models.

With an understanding of the different levels of fastai API, the next chapter will delve into training a model using an example with the MNIST dataset, showcasing the varying levels of API abstraction in action. From high-level, automated approaches to mid-level customization, and low-level fine-grained control, we will explore how fastai empowers users with flexibility and convenience in building and training deep learning models.