|
166 | 166 | "source": [ |
167 | 167 | "## 1. Get data\n", |
168 | 168 | "\n", |
169 | | - "First thing's first we need some data.\n", |
| 169 | + "First things first we need some data.\n", |
170 | 170 | "\n", |
171 | 171 | "And like any good cooking show, some data has already been prepared for us.\n", |
172 | 172 | "\n", |
|
270 | 270 | "\n", |
271 | 271 | "In our case, we have images of pizza, steak and sushi in standard image classification format.\n", |
272 | 272 | "\n", |
273 | | - "Image classification format contains separate classes of images in seperate directories titled with a particular class name.\n", |
| 273 | + "Image classification format contains separate classes of images in separate directories titled with a particular class name.\n", |
274 | 274 | "\n", |
275 | 275 | "For example, all images of `pizza` are contained in the `pizza/` directory.\n", |
276 | 276 | "\n", |
|
973 | 973 | "\n", |
974 | 974 | "We'll do so using [`torch.utils.data.DataLoader`](https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader).\n", |
975 | 975 | "\n", |
976 | | - "Turning our `Dataset`'s into `DataLoader`'s makes them iterable so a model can go through learn the relationships between samples and targets (features and labels).\n", |
| 976 | + "Turning our `Dataset`'s into `DataLoader`'s makes them iterable so a model can go through and learn the relationships between samples and targets (features and labels).\n", |
977 | 977 | "\n", |
978 | 978 | "To keep things simple, we'll use a `batch_size=1` and `num_workers=1`.\n", |
979 | 979 | "\n", |
|
1759 | 1759 | "source": [ |
1760 | 1760 | "They sure do!\n", |
1761 | 1761 | "\n", |
1762 | | - "Let's now take a lot at some other forms of data transforms." |
| 1762 | + "Let's now take a look at some other forms of data transforms." |
1763 | 1763 | ] |
1764 | 1764 | }, |
1765 | 1765 | { |
|
1778 | 1778 | "\n", |
1779 | 1779 | "Or cropping it or randomly erasing a portion or randomly rotating them.\n", |
1780 | 1780 | "\n", |
1781 | | - "Doing this kinds of transforms is often referred to as **data augmentation**.\n", |
| 1781 | + "Doing these kinds of transforms is often referred to as **data augmentation**.\n", |
1782 | 1782 | "\n", |
1783 | 1783 | "**Data augmentation** is the process of altering your data in such a way that you *artificially* increase the diversity of your training set.\n", |
1784 | 1784 | "\n", |
|
2090 | 2090 | " self.classifier = nn.Sequential(\n", |
2091 | 2091 | " nn.Flatten(),\n", |
2092 | 2092 | " # Where did this in_features shape come from? \n", |
2093 | | - " # It's because each layer of our network compresses and changes the shape of our inputs data.\n", |
| 2093 | + " # It's because each layer of our network compresses and changes the shape of our input data.\n", |
2094 | 2094 | " nn.Linear(in_features=hidden_units*16*16,\n", |
2095 | 2095 | " out_features=output_shape)\n", |
2096 | 2096 | " )\n", |
|
2361 | 2361 | " # 5. Optimizer step\n", |
2362 | 2362 | " optimizer.step()\n", |
2363 | 2363 | "\n", |
2364 | | - " # Calculate and accumulate accuracy metric across all batches\n", |
| 2364 | + " # Calculate and accumulate accuracy metrics across all batches\n", |
2365 | 2365 | " y_pred_class = torch.argmax(torch.softmax(y_pred, dim=1), dim=1)\n", |
2366 | 2366 | " train_acc += (y_pred_class == y).sum().item()/len(y_pred)\n", |
2367 | 2367 | "\n", |
|
2522 | 2522 | "\n", |
2523 | 2523 | "To keep our experiments quick, we'll train our model for **5 epochs** (though you could increase this if you want).\n", |
2524 | 2524 | "\n", |
2525 | | - "As for an **optimizer** and **loss function**, we'll use `torch.nn.CrossEntropyLoss()` (since we're working with multi-class classification data) and `torch.optim.Adam()` with a learning rate of `1e-3` respecitvely.\n", |
| 2525 | + "As for an **optimizer** and **loss function**, we'll use `torch.nn.CrossEntropyLoss()` (since we're working with multi-class classification data) and `torch.optim.Adam()` with a learning rate of `1e-3` respectively.\n", |
2526 | 2526 | "\n", |
2527 | 2527 | "To see how long things take, we'll import Python's [`timeit.default_timer()`](https://docs.python.org/3/library/timeit.html#timeit.default_timer) method to calculate the training time." |
2528 | 2528 | ] |
|
2772 | 2772 | "source": [ |
2773 | 2773 | "### 8.1 How to deal with overfitting\n", |
2774 | 2774 | "\n", |
2775 | | - "Since the main problem with overfitting is that you're model is fitting the training data *too well*, you'll want to use techniques to \"reign it in\".\n", |
| 2775 | + "Since the main problem with overfitting is that your model is fitting the training data *too well*, you'll want to use techniques to \"reign it in\".\n", |
2776 | 2776 | "\n", |
2777 | 2777 | "A common technique of preventing overfitting is known as [**regularization**](https://ml-cheatsheet.readthedocs.io/en/latest/regularization.html).\n", |
2778 | 2778 | "\n", |
|
2830 | 2830 | "\n", |
2831 | 2831 | "And preventing overfitting and underfitting is possibly the most active area of machine learning research.\n", |
2832 | 2832 | "\n", |
2833 | | - "Since everone wants their models to fit better (less underfitting) but not so good they don't generalize well and perform in the real world (less overfitting).\n", |
| 2833 | + "Since everyone wants their models to fit better (less underfitting) but not so good they don't generalize well and perform in the real world (less overfitting).\n", |
2834 | 2834 | "\n", |
2835 | 2835 | "There's a fine line between overfitting and underfitting.\n", |
2836 | 2836 | "\n", |
|
3180 | 3180 | "\n", |
3181 | 3181 | "Even though our models our performing quite poorly, we can still write code to compare them.\n", |
3182 | 3182 | "\n", |
3183 | | - "Let's first turn our model results in pandas DataFrames." |
| 3183 | + "Let's first turn our model results into pandas DataFrames." |
3184 | 3184 | ] |
3185 | 3185 | }, |
3186 | 3186 | { |
|
3358 | 3358 | "source": [ |
3359 | 3359 | "## 11. Make a prediction on a custom image\n", |
3360 | 3360 | "\n", |
3361 | | - "If you've trained a model on a certain dataset, chances are you'd like to make a prediction on on your own custom data.\n", |
| 3361 | + "If you've trained a model on a certain dataset, chances are you'd like to make a prediction on your own custom data.\n", |
3362 | 3362 | "\n", |
3363 | 3363 | "In our case, since we've trained a model on pizza, steak and sushi images, how could we use our model to make a prediction on one of our own images?\n", |
3364 | 3364 | "\n", |
|
0 commit comments