From 4f912a6ee1334f74fea84e5cd8c51110bdcd37a4 Mon Sep 17 00:00:00 2001 From: Daniel Bourke Date: Mon, 25 Jul 2022 15:44:59 +1000 Subject: [PATCH] add annotations --- 08_pytorch_paper_replicating.ipynb | 55 +++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/08_pytorch_paper_replicating.ipynb b/08_pytorch_paper_replicating.ipynb index bf7eaf6..a98f95a 100644 --- a/08_pytorch_paper_replicating.ipynb +++ b/08_pytorch_paper_replicating.ipynb @@ -17,16 +17,15 @@ "source": [ "# (WIP) 08. PyTorch Paper Replicating\n", "\n", - "TK intro... welcome to Milestone Project 2!\n", + "Welcome to Milestone Project 2: PyTorch Paper Replicating!\n", "\n", - "Want to recreate ViT paper: \"An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale\" - https://arxiv.org/abs/2010.11929 - TK will refer to this as \"ViT paper\" throughout.\n", + "In this project, we're going to be **replicating a machine learning research paper** and creating a Vision Transformer (ViT) from scratch using PyTorch. \n", "\n", - "TODO: \n", - "* TK what is ViT?\n", - "* TK - The name Transformer comes from the architecture name in the paper where it was originally introduced, [*Attention is all you need*](https://arxiv.org/abs/1706.03762). An architecture is usually considered a Transformer variant if it uses attention layers in a specific pattern. Since the Transformer architecture originally focused on text data, the goal of the ViT paper was to bring it to the vision.\n", - "* TK - The original transformer was made to work on sequences of text (1D), Vision Transformer turns images into sequences of \"patches\".\n", - "* TK - original ViT also called \"vanilla vision transformer\", understand Vanilla vision transformer, you can start to understand the many variants of the vision transformer \n", - "* TK - Transformer can be generally defined any architecture that uses a form of the attention mechanism as part of its architecture. " + "We'll then see how ViT, a state-of-the-art computer vision architecture, performs on our FoodVision Mini problem.\n", + "\n", + "\"appyling\n", + "\n", + "*For Milestone Project 2 we're going to focus on recreating the Vision Transformer (ViT) computer vision architecture and applying it to our FoodVision Mini problem to classify different images of pizza, steak and sushi.*" ] }, { @@ -44,7 +43,9 @@ "\n", "For example, let's say a new model architecture gets released that performs better than any other architecture before on various benchmarks, wouldn't it be nice to try that architecture on your own problems?\n", "\n", - "* TK image: paper replicating = research paper (language + diagrams + math) -> code (turn language, diagrams and math into usable code) / (translate a research paper into usable code)\n" + "\"paper\n", + "\n", + "*Machine learning paper replicating involves turning a machine learning paper comprised of images/diagrams, math and text into usable code and in our case, usable PyTorch code. Diagram, math equations and text from the [ViT paper](https://arxiv.org/abs/2010.11929).*\n" ] }, { @@ -124,13 +125,35 @@ "source": [ "## TK - What we're going to cover\n", "\n", - "TODO\n", + "Rather than talk about a replicating a paper, we're going to hands-on and *actually* replicate a paper.\n", "\n", - "* TK - rather than talk about replicating a paper, we're going to hands-on and *actually* replicate a paper (Vision Transformer)\n", - " * The process for replicating all papers will be slightly different but by seeing what it's like to do one, we'll get the momentum to do more. \n", - "* ViT -> FoodVision Mini\n", - "* Layers = collections of functions to manipulate data -> Architectures = collections of layers (blocks) -> All layers (and blocks) have inputs and outputs\n", - " * Replicating research papers starts by figuring out the inputs and outputs of your layers -> blocks -> model " + "The process for replicating all papers will be slightly different but by seeing what it's like to do one, we'll get the momentum to do more. \n", + "\n", + "More specifically, we're going to be replicating the machine learning research paper [*An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale*](https://arxiv.org/abs/2010.11929) (ViT paper) with PyTorch.\n", + "\n", + "The Transformer neural network architecture was originally introduced in the machine learning research paper [*Attention is all you need*](https://arxiv.org/abs/1706.03762).\n", + "\n", + "And the original Transformer architecture was designed to work on one-dimensional (1D) sequences of text.\n", + "\n", + "A **Transformer architecture** is generally considered to be any neural network that uses the [**attention mechanism**](https://en.wikipedia.org/wiki/Attention_(machine_learning)) as its primary learning layer. Similar to a how a convolutional neural network (CNN) uses convolutions as its primary learning layer.\n", + "\n", + "Like the name suggests, the Vision Transformer architecture was designed to adapt the original Transformer architecture to vision problem(s) (classification being the first and since many others have followed).\n", + "\n", + "The original Vision Transformer (ViT) has been through several iterations over the past couple of years, however, we're going to focus on replicating the original, otherwise known as the \"vanilla Vision Transformer\". Because if you can recreate the original, you can adapt to the others. \n", + "\n", + "We're going to be focusing on building the ViT architecture as per the original ViT paper and applying it to FoodVision Mini.\n", + "\n", + "TK - table of contents\n", + "\n", + "> **Note:** Despite the fact we're going to be focused on replicating the ViT paper, avoid getting too bogged down on a particular paper as newer better methods will often come along, quickly, so the skill should be to remain curious whilst building the fundamental skills of turning math and words on a page into working code.\n", + "\n", + "## Terminology\n", + "\n", + "There are going to be a fair few acronyms throughout this notebook.\n", + "\n", + "In light of this, here are some definitions:\n", + "* **ViT** - Stands for Vision Transformer (the main neural network architecture we're going to be focused on replicating). \n", + "* **ViT paper** - Short hand for the original machine learning research paper that introduced the ViT architecture, [*An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale*](https://arxiv.org/abs/2010.11929), anytime *ViT paper* is mentioned, you can be assured it is referencing this paper.\n" ] }, { @@ -164,7 +187,7 @@ "\n", "`torchinfo` will help later on to give us a visual representation of our model.\n", "\n", - "And since later on we'll be using a newer version of the `torchvision` package (as of June 2022), we'll make sure we've got the latest versions." + "And since later on we'll be using `torchvision` v0.13 package (available as of July 2022), we'll make sure we've got the latest versions." ] }, {