Book Image

Deep Learning with fastai Cookbook

By : Mark Ryan
Book Image

Deep Learning with fastai Cookbook

By: Mark Ryan

Overview of this book

fastai is an easy-to-use deep learning framework built on top of PyTorch that lets you rapidly create complete deep learning solutions with as few as 10 lines of code. Both predominant low-level deep learning frameworks, TensorFlow and PyTorch, require a lot of code, even for straightforward applications. In contrast, fastai handles the messy details for you and lets you focus on applying deep learning to actually solve problems. The book begins by summarizing the value of fastai and showing you how to create a simple 'hello world' deep learning application with fastai. You'll then learn how to use fastai for all four application areas that the framework explicitly supports: tabular data, text data (NLP), recommender systems, and vision data. As you advance, you'll work through a series of practical examples that illustrate how to create real-world applications of each type. Next, you'll learn how to deploy fastai models, including creating a simple web application that predicts what object is depicted in an image. The book wraps up with an overview of the advanced features of fastai. By the end of this fastai book, you'll be able to create your own deep learning applications using fastai. You'll also have learned how to use fastai to prepare raw datasets, explore datasets, train deep learning models, and deploy trained models.
Table of Contents (10 chapters)

Using callbacks to get the most out of your training cycle

So far in this book, we have kicked off the training process for a fastai model by applying fit_one_cycle or fine_tune to the learner object and have then just let the training run through the specified number of epochs. For many of the models we have trained in this book, this approach has been good enough, particularly for models where each epoch takes a long time and we only train for one or two epochs. But what about models where we want to train the model for 10 or more epochs? If we simply let the training process go to the end, we face the problem shown in the training results shown in Figure 8.30. In Figure 8.30, we see the result of training a tabular model for 10 epochs with metric set to accuracy:

Figure 8.30 – Results from a 10-epoch run training a model with tabular data

The goal of this training process is to get a model with the best accuracy. With this goal in mind, there are...