From a2fc0341ac0a919c3b1ffabb450cd2f05db0d00d Mon Sep 17 00:00:00 2001 From: Daniel Bourke Date: Thu, 10 Feb 2022 12:10:26 +1000 Subject: [PATCH] add images --- 00_pytorch_fundamentals.ipynb | 280 ++++++++++++++++++---------------- 1 file changed, 145 insertions(+), 135 deletions(-) diff --git a/00_pytorch_fundamentals.ipynb b/00_pytorch_fundamentals.ipynb index 5a8e8b8..f0ff3ae 100644 --- a/00_pytorch_fundamentals.ipynb +++ b/00_pytorch_fundamentals.ipynb @@ -18,23 +18,27 @@ "source": [ "# 00. PyTorch Fundamentals\n", "\n", - "## TK - What is PyTorch?\n", + "## What is PyTorch?\n", "\n", "[PyTorch](https://pytorch.org/) is an open source machine learning and deep learning framework.\n", "\n", - "## TK - What can PyTorch be used for?\n", + "## What can PyTorch be used for?\n", "\n", "PyTorch allows you to manipulate and process data and write machine learning algorithms using Python code.\n", "\n", - "## TK - Who uses PyTorch?\n", + "## Who uses PyTorch?\n", "\n", - "Many of the worlds largest technology companies such as Meta (Facebook), Tesla and Microsoft as well as artificial intelligence research companies such as OpenAI use PyTorch to power research and bring machine learning to their products.\n", + "Many of the worlds largest technology companies such as [Meta (Facebook)](https://ai.facebook.com/blog/pytorch-builds-the-future-of-ai-and-machine-learning-at-facebook/), Tesla and Microsoft as well as artificial intelligence research companies such as [OpenAI use PyTorch](https://openai.com/blog/openai-pytorch/) to power research and bring machine learning to their products.\n", "\n", - "* TK - image of who uses PyTorch\n", + "![pytorch being used across industry and research](https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/00-pytorch-being-used-across-research-and-industry.png)\n", "\n", "For example, Andrej Karpathy (head of AI at Tesla) has given several talks ([PyTorch DevCon 2019](https://youtu.be/oBklltKXtDE), [Tesla AI Day 2021](https://youtu.be/j0z4FweCy4M?t=2904)) about how Tesla use PyTorch to power their self-driving computer vision models.\n", "\n", - "## TK - Why use PyTorch?\n", + "PyTorch is also used in other industries such as argiculture to [power computer vision on tractors](https://medium.com/pytorch/ai-for-ag-production-machine-learning-for-agriculture-e8cfdb9849a1).\n", + "\n", + "And as of February 2022, PyTorch is the [most used deep learning framework on Papers With Code](https://paperswithcode.com/trends), a website for tracking machine learning research papers and the code repositories attached with them.\n", + "\n", + "## Why use PyTorch?\n", "\n", "Researchers love using PyTorch. Many of the latest machine learning research papers have [some kind of PyTorch code attached](https://paperswithcode.com/trends). \n", "\n", @@ -44,7 +48,7 @@ "\n", "And if companies such as Tesla and Meta (Facebook) use it to build models they deploy to power hundreds of applications, drive thousands of cars and deliver content to billions of people, it's clearly capable on the development front too.\n", "\n", - "## TK - What we're going to cover in this module...\n", + "## What we're going to cover in this module\n", "\n", "This course is broken down into different sections (notebooks). \n", "\n", @@ -74,7 +78,7 @@ "\n", "And if you run into trouble, you can ask a question on the [Discussions page](https://github.com/mrdbourke/pytorch-deep-learning/discussions) there too.\n", "\n", - "There's also the [PyTorch developer forums](https://discuss.pytorch.org/), a very helpful place for all things PyTorch. \n" + "There's also the [PyTorch developer forums](https://discuss.pytorch.org/), a very helpful place for all things PyTorch. " ] }, { @@ -83,9 +87,11 @@ "id": "5v3iRCRUTGeu" }, "source": [ - "## TK - Importing PyTorch\n", + "## Importing PyTorch\n", "\n", - "> **Note:** Before running any of the code in this notebook, you should have gone through the PyTorch setup steps (TK-setup steps link). However, if you're running on Google Colab, everything should work (Google Colab comes with PyTorch and other libraries installed).\n", + "> **Note:** Before running any of the code in this notebook, you should have gone through the [PyTorch setup steps](https://pytorch.org/get-started/locally/). \n", + ">\n", + "> However, **if you're running on Google Colab**, everything should work (Google Colab comes with PyTorch and other libraries installed).\n", "\n", "Let's start by importing PyTorch and checking the version we're using." ] @@ -99,7 +105,7 @@ "height": 35 }, "id": "1VxEOik46Y4i", - "outputId": "cca909a6-27cf-42f8-b248-f63c8ff84967" + "outputId": "f3141076-29bc-4600-c1c3-1586b1fe2292" }, "outputs": [ { @@ -138,7 +144,7 @@ "id": "i-33BKR16iWc" }, "source": [ - "## TK - Introduction to tensors \n", + "## Introduction to tensors \n", "\n", "Now we've got PyTorch imported, it's time to learn about tensors.\n", "\n", @@ -148,7 +154,7 @@ "\n", "For example, you could represent an image as a tensor with shape `[3, 224, 224]` which would mean `[colour_channels, height, width]`, as in the image has `3` colour channels (red, green, blue), a height of `224` pixels and a width of `224` pixels.\n", "\n", - "TK - image \n", + "![example of going from an input image to a tensor representation of the image, image gets broken down into 3 colour channels as well as numbers to represent the height and width](https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/00-tensor-shape-example-of-image.png)\n", "\n", "In tensor-speak (the language used to describe tensors), the tensor would have three dimensions, one for `colour_channels`, `height` and `width`.\n", "\n", @@ -163,7 +169,7 @@ "id": "gFF0N2TU7S7Q" }, "source": [ - "### TK - Creating tensors \n", + "### Creating tensors \n", "\n", "PyTorch loves tensors. So much so there's a whole documentation page dedicated to the [`torch.Tensor`](https://pytorch.org/docs/stable/generated/torch.tensor.html#torch.tensor) class.\n", "\n", @@ -186,7 +192,7 @@ "base_uri": "https://localhost:8080/" }, "id": "YUDgG2zk7Us5", - "outputId": "4c6c3dcf-f4db-433a-ad59-21f085d161f3" + "outputId": "0ac22bd2-16bc-4307-f312-31ae89d6c375" }, "outputs": [ { @@ -227,7 +233,7 @@ "base_uri": "https://localhost:8080/" }, "id": "lV98Yz868bav", - "outputId": "9d68c5ea-817d-47d9-c4ae-e47780680d17" + "outputId": "502a625e-ff3c-4fc4-b523-f7634ea82128" }, "outputs": [ { @@ -266,7 +272,7 @@ "base_uri": "https://localhost:8080/" }, "id": "-k4cyKumPfbE", - "outputId": "03f790d4-8bde-4303-c6c4-dbe285921a1c" + "outputId": "1f6a7916-0c7c-403f-8ebd-875454a94470" }, "outputs": [ { @@ -308,7 +314,7 @@ "base_uri": "https://localhost:8080/" }, "id": "-IZF6ASs8QH9", - "outputId": "0561351f-e9ac-4515-9e5d-e47e3d63f6ad" + "outputId": "e556ed2a-e58a-440f-b103-0f06c91bc75c" }, "outputs": [ { @@ -347,7 +353,7 @@ "base_uri": "https://localhost:8080/" }, "id": "03hm3VVv8kr4", - "outputId": "2a39ed38-42ea-47fd-da63-dd0aeecb1f33" + "outputId": "2035bb26-0189-4b28-fa02-34220d44677f" }, "outputs": [ { @@ -390,7 +396,7 @@ "execution_count": 7, "metadata": { "id": "6zREV1bDTGe2", - "outputId": "6866659c-675e-4f67-eb9b-ad3117e78299", + "outputId": "2a6e7ceb-7eb2-422b-b006-2c6e4825272f", "colab": { "base_uri": "https://localhost:8080/" } @@ -431,7 +437,7 @@ "base_uri": "https://localhost:8080/" }, "id": "D5iNwCYL8QO9", - "outputId": "d5f640d9-2e9e-4409-c199-2638673268b1" + "outputId": "88fc63a7-4130-4c7a-a574-c61e85d2e99e" }, "outputs": [ { @@ -471,7 +477,7 @@ "base_uri": "https://localhost:8080/" }, "id": "8LREUbeb8r8j", - "outputId": "e2332d41-6860-44f0-cdf6-005358421269" + "outputId": "636246b0-b109-472a-c6d5-8601a9e08654" }, "outputs": [ { @@ -506,7 +512,7 @@ "execution_count": 10, "metadata": { "id": "_TL26I31TGe3", - "outputId": "21de8a5d-425b-46e1-faed-124bb432cad8", + "outputId": "f05ec0b6-0bc1-4381-9474-56cbe6c67139", "colab": { "base_uri": "https://localhost:8080/" } @@ -546,7 +552,7 @@ "base_uri": "https://localhost:8080/" }, "id": "wEMDQr188QWW", - "outputId": "0980fb64-ec44-4b15-93c8-ee802cbf63cf" + "outputId": "4230e6bd-1844-4210-eea8-245bb8b8b265" }, "outputs": [ { @@ -595,7 +601,7 @@ "base_uri": "https://localhost:8080/" }, "id": "8dhuEsjS8QcT", - "outputId": "9db51295-0a79-48c5-ccef-3ddad5a82754" + "outputId": "7a45df1b-fc32-4cc5-e330-527c6ef7ba5d" }, "outputs": [ { @@ -628,7 +634,7 @@ "execution_count": 13, "metadata": { "id": "hdVv4iNRTGe5", - "outputId": "e9e50345-3a5b-4941-9dc2-f4eab3b2056b", + "outputId": "d8ac706c-020b-4926-b145-d44e41f35e90", "colab": { "base_uri": "https://localhost:8080/" } @@ -662,7 +668,7 @@ "\n", "That means there's 1 dimension of 3 by 3.\n", "\n", - "TK - image: 00_pytorch_fundamentals_tensor_shape (keynote 00)\n", + "![example of different tensor dimensions](https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/00-pytorch-different-tensor-dimensions.png)\n", "\n", "> **Note:** You might've noticed me using lowercase letters for `scalar` and `vector` and uppercase letters for `MATRIX` and `TENSOR`. This was on purpose. In practice, you'll often see scalars and vectors denoted as lowercase letters such as `y` or `a`. And matrices and tensors denoted as uppercase letters such as `X` or `W`.\n", ">\n", @@ -677,7 +683,7 @@ "| **matrix** | a 2-dimensional array of numbers | 2 | Upper (`Q`) |\n", "| **tensor** | an n-dimensional array of numbers | can be any number, a 0-dimension tensor is a scalar, a 1-dimension tensor is a vector | Upper (`X`) | \n", "\n", - "TK - image: scalar, vector, matrix, tensor" + "![scalar vector matrix tensor and what they look like](https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/00-scalar-vector-matrix-tensor.png)" ] }, { @@ -717,16 +723,16 @@ "base_uri": "https://localhost:8080/" }, "id": "EOJEtDx--GnK", - "outputId": "ef632a8e-a93c-415c-a008-6e664ba05e96" + "outputId": "2680d44b-e31c-4ab1-d5b1-c0cd76706a0d" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ - "(tensor([[0.9224, 0.0830, 0.2516, 0.5563],\n", - " [0.2857, 0.8119, 0.5524, 0.4394],\n", - " [0.4216, 0.2363, 0.1855, 0.1223]]), torch.float32)" + "(tensor([[0.4090, 0.2527, 0.8699, 0.2002],\n", + " [0.8421, 0.1428, 0.1431, 0.0111],\n", + " [0.2281, 0.0345, 0.6734, 0.3866]]), torch.float32)" ] }, "metadata": {}, @@ -762,7 +768,7 @@ "base_uri": "https://localhost:8080/" }, "id": "xMF_NUp3Ym__", - "outputId": "61721fcf-6278-4682-f490-3bd44e45e00f" + "outputId": "8346b853-0b1e-481a-d9ee-a410ee21bab0" }, "execution_count": 15, "outputs": [ @@ -803,7 +809,7 @@ "base_uri": "https://localhost:8080/" }, "id": "oCzhd0hl9Vp6", - "outputId": "c8fa9ea0-cc61-47ed-81b1-591b74b96fd8" + "outputId": "9c8ec87f-d8c9-4751-a13e-6a5e986daaa9" }, "outputs": [ { @@ -839,7 +845,7 @@ "execution_count": 17, "metadata": { "id": "HRe6sSXiTGe6", - "outputId": "ec31a29b-24e3-429d-a771-4cfe96acb9cf", + "outputId": "3f45b0b8-7f65-423d-c664-f5b5f7866fd2", "colab": { "base_uri": "https://localhost:8080/" } @@ -892,7 +898,7 @@ "base_uri": "https://localhost:8080/" }, "id": "1IqUs81d9W4W", - "outputId": "b530281c-d571-4bb7-ebe5-67df0d6c7bf3" + "outputId": "2a6f0c08-052e-4b36-b4eb-6a537239026f" }, "outputs": [ { @@ -944,7 +950,7 @@ "base_uri": "https://localhost:8080/" }, "id": "ZvXwUut5BhHq", - "outputId": "cb8e4bbd-dc7f-44d2-ed68-a489ea02ecd8" + "outputId": "096b2f8e-8c21-4ace-97b9-c36b92b2fe77" }, "outputs": [ { @@ -1017,7 +1023,7 @@ "base_uri": "https://localhost:8080/" }, "id": "q3MoGnpw9XaF", - "outputId": "c35afe7f-ab4f-4959-fe39-6e1ae8484135" + "outputId": "61070939-8c52-4ac6-bed7-e64b3ce24615" }, "outputs": [ { @@ -1066,7 +1072,7 @@ "base_uri": "https://localhost:8080/" }, "id": "PKSuajld_09s", - "outputId": "b7e19c85-84e8-4685-d413-32389a75f8cb" + "outputId": "cbac29d9-3371-4fe1-b47c-3af4623b5fbf" }, "outputs": [ { @@ -1113,16 +1119,16 @@ "base_uri": "https://localhost:8080/" }, "id": "hd_X4D0j7Umq", - "outputId": "2dd76965-f13e-4ab6-ab47-ff65a85d0a45" + "outputId": "86045713-ab36-4c8e-840c-e788f80c5266" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "tensor([[0.4356, 0.7493, 0.5617, 0.5367],\n", - " [0.3113, 0.0558, 0.6181, 0.5538],\n", - " [0.3466, 0.4585, 0.2017, 0.2721]])\n", + "tensor([[0.7799, 0.8140, 0.0893, 0.2062],\n", + " [0.7525, 0.3845, 0.8207, 0.4587],\n", + " [0.9277, 0.8166, 0.9052, 0.0953]])\n", "Shape of tensor: torch.Size([3, 4])\n", "Datatype of tensor: torch.float32\n", "Device tensor is stored on: cpu\n" @@ -1156,7 +1162,7 @@ "id": "BdiWvoAi7UjL" }, "source": [ - "## TK - Manipulating tensors (tensor operations)\n", + "## Manipulating tensors (tensor operations)\n", "\n", "In deep learning, data (images, text, video, audio, protein structures, etc) gets represented as tensors.\n", "\n", @@ -1195,7 +1201,7 @@ "base_uri": "https://localhost:8080/" }, "id": "X71WpQoPD7a4", - "outputId": "4bdffc69-5034-4a09-d897-0e740ac98547" + "outputId": "ab30f13e-fc67-4ae4-c5ce-1006410dba07" }, "outputs": [ { @@ -1223,7 +1229,7 @@ "base_uri": "https://localhost:8080/" }, "id": "Sp4TlTWWEFeO", - "outputId": "9873b4c6-8de0-4a6d-a883-58862c2c1671" + "outputId": "ce7d2296-881f-4eb3-802e-fd12bc25d6ea" }, "outputs": [ { @@ -1259,7 +1265,7 @@ "base_uri": "https://localhost:8080/" }, "id": "XuB1UjCIEJIA", - "outputId": "7ac146d8-4054-475a-f77b-4abd4d5e4ae2" + "outputId": "57cae862-c145-4681-d74b-fe6d77f2125a" }, "outputs": [ { @@ -1295,7 +1301,7 @@ "base_uri": "https://localhost:8080/" }, "id": "U4iWKoLsENry", - "outputId": "a3f38221-48f9-4f8f-8e2e-219192219c61" + "outputId": "14d6771d-eb57-4b11-88a7-b1bb308ddc6e" }, "outputs": [ { @@ -1323,7 +1329,7 @@ "base_uri": "https://localhost:8080/" }, "id": "tFgZY-PaFNXa", - "outputId": "989925ed-8e9e-4761-c6f3-4a0c78b32a26" + "outputId": "3536ea54-a056-444c-cd5d-6d438ddda965" }, "outputs": [ { @@ -1360,7 +1366,7 @@ "base_uri": "https://localhost:8080/" }, "id": "uVysdk3kFWbY", - "outputId": "c20ef9f0-4a07-49cb-f60c-62858c08b0b6" + "outputId": "3a5bf687-cf24-4224-9e76-975f84638ca8" }, "outputs": [ { @@ -1387,7 +1393,7 @@ "base_uri": "https://localhost:8080/" }, "id": "IxuPJIpNFbqO", - "outputId": "0e808055-072a-4c5c-e363-22bc50f61992" + "outputId": "f04cafd9-eaea-4254-df1a-5ab3b524d74e" }, "outputs": [ { @@ -1423,7 +1429,7 @@ "base_uri": "https://localhost:8080/" }, "id": "S5v3RkR0F2Jq", - "outputId": "249bc05e-45ca-4fa5-ba8e-08f25022b951" + "outputId": "0137caab-5ea1-4d95-f4c5-a0baa0fd652d" }, "outputs": [ { @@ -1478,7 +1484,7 @@ "base_uri": "https://localhost:8080/" }, "id": "ZE7loucmDlEM", - "outputId": "c3787443-c181-4ecf-f008-033b3ff15a71" + "outputId": "44032bf9-c1f7-42fc-c842-dbe7a5c1221a" }, "outputs": [ { @@ -1525,7 +1531,7 @@ "base_uri": "https://localhost:8080/" }, "id": "i42gkUeHvI_1", - "outputId": "82409791-ac33-4f25-f1f7-b7dcc56ca078" + "outputId": "18a630ce-bb56-4c40-81b4-9fdbb2ed7a4f" }, "execution_count": 32, "outputs": [ @@ -1549,7 +1555,7 @@ "base_uri": "https://localhost:8080/" }, "id": "PvCBiiTTDk8y", - "outputId": "e31865d6-0547-46bf-d5a0-63d95eb5caf1" + "outputId": "cf623247-8f1b-49f1-e788-16da3ed1e59c" }, "outputs": [ { @@ -1576,7 +1582,7 @@ "base_uri": "https://localhost:8080/" }, "id": "m4E_pROBDk2r", - "outputId": "5a92e958-ddb9-438b-8323-2c4ef4f9f674" + "outputId": "a09af00f-277b-479e-b0a2-ad6311ee5413" }, "outputs": [ { @@ -1614,15 +1620,15 @@ "base_uri": "https://localhost:8080/" }, "id": "6qMSaLOoJscL", - "outputId": "97179002-d9ce-4379-ab02-b074a2ac3861" + "outputId": "8bcad8a2-c900-4966-e13c-ff2cc02b9207" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "CPU times: user 161 µs, sys: 56 µs, total: 217 µs\n", - "Wall time: 224 µs\n" + "CPU times: user 146 µs, sys: 38 µs, total: 184 µs\n", + "Wall time: 227 µs\n" ] } ], @@ -1647,7 +1653,7 @@ "base_uri": "https://localhost:8080/" }, "id": "vVWiKB0KwH74", - "outputId": "9436c434-eac4-45c2-ad9f-84e14fb81117" + "outputId": "fce58235-5c09-49ec-f34b-a90e5640281e" }, "execution_count": 36, "outputs": [ @@ -1655,8 +1661,8 @@ "output_type": "stream", "name": "stdout", "text": [ - "CPU times: user 43 µs, sys: 15 µs, total: 58 µs\n", - "Wall time: 62 µs\n" + "CPU times: user 27 µs, sys: 7 µs, total: 34 µs\n", + "Wall time: 36.7 µs\n" ] }, { @@ -1688,10 +1694,10 @@ "metadata": { "colab": { "base_uri": "https://localhost:8080/", - "height": 201 + "height": 204 }, "id": "rN5RcoD4Jo6y", - "outputId": "34408b14-3bf9-412e-d49d-40bbc39a2563" + "outputId": "20f6c65b-86f4-4903-d253-f6cbf0583934" }, "outputs": [ { @@ -1748,7 +1754,7 @@ "base_uri": "https://localhost:8080/" }, "id": "lUqgaANiy1wq", - "outputId": "bf1f3031-b1c0-487f-eb24-bc1310a19b30" + "outputId": "e48bbf0c-8008-434e-d372-caa658b2f36b" }, "execution_count": 38, "outputs": [ @@ -1778,7 +1784,7 @@ "base_uri": "https://localhost:8080/" }, "id": "DveqxO7iy_Fi", - "outputId": "00c3e98f-bd28-4071-8215-da93307410f7" + "outputId": "1bd2e85b-ea4d-4948-c408-8eb46ef3534c" }, "execution_count": 39, "outputs": [ @@ -1803,7 +1809,7 @@ "base_uri": "https://localhost:8080/" }, "id": "35rEIu-NKtVE", - "outputId": "dc45f1ab-cc2a-4050-b56d-86502bf42410" + "outputId": "0b32c7f1-556e-45d4-de22-388419e93dc2" }, "outputs": [ { @@ -1851,7 +1857,7 @@ "execution_count": 41, "metadata": { "id": "x3rJvW_TTGe_", - "outputId": "498f7f7c-3689-4f82-bc4c-c3ad482b2585", + "outputId": "2c501972-20bf-4a83-ad4a-b5f1b2424097", "colab": { "base_uri": "https://localhost:8080/" } @@ -1900,8 +1906,9 @@ "\n", "The [`torch.nn.Linear()`](https://pytorch.org/docs/1.9.1/generated/torch.nn.Linear.html) module (we'll see this in action later on), also known as a feed-forward layer or fully connected layer, implements a matrix multiplication between an input `x` and a weights matrix `A`.\n", "\n", - "* TK - image in keynote of y = x•A^T + b - see here: https://pytorch.org/docs/1.9.1/generated/torch.nn.Linear.html, also: https://pytorch.org/docs/stable/generated/torch.nn.functional.linear.html#torch.nn.functional.linear - make sure to include the dot product \n", - "* This is a linear function (y = mx+b), and can be used to draw a straight line!\n", + "$$\n", + "y = x\\cdot{A^T} + b\n", + "$$\n", "\n", "Where:\n", "* `x` is the input to the layer (deep learning is a stack of layers like `torch.nn.Linear()` and others on top of each other).\n", @@ -1910,6 +1917,8 @@ "* `b` is the bias term used to slightly offset the weights and inputs.\n", "* `y` is the output (a manipulation of the input in the hopes to discover patterns in it).\n", "\n", + "This is a linear function (you may have seen something like $y = mx+b$ in high school or elsewhere), and can be used to draw a straight line!\n", + "\n", "Let's play around with a linear layer.\n", "\n", "Try changing the values of `in_features` and `out_features` below and see what happens.\n", @@ -1928,7 +1937,7 @@ "base_uri": "https://localhost:8080/" }, "id": "mC_MjKW1LX7T", - "outputId": "ef82bec2-e9e2-42ea-f8a4-9962ca012853" + "outputId": "768f75d2-c978-4df3-e18a-4684d46bdfa9" }, "outputs": [ { @@ -2009,7 +2018,7 @@ "base_uri": "https://localhost:8080/" }, "id": "jrFQbe5fP1Rk", - "outputId": "a1bdc960-dba5-4589-d34e-73237d131915" + "outputId": "034013c1-b384-4a0d-edf8-295ed3a456f1" }, "outputs": [ { @@ -2046,7 +2055,7 @@ "base_uri": "https://localhost:8080/" }, "id": "e5wSP9YKP3Lb", - "outputId": "750e2332-606e-4754-e22a-fcce98fcf931" + "outputId": "3aa238c7-646f-434f-a55c-292aabef7227" }, "outputs": [ { @@ -2087,7 +2096,7 @@ "base_uri": "https://localhost:8080/" }, "id": "0Cr23Y9uP3HO", - "outputId": "d91f2a26-3336-446e-ee32-3bbe2286bf3e" + "outputId": "9c86d805-eef2-465c-e2c8-2bccd515e6d5" }, "outputs": [ { @@ -2126,7 +2135,7 @@ "base_uri": "https://localhost:8080/" }, "id": "FzNBl9JSGlHi", - "outputId": "0b50f915-735c-41c7-e870-95242f53349c" + "outputId": "01e0740e-c34f-469b-9c8f-9e6e5f0363af" }, "outputs": [ { @@ -2155,7 +2164,7 @@ "id": "QBu33WihOXBk" }, "source": [ - "### TK - Change tensor datatype\n", + "### Change tensor datatype\n", "\n", "As mentioned, a common issue with deep learning operations is having your tensors in different datatypes.\n", "\n", @@ -2176,7 +2185,7 @@ "base_uri": "https://localhost:8080/" }, "id": "rY2FEsCAOaLu", - "outputId": "ffc4fea0-862f-4798-d52c-6b332c9f3d22" + "outputId": "507f1ade-7c7a-4172-fa48-60c9ac4831c0" }, "outputs": [ { @@ -2214,7 +2223,7 @@ "base_uri": "https://localhost:8080/" }, "id": "Cac8gRYjOeab", - "outputId": "24875651-4ea0-40f8-c6c1-aa0a8d16a994" + "outputId": "96e5ce12-bc29-4a2b-f81c-bfc89ea2d075" }, "outputs": [ { @@ -2251,7 +2260,7 @@ "base_uri": "https://localhost:8080/" }, "id": "8Yqovld2Oj6s", - "outputId": "57620d25-2624-436d-80ab-ea513e7de5d0" + "outputId": "667da17f-e38f-404a-bd2d-63683e45c99a" }, "outputs": [ { @@ -2288,7 +2297,7 @@ "id": "7CkCtAYmGsHY" }, "source": [ - "### TK - Reshaping, stacking, squeezing and unsqueezing\n", + "### Reshaping, stacking, squeezing and unsqueezing\n", "\n", "Often times you'll want to reshape or change the dimensions of your tensors without actually changing the values inside them.\n", "\n", @@ -2320,7 +2329,7 @@ "base_uri": "https://localhost:8080/" }, "id": "EYjRTLOzG4Ev", - "outputId": "6624988a-a681-4d8c-d4ca-7898753b7e16" + "outputId": "f7f2719c-15ce-406b-dc8f-4477046cd5d9" }, "outputs": [ { @@ -2358,7 +2367,7 @@ "base_uri": "https://localhost:8080/" }, "id": "US4WjpQ3SG-8", - "outputId": "fbf60ab4-7cb0-4e7b-812d-d093563a3925" + "outputId": "c519d59e-85f1-4a10-eaaa-acb487028e3a" }, "outputs": [ { @@ -2392,7 +2401,7 @@ "execution_count": 52, "metadata": { "id": "WDN2BNe5TGfB", - "outputId": "2ae3ce52-fc51-433e-cc10-f5023fbeab56", + "outputId": "3df1b0d6-2548-4ecc-ca25-0c4e28a6e536", "colab": { "base_uri": "https://localhost:8080/" } @@ -2432,7 +2441,7 @@ "execution_count": 53, "metadata": { "id": "2DxURVvXTGfC", - "outputId": "73f89a20-cfea-4d17-fd1d-f6495bf2f8ae", + "outputId": "668d194d-dd0a-4db1-da00-9c3fd8849186", "colab": { "base_uri": "https://localhost:8080/" } @@ -2472,7 +2481,7 @@ "base_uri": "https://localhost:8080/" }, "id": "pX5Adf3ORiTK", - "outputId": "18486baa-4d18-448c-bf33-c176bacdc6e9" + "outputId": "703e8568-61df-4ebd-f4d3-a6366dc265c0" }, "outputs": [ { @@ -2514,7 +2523,7 @@ "base_uri": "https://localhost:8080/" }, "id": "w2Y2HEoDRxJZ", - "outputId": "01ec18a1-d2d1-41a4-f732-e9fb911ad20e" + "outputId": "dd0645a6-1cdd-46bc-a3a2-433d9cd09336" }, "outputs": [ { @@ -2556,7 +2565,7 @@ "base_uri": "https://localhost:8080/" }, "id": "CUC-DEEwSYv7", - "outputId": "df20f190-8aaa-4e94-bcb1-56f219e16bff" + "outputId": "da60e019-3ea6-42f8-8e47-ba037ead737f" }, "outputs": [ { @@ -2595,7 +2604,7 @@ "execution_count": 57, "metadata": { "id": "fCRGCX8DTGfC", - "outputId": "faf0bee6-6644-48ea-e0a2-81e0a386068f", + "outputId": "6853328b-a1cf-4470-f366-106a231a189c", "colab": { "base_uri": "https://localhost:8080/" } @@ -2636,7 +2645,7 @@ "id": "nEPqVL7fTGfC" }, "source": [ - "## TK - Indexing (selecting data from tensors)\n", + "## Indexing (selecting data from tensors)\n", "\n", "Sometimes you'll want to select specific data from tensors (for example, only the first column or second row).\n", "\n", @@ -2653,7 +2662,7 @@ "colab": { "base_uri": "https://localhost:8080/" }, - "outputId": "a13ebb96-81d6-4a74-e768-ad28f9db97c6" + "outputId": "05a72c08-5f8c-433a-cd31-46065686f825" }, "outputs": [ { @@ -2690,7 +2699,7 @@ "execution_count": 59, "metadata": { "id": "zv_Z3IAzTGfD", - "outputId": "db42a881-e5ef-4121-e969-2d06fd009743", + "outputId": "cf6c0936-7600-4af4-9b6f-f6b8ac9b4c05", "colab": { "base_uri": "https://localhost:8080/" } @@ -2730,7 +2739,7 @@ "execution_count": 60, "metadata": { "id": "gCT09pqeTGfD", - "outputId": "035f3c87-1fc5-4d32-9783-2bd1e64471f2", + "outputId": "a91f9b73-f8f0-476a-9c69-fcd03b042f6b", "colab": { "base_uri": "https://localhost:8080/" } @@ -2757,7 +2766,7 @@ "execution_count": 61, "metadata": { "id": "dwDx_gMsTGfD", - "outputId": "84c82056-baa9-4971-a8c3-a0dddbc2bf26", + "outputId": "8165cfd9-a88d-4212-8c45-1eb84ef5be83", "colab": { "base_uri": "https://localhost:8080/" } @@ -2784,7 +2793,7 @@ "execution_count": 62, "metadata": { "id": "xiw3_1E3TGfD", - "outputId": "2a168b32-ea2d-4161-95b2-4b042e12195f", + "outputId": "12fa4749-cf52-4e88-c2c0-44d26aeb633c", "colab": { "base_uri": "https://localhost:8080/" } @@ -2811,7 +2820,7 @@ "execution_count": 63, "metadata": { "id": "XFVEgrKhTGfD", - "outputId": "94bf691b-1036-40e3-b96d-4bdd59a98e64", + "outputId": "69eadeb9-11b3-4b48-cb95-0b3305c1274c", "colab": { "base_uri": "https://localhost:8080/" } @@ -2848,9 +2857,9 @@ "id": "h8ZaW0Bq7rCm" }, "source": [ - "## TK - PyTorch tensors & NumPy\n", + "## PyTorch tensors & NumPy\n", "\n", - "Since NumPy is a very popular Python numerical computing library, PyTorch has functionality to interact with it nicely. \n", + "Since NumPy is a popular Python numerical computing library, PyTorch has functionality to interact with it nicely. \n", "\n", "The two main methods you'll want to use for NumPy to PyTorch (and back again) are: \n", "* [`torch.from_numpy(ndarray)`](https://pytorch.org/docs/stable/generated/torch.from_numpy.html) - NumPy array -> PyTorch tensor. \n", @@ -2867,7 +2876,7 @@ "base_uri": "https://localhost:8080/" }, "id": "yDrDCnvY7rKS", - "outputId": "dbe9c441-6be2-4f26-a7f5-e61de75657b4" + "outputId": "86155a63-01f9-4372-e889-61a65ebf0fb1" }, "outputs": [ { @@ -2914,7 +2923,7 @@ "base_uri": "https://localhost:8080/" }, "id": "ovwl7VCREv8L", - "outputId": "7e3e386e-a820-4fea-fcf1-bf83fd1f7cee" + "outputId": "efd21eb9-0010-436a-dc29-f851e3d7d77a" }, "outputs": [ { @@ -2952,7 +2961,7 @@ "base_uri": "https://localhost:8080/" }, "id": "xw_7ZyVaTKxQ", - "outputId": "81a8de67-3b43-454a-8eba-82108fbf456b" + "outputId": "54d6f347-d3f6-44df-9155-83d980c31780" }, "outputs": [ { @@ -2991,7 +3000,7 @@ "base_uri": "https://localhost:8080/" }, "id": "mMp6ZSkET4_Y", - "outputId": "25854919-c9d9-4f5e-c62e-f8a0dff58f3f" + "outputId": "100678a4-c220-4a44-e4a5-0542359cb9de" }, "outputs": [ { @@ -3018,7 +3027,7 @@ "id": "7gU3ubCrUkI-" }, "source": [ - "## TK - Reproducibility (trying to take the random out of random)\n", + "## Reproducibility (trying to take the random out of random)\n", "\n", "As you learn more about neural networks and machine learning, you'll start to discover how much randomness plays a part.\n", "\n", @@ -3058,7 +3067,7 @@ "execution_count": 68, "metadata": { "id": "eSwxnwEbTGfF", - "outputId": "59f07f04-958e-42b0-d250-d4c32c9ad5f9", + "outputId": "73b34154-734f-496f-9b55-b6aaa137e854", "colab": { "base_uri": "https://localhost:8080/" } @@ -3129,7 +3138,7 @@ "execution_count": 69, "metadata": { "id": "sB6d1GfYTGfF", - "outputId": "fce996f8-1734-4461-b07c-0057c4b7ed01", + "outputId": "4d11d38e-4406-4aff-9a81-cf13aa89ee5f", "colab": { "base_uri": "https://localhost:8080/" } @@ -3206,7 +3215,7 @@ "id": "hxIIM7t27rQ-" }, "source": [ - "## TK - Running tensors on GPUs (and making faster computations)\n", + "## Running tensors on GPUs (and making faster computations)\n", "\n", "Deep learning algorithms require a lot of numerical operations.\n", "\n", @@ -3220,7 +3229,7 @@ "\n", "There are a few ways to first get access to a GPU and secondly get PyTorch to use the GPU.\n", "\n", - "> **Note:** When I reference \"GPU\" throughout this course, I'm referencing a [Nvidia GPU with CUDA](https://developer.nvidia.com/cuda-gpus) enabled (CUDA helps speed up computations) unless otherwise specified.\n", + "> **Note:** When I reference \"GPU\" throughout this course, I'm referencing a [Nvidia GPU with CUDA](https://developer.nvidia.com/cuda-gpus) enabled (CUDA is a computing platform and API that helps allow GPUs be used for general purpose computing & not just graphics) unless otherwise specified.\n", "\n" ] }, @@ -3261,24 +3270,24 @@ "base_uri": "https://localhost:8080/" }, "id": "vEMcO-9zYc-w", - "outputId": "483b133a-d63a-495d-c35c-ece122ed4122" + "outputId": "77405db7-3494-4add-cfc7-8415e52a0412" }, - "execution_count": 1, + "execution_count": 70, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "Wed Jan 19 22:09:08 2022 \n", + "Thu Feb 10 02:09:18 2022 \n", "+-----------------------------------------------------------------------------+\n", - "| NVIDIA-SMI 495.46 Driver Version: 460.32.03 CUDA Version: 11.2 |\n", + "| NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 |\n", "|-------------------------------+----------------------+----------------------+\n", "| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n", "| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n", "| | | MIG M. |\n", "|===============================+======================+======================|\n", "| 0 Tesla P100-PCIE... Off | 00000000:00:04.0 Off | 0 |\n", - "| N/A 35C P0 27W / 250W | 0MiB / 16280MiB | 0% Default |\n", + "| N/A 36C P0 28W / 250W | 0MiB / 16280MiB | 0% Default |\n", "| | | N/A |\n", "+-------------------------------+----------------------+----------------------+\n", " \n", @@ -3354,13 +3363,13 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 71, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "OweDLgwjEvZ2", - "outputId": "0aec80bc-e002-4399-a322-a1a621e35ceb" + "outputId": "3a278a24-3ec3-4b1f-8f96-298086fa6ea6" }, "outputs": [ { @@ -3371,7 +3380,7 @@ ] }, "metadata": {}, - "execution_count": 2 + "execution_count": 71 } ], "source": [ @@ -3397,10 +3406,10 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 72, "metadata": { "id": "j92HBCKB7rYa", - "outputId": "664b5ecf-e7b9-4875-83a9-dfdffe6c4cb2", + "outputId": "8cca1643-645c-4b67-f1f5-37066f6b9549", "colab": { "base_uri": "https://localhost:8080/", "height": 35 @@ -3418,7 +3427,7 @@ ] }, "metadata": {}, - "execution_count": 3 + "execution_count": 72 } ], "source": [ @@ -3444,10 +3453,10 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 73, "metadata": { "id": "MArsn0DFTGfG", - "outputId": "51e9a73a-7049-4f78-ff43-27c73951cfae", + "outputId": "de717df5-bb67-4900-805e-a6f00ad0b409", "colab": { "base_uri": "https://localhost:8080/" } @@ -3461,7 +3470,7 @@ ] }, "metadata": {}, - "execution_count": 4 + "execution_count": 73 } ], "source": [ @@ -3501,10 +3510,10 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 74, "metadata": { "id": "FhI3srFXEHfP", - "outputId": "3a33a9ec-dcf8-404c-e7ff-4612d8918a46", + "outputId": "2f4f6435-fdc4-4e99-e87c-9421c2100f36", "colab": { "base_uri": "https://localhost:8080/" } @@ -3525,7 +3534,7 @@ ] }, "metadata": {}, - "execution_count": 5 + "execution_count": 74 } ], "source": [ @@ -3574,13 +3583,13 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 75, "metadata": { "id": "3ChSLJgPTGfG", - "outputId": "a72bb2f0-dfee-4dd3-9e1c-a124c0fa9d1d", + "outputId": "32e92f62-db28-4dc7-ce93-c2ab33229252", "colab": { "base_uri": "https://localhost:8080/", - "height": 201 + "height": 186 } }, "outputs": [ @@ -3591,7 +3600,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# If tensor is on GPU, can't transform it to NumPy (this will error)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtensor_on_gpu\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# If tensor is on GPU, can't transform it to NumPy (this will error)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mtensor_on_gpu\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mTypeError\u001b[0m: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first." ] } @@ -3614,10 +3623,10 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 76, "metadata": { "id": "gN15s-NdTGfG", - "outputId": "40ff02c9-a279-4b8c-b0f9-1673723ddcf9", + "outputId": "9fffb6f2-c200-4f9c-d987-d9ab5d9cba49", "colab": { "base_uri": "https://localhost:8080/" } @@ -3631,7 +3640,7 @@ ] }, "metadata": {}, - "execution_count": 15 + "execution_count": 76 } ], "source": [ @@ -3651,10 +3660,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 77, "metadata": { "id": "S5u83PCRTGfH", - "outputId": "5824b734-e258-46be-c8d8-592c2629b09f", + "outputId": "4cb931e2-7c8d-49b9-a7de-db3d3c6589b5", "colab": { "base_uri": "https://localhost:8080/" } @@ -3668,7 +3677,7 @@ ] }, "metadata": {}, - "execution_count": 8 + "execution_count": 77 } ], "source": [ @@ -3681,7 +3690,7 @@ "id": "xlmBpnuPTGfH" }, "source": [ - "## TK - Exercises\n", + "## Exercises\n", "\n", "1. Documentation reading - A big part of deep learning (and learning to code in general) is getting familiar with the documentation of a certain framework you're using. We'll be using the PyTorch documentation a lot throughout the rest of this course. So I'd recommend spending 10-minutes reading the following (it's okay if you don't get some things for now, the focus is not yet full understanding, it's awareness):\n", " * The documentation on [`torch.Tensor`](https://pytorch.org/docs/stable/tensors.html#torch-tensor).\n", @@ -3723,7 +3732,7 @@ " 0.8513]) torch.Size([10])\n", "```\n", "\n", - "> **Resource:** See the [exercises notebooks templates](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/extras/exercises) and [solutions](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/extras/solutions) on the course GitHub.\n", + "> **Resource:** To complete these exercises, see the [exercises notebooks templates](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/extras/exercises) and potential [solutions](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/extras/solutions) on the course GitHub.\n", "\n", "## Extra-curriculum\n", "\n", @@ -3737,6 +3746,7 @@ "collapsed_sections": [], "name": "00_pytorch_fundamentals.ipynb", "provenance": [], + "toc_visible": true, "include_colab_link": true }, "interpreter": {