"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
+ "output_type": "execute_result"
}
],
"source": [
- "# Example code to run in Google Colab\n",
- "%load_ext tensorboard\n",
- "%tensorboard --logdir runs"
+ "# Check out the model results\n",
+ "results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "## TK 6. Create a helper function to build `SummaryWriter()` instances"
+ "Hmmm, we could format this to be a nice plot but could you image keeping track of a bunch of these dictionaries?\n",
+ "\n",
+ "There has to be a better way..."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## TK 5. View our model's results in TensorBoard\n",
+ "\n",
+ "The `SummaryWriter()` class stores our model's results by default in a directory called `runs/` in TensorBoard format.\n",
+ "\n",
+ "TensorBoard is a visualization program created by the TensorFlow team to view and inspect information about models and data.\n",
+ "\n",
+ "You know what that means?\n",
+ "\n",
+ "It's time to follow the data visualizer's motto and *visualize, visualize, visualize!* \n",
+ "\n",
+ "You can view TensorBoard in a number of ways:\n",
+ "\n",
+ "| Code environment | How to view TensorBoard | Resource |\n",
+ "| ----- | ----- | ----- |\n",
+ "| VS Code (notebooks or Python scripts) | Press `SHIFT + CMD + P` to open the Command Palette and search for the command \"Python: Launch TensorBoard\". | [VS Code Guide on TensorBoard and PyTorch](https://code.visualstudio.com/docs/datascience/pytorch-support#_tensorboard-integration) |\n",
+ "| Jupyter and Colab Notebooks | Make sure [TensorBoard is installed](https://pypi.org/project/tensorboard/), load it with `%load_ext tensorboard` and then view your results with `%tensorboard --logdir DIR_WITH_LOGS`. | [`torch.utils.tensorboard`](https://pytorch.org/docs/stable/tensorboard.html) and [Get started with TensorBoard](https://www.tensorflow.org/tensorboard/get_started) |\n",
+ "\n",
+ "You can also upload your experiments to [tensorboard.dev](https://tensorboard.dev/) to share them publicly with others.\n",
+ "\n",
+ "Running the following code in a Google Colab or Jupyter Notebook will start an interactive TensorBoard session to view TensorBoard files in the `runs/` directory.\n",
+ "\n",
+ "```python\n",
+ "%load_ext tensorboard # line magic to load TensorBoard\n",
+ "%tensorboard --logdir runs # run TensorBoard session with the \"runs/\" directory\n",
+ "```"
]
},
{
"cell_type": "code",
- "execution_count": 35,
+ "execution_count": 56,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Example code to run in Jupyter or Google Colab Notebook (uncomment to try it out)\n",
+ "# %load_ext tensorboard\n",
+ "# %tensorboard --logdir runs"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "If all went correctly, you should see something like the following:\n",
+ "\n",
+ "* TK image - tensorboard session with `runs/` directory \n",
+ "* TK explain the different things you can view on TensorBoard\n",
+ "\n",
+ "> **Note:** For more information on running TensorBoard in notebooks or in other locations, see the following:\n",
+ "> * [Using TensorBoard in Notebooks guide by TensorFlow](https://www.tensorflow.org/tensorboard/tensorboard_in_notebooks)\n",
+ "> * [Get started with TensorBoard.dev](https://tensorboard.dev/#get-started) (helpful for uploading your TensorBoard logs to a shareable link)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## TK 6. Create a helper function to build `SummaryWriter()` instances\n",
+ "\n",
+ "UPTOHERE"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "'2022-06-02'"
+ "'2022-06-03'"
]
},
- "execution_count": 35,
+ "execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
@@ -574,7 +780,7 @@
},
{
"cell_type": "code",
- "execution_count": 36,
+ "execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
@@ -592,15 +798,23 @@
" return SummaryWriter(log_dir=log_dir)"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### TK 6.1 Update the `train()` function to include `create_writer()` "
+ ]
+ },
{
"cell_type": "code",
- "execution_count": 37,
+ "execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"# Add create_writer() to train()\n",
"from typing import Dict, List\n",
"from tqdm.auto import tqdm\n",
+ "\n",
"def train(model: torch.nn.Module, \n",
" train_dataloader: torch.utils.data.DataLoader, \n",
" test_dataloader: torch.utils.data.DataLoader, \n",
@@ -704,23 +918,53 @@
"\n",
"TK - turn this into a table...\n",
"\n",
- "TK - experiments to track:\n",
- "- model_0 = 10% data, effnet_b0, 5 epochs\n",
- "- model_1 = 10% data, effnet_b0, 10 epochs (double training time)\n",
- "- model_2 = 20% data, effnet_b0, 5 epochs (double data)\n",
- "- model_3 = 10% data, effnet_b2, 5 epochs (double model parameters)\n",
- "- 2 x epochs, 2 x models, 2 x datasets = 6 models total\n",
+ "TK - what kind of experiments should you run?\n",
+ "* all different hyperparameters - image size, learning rate, number of epochs\n",
+ "* different amounts of data\n",
+ "* different kinds of data augmentation\n",
+ "* if something works better than others, scale it up\n",
+ "\n",
+ "TK - things to know about running experiments (generally, the quicker the better)\n",
+ "\n",
+ "TK - where did data come from? - https://github.com/mrdbourke/pytorch-deep-learning/blob/main/extras/04_custom_data_creation.ipynb \n",
+ "\n",
+ "| Experiment number | Dataset | Model | Number of epochs |\n",
+ "| ----- | ----- | ----- | ----- |\n",
+ "| 1 | Pizza, Steak, Sushi 10% percent | EfficientNetB0 | 5 |\n",
+ "| 2 | Pizza, Steak, Sushi 10% percent | EfficientNetB2 | 5 | \n",
+ "| 3 | Pizza, Steak, Sushi 10% percent | EfficientNetB0 | 10 | \n",
+ "| 4 | Pizza, Steak, Sushi 10% percent | EfficientNetB2 | 10 |\n",
+ "| 5 | Pizza, Steak, Sushi 20% percent | EfficientNetB0 | 5 |\n",
+ "| 6 | Pizza, Steak, Sushi 20% percent | EfficientNetB2 | 5 |\n",
+ "| 7 | Pizza, Steak, Sushi 20% percent | EfficientNetB0 | 10 |\n",
+ "| 8 | Pizza, Steak, Sushi 20% percent | EfficientNetB2 | 10 |\n",
+ "\n",
+ "Notice how we're running a series of experiments to slowly increase the amount of data, the model size and the length of training.\n",
+ "\n",
+ "By the end, experiment 8 will be using double the data, double the model size and double the length of training compared to experiment 1. \n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### TK - Load and prepare different datasets\n",
+ "\n",
+ "* TK - Create two datasets for:\n",
+ " * Train with 10% of data\n",
+ " * Train with 20% of data\n",
+ "* TK - See how the data was created: https://github.com/mrdbourke/pytorch-deep-learning/blob/main/extras/04_custom_data_creation.ipynb \n",
"\n",
"See a list of Torch pretrained models here: https://pytorch.org/vision/stable/models.html, all pretrained models are expected to have data inputs that are normalized with the following:\n",
"```python\n",
"normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],\n",
" std=[0.229, 0.224, 0.225])\n",
- "``` \n"
+ "``` "
]
},
{
"cell_type": "code",
- "execution_count": 38,
+ "execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
@@ -736,21 +980,9 @@
"])"
]
},
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### TK - Load data\n",
- "\n",
- "* TK - Create two datasets for:\n",
- " * Train with 10% of data\n",
- " * Train with 20% of data\n",
- "* TK - See how the data was created: https://github.com/mrdbourke/pytorch-deep-learning/blob/main/extras/04_custom_data_creation.ipynb "
- ]
- },
{
"cell_type": "code",
- "execution_count": 39,
+ "execution_count": 40,
"metadata": {},
"outputs": [
{
@@ -763,6 +995,7 @@
}
],
"source": [
+ "# Download 10 percent and 20 percent training data (if necessary)\n",
"data_10_percent_path = download_data(source=\"https://github.com/mrdbourke/pytorch-deep-learning/raw/main/data/pizza_steak_sushi.zip\",\n",
" destination=\"pizza_steak_sushi\")\n",
"\n",
@@ -772,7 +1005,7 @@
},
{
"cell_type": "code",
- "execution_count": 40,
+ "execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
@@ -786,37 +1019,42 @@
},
{
"cell_type": "code",
- "execution_count": 41,
+ "execution_count": 48,
"metadata": {},
"outputs": [
{
- "data": {
- "text/plain": [
- "(8, 15, 3, 3)"
- ]
- },
- "execution_count": 41,
- "metadata": {},
- "output_type": "execute_result"
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Number of batches of size 32 in 10 percent training data: 8\n",
+ "Number of batches of size 32 in 20 percent training data: 15\n",
+ "Number of batches of size 32 in testing data: 8 (all experiments will use the same test set)\n",
+ "Number of classes: 3, class names: ['pizza', 'steak', 'sushi']\n"
+ ]
}
],
"source": [
- "# Create 10% dataloaders\n",
+ "BATCH_SIZE = 32\n",
+ "\n",
+ "# Create 10% training data dataloaders\n",
"train_dataloader_10_percent, test_dataloader, class_names = data_setup.create_dataloaders(train_dir=train_dir_10_percent,\n",
" test_dir=test_dir,\n",
" transform=simple_transform,\n",
- " batch_size=32\n",
+ " batch_size=BATCH_SIZE\n",
")\n",
"\n",
- "# Create 20% dataloaders\n",
+ "# Create 20% training data dataloaders\n",
"train_dataloader_20_percent, test_dataloader, class_names = data_setup.create_dataloaders(train_dir=train_dir_20_percent,\n",
" test_dir=test_dir,\n",
" transform=simple_transform,\n",
- " batch_size=32\n",
+ " batch_size=BATCH_SIZE\n",
")\n",
"\n",
- "# TK - number of samples/batches per dataloader (using the same test_dataloader for both experiments)\n",
- "len(train_dataloader_10_percent), len(train_dataloader_20_percent), len(test_dataloader), len(class_names)"
+ "# Find the number of samples/batches per dataloader (using the same test_dataloader for both experiments)\n",
+ "print(f\"Number of batches of size {BATCH_SIZE} in 10 percent training data: {len(train_dataloader_10_percent)}\")\n",
+ "print(f\"Number of batches of size {BATCH_SIZE} in 20 percent training data: {len(train_dataloader_20_percent)}\")\n",
+ "print(f\"Number of batches of size {BATCH_SIZE} in testing data: {len(train_dataloader_10_percent)} (all experiments will use the same test set)\")\n",
+ "print(f\"Number of classes: {len(class_names)}, class names: {class_names}\")"
]
},
{
@@ -830,7 +1068,7 @@
},
{
"cell_type": "code",
- "execution_count": 42,
+ "execution_count": 43,
"metadata": {},
"outputs": [],
"source": [
@@ -846,7 +1084,7 @@
},
{
"cell_type": "code",
- "execution_count": 43,
+ "execution_count": 44,
"metadata": {},
"outputs": [
{
@@ -855,7 +1093,7 @@
"1408"
]
},
- "execution_count": 43,
+ "execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
@@ -867,18 +1105,13 @@
},
{
"cell_type": "code",
- "execution_count": 44,
+ "execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"import torchvision\n",
"from torch import nn\n",
"\n",
- "# Set seeds\n",
- "def set_seeds(seed=42):\n",
- " torch.manual_seed(seed)\n",
- " torch.cuda.manual_seed(seed)\n",
- "\n",
"# Get num out features\n",
"OUT_FEATURES = len(class_names)\n",
"\n",
@@ -929,12 +1162,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## Create experiments"
+ "### TK - Create experiments and set up training code"
]
},
{
"cell_type": "code",
- "execution_count": 45,
+ "execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
@@ -951,7 +1184,7 @@
},
{
"cell_type": "code",
- "execution_count": 51,
+ "execution_count": 49,
"metadata": {},
"outputs": [
{
@@ -963,13 +1196,13 @@
"[INFO] DataLoader: data_10_percent\n",
"[INFO] Training for 5 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_10_percent/effnetb0/_5_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb0/5_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "8c07e32372d243ab9c8cbbab97efaa1d",
+ "model_id": "22fa4b3b64a1412283c4fe3365f31cb9",
"version_major": 2,
"version_minor": 0
},
@@ -989,7 +1222,6 @@
"Epoch: 3 | train_loss: 0.8097 | train_acc: 0.6523 | test_loss: 0.7196 | test_acc: 0.8258\n",
"Epoch: 4 | train_loss: 0.7096 | train_acc: 0.7578 | test_loss: 0.5920 | test_acc: 0.8864\n",
"Epoch: 5 | train_loss: 0.5999 | train_acc: 0.9062 | test_loss: 0.5689 | test_acc: 0.8864\n",
- "[INFO] Saving model to 07_effnetb0_data_10_percent_5_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb0_data_10_percent_5_epochs.pth\n",
"----------\n",
"\n",
@@ -998,13 +1230,13 @@
"[INFO] DataLoader: data_10_percent\n",
"[INFO] Training for 5 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_10_percent/effnetb2/_5_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb2/5_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "da29eefda13f4105b3cc2fde3e1e1e56",
+ "model_id": "84d43c55bd0d449dbd89342b9714e2eb",
"version_major": 2,
"version_minor": 0
},
@@ -1024,7 +1256,6 @@
"Epoch: 3 | train_loss: 0.8080 | train_acc: 0.7578 | test_loss: 0.7511 | test_acc: 0.9072\n",
"Epoch: 4 | train_loss: 0.7182 | train_acc: 0.8867 | test_loss: 0.7161 | test_acc: 0.9081\n",
"Epoch: 5 | train_loss: 0.6847 | train_acc: 0.7656 | test_loss: 0.7087 | test_acc: 0.8873\n",
- "[INFO] Saving model to 07_effnetb2_data_10_percent_5_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb2_data_10_percent_5_epochs.pth\n",
"----------\n",
"\n",
@@ -1033,13 +1264,13 @@
"[INFO] DataLoader: data_10_percent\n",
"[INFO] Training for 10 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_10_percent/effnetb0/_10_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb0/10_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "242b96e6f5e1436c97f8454d4fc49b66",
+ "model_id": "bda0cea43afa466691557a2582d2f61c",
"version_major": 2,
"version_minor": 0
},
@@ -1064,7 +1295,6 @@
"Epoch: 8 | train_loss: 0.4700 | train_acc: 0.9492 | test_loss: 0.5199 | test_acc: 0.8759\n",
"Epoch: 9 | train_loss: 0.5729 | train_acc: 0.7695 | test_loss: 0.5120 | test_acc: 0.8873\n",
"Epoch: 10 | train_loss: 0.4782 | train_acc: 0.8242 | test_loss: 0.4650 | test_acc: 0.9072\n",
- "[INFO] Saving model to 07_effnetb0_data_10_percent_10_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb0_data_10_percent_10_epochs.pth\n",
"----------\n",
"\n",
@@ -1073,13 +1303,13 @@
"[INFO] DataLoader: data_10_percent\n",
"[INFO] Training for 10 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_10_percent/effnetb2/_10_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb2/10_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "5c30dac86f8b40f7bef3c83bcc581453",
+ "model_id": "7217e45ae841404685e06b34ba4f48e4",
"version_major": 2,
"version_minor": 0
},
@@ -1104,7 +1334,6 @@
"Epoch: 8 | train_loss: 0.5196 | train_acc: 0.9336 | test_loss: 0.6201 | test_acc: 0.8977\n",
"Epoch: 9 | train_loss: 0.5421 | train_acc: 0.8086 | test_loss: 0.6231 | test_acc: 0.8769\n",
"Epoch: 10 | train_loss: 0.4919 | train_acc: 0.8086 | test_loss: 0.5879 | test_acc: 0.8873\n",
- "[INFO] Saving model to 07_effnetb2_data_10_percent_10_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb2_data_10_percent_10_epochs.pth\n",
"----------\n",
"\n",
@@ -1113,13 +1342,13 @@
"[INFO] DataLoader: data_20_percent\n",
"[INFO] Training for 5 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_20_percent/effnetb0/_5_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb0/5_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "beb5a98ddda24d2cbd524541791e27b4",
+ "model_id": "e50fa786facb4351b77b28445cdcfad1",
"version_major": 2,
"version_minor": 0
},
@@ -1139,7 +1368,6 @@
"Epoch: 3 | train_loss: 0.5805 | train_acc: 0.8604 | test_loss: 0.4576 | test_acc: 0.9176\n",
"Epoch: 4 | train_loss: 0.4937 | train_acc: 0.8646 | test_loss: 0.4454 | test_acc: 0.9176\n",
"Epoch: 5 | train_loss: 0.4886 | train_acc: 0.8500 | test_loss: 0.3913 | test_acc: 0.9176\n",
- "[INFO] Saving model to 07_effnetb0_data_20_percent_5_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb0_data_20_percent_5_epochs.pth\n",
"----------\n",
"\n",
@@ -1148,13 +1376,13 @@
"[INFO] DataLoader: data_20_percent\n",
"[INFO] Training for 5 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_20_percent/effnetb2/_5_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb2/5_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "be92607064144c84a8e45607cd1dcff9",
+ "model_id": "ca0159cbcdff43c99e3d6f2304343da4",
"version_major": 2,
"version_minor": 0
},
@@ -1174,7 +1402,6 @@
"Epoch: 3 | train_loss: 0.6011 | train_acc: 0.8458 | test_loss: 0.5633 | test_acc: 0.9280\n",
"Epoch: 4 | train_loss: 0.5429 | train_acc: 0.8354 | test_loss: 0.5685 | test_acc: 0.8977\n",
"Epoch: 5 | train_loss: 0.4410 | train_acc: 0.8708 | test_loss: 0.4470 | test_acc: 0.9384\n",
- "[INFO] Saving model to 07_effnetb2_data_20_percent_5_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb2_data_20_percent_5_epochs.pth\n",
"----------\n",
"\n",
@@ -1183,13 +1410,13 @@
"[INFO] DataLoader: data_20_percent\n",
"[INFO] Training for 10 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_20_percent/effnetb0/_10_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb0/10_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "7a5c4e7a584e4664901c7edb94a40262",
+ "model_id": "f7e034a9e2f749229fd359939e06793b",
"version_major": 2,
"version_minor": 0
},
@@ -1214,7 +1441,6 @@
"Epoch: 8 | train_loss: 0.3739 | train_acc: 0.8938 | test_loss: 0.3346 | test_acc: 0.8977\n",
"Epoch: 9 | train_loss: 0.2975 | train_acc: 0.9375 | test_loss: 0.3088 | test_acc: 0.9280\n",
"Epoch: 10 | train_loss: 0.3625 | train_acc: 0.8479 | test_loss: 0.2771 | test_acc: 0.9072\n",
- "[INFO] Saving model to 07_effnetb0_data_20_percent_10_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb0_data_20_percent_10_epochs.pth\n",
"----------\n",
"\n",
@@ -1223,13 +1449,13 @@
"[INFO] DataLoader: data_20_percent\n",
"[INFO] Training for 10 epochs\n",
"----------\n",
- "Created SummaryWriter and saving to runs/2022-06-02/data_20_percent/effnetb2/_10_epochs...\n"
+ "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb2/10_epochs...\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
- "model_id": "3e904514585b49339ff7c4434f44ac50",
+ "model_id": "969b861a30e04ef8abef8189ca5be6a2",
"version_major": 2,
"version_minor": 0
},
@@ -1254,12 +1480,11 @@
"Epoch: 8 | train_loss: 0.3861 | train_acc: 0.8792 | test_loss: 0.4350 | test_acc: 0.9280\n",
"Epoch: 9 | train_loss: 0.3315 | train_acc: 0.8979 | test_loss: 0.4254 | test_acc: 0.9081\n",
"Epoch: 10 | train_loss: 0.3382 | train_acc: 0.8979 | test_loss: 0.3909 | test_acc: 0.9384\n",
- "[INFO] Saving model to 07_effnetb2_data_20_percent_10_epochs.pth\n",
"[INFO] Saving model to: models/07_effnetb2_data_20_percent_10_epochs.pth\n",
"----------\n",
"\n",
- "CPU times: user 36 s, sys: 31.4 s, total: 1min 7s\n",
- "Wall time: 1min 19s\n"
+ "CPU times: user 36.5 s, sys: 46.2 s, total: 1min 22s\n",
+ "Wall time: 1min 36s\n"
]
}
],
@@ -1310,7 +1535,6 @@
" \n",
" # Save the model to file so we can get back the best model\n",
" save_filepath = f\"07_{model_name}_{dataloader_name}_{epochs}_epochs.pth\"\n",
- " print(f\"[INFO] Saving model to {save_filepath}\")\n",
" save_model(model=model,\n",
" target_dir=\"models\",\n",
" model_name=save_filepath)\n",
@@ -1321,7 +1545,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## View experiments in TensorBoard\n",
+ "## TK 8. View experiments in TensorBoard\n",
"\n",
"* TK - See example notebook: https://colab.research.google.com/github/tensorflow/tensorboard/blob/master/docs/tensorboard_in_notebooks.ipynb#scrollTo=GUSM8yLrO2yZ \n",
"\n",
@@ -1390,7 +1614,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "## TK - Load in the best model and make predictions with it\n",
+ "## TK - 9. Load in the best model and make predictions with it\n",
"\n",
"TK - best model = effnetb2 + 10 epochs + 20% data (double parameters, double data, double training time)"
]
@@ -1468,7 +1692,8 @@
}
],
"source": [
- "# TK - import function from previously created section: https://www.learnpytorch.io/06_pytorch_transfer_learning/#6-make-predictions-on-images-from-the-test-set \n",
+ "# Import function to make predictions on images and plot them \n",
+ "# See the function previously created in section: https://www.learnpytorch.io/06_pytorch_transfer_learning/#6-make-predictions-on-images-from-the-test-set\n",
"from going_modular.going_modular.predictions import pred_and_plot_image\n",
"\n",
"# Get a random list of 3 images from 20% test set\n",
@@ -1545,9 +1770,9 @@
"metadata": {},
"source": [
"## Exercises\n",
- "* Add functionality to save the best model?\n",
- "* Scale up the dataset (e.g. could use *all* of Food101 + track experiment)\n",
+ "* Upload TensorBoard results to [Get started with TensorBoard.dev](https://tensorboard.dev/#get-started) (helpful for uploading your TensorBoard logs to a shareable link)\n",
"* Introduce data augmentation to the list of experiments, does this change anything?\n",
+ "* Scale up the dataset (e.g. could use *all* of Food101 + design 2 experiments, perhaps a large and a small model, track experiments)\n",
"* Could use the following for data augmentation:\n",
"\n",
"```python\n",
@@ -1627,26 +1852,12 @@
"source": [
"## Extra-curriculum\n",
"\n",
+ "* Check out the PyTorch YouTube tutorial for TensorBoard -- https://pytorch.org/tutorials/beginner/introyt/tensorboardyt_tutorial.html \n",
"* See here for more on the profiler: https://pytorch.org/blog/introducing-pytorch-profiler-the-new-and-improved-performance-tool/\n",
"* See here on setting up TensorBoard in VSCode: https://code.visualstudio.com/docs/datascience/pytorch-support\n",
"* See more on ML experiment tracking - https://madewithml.com/courses/mlops/experiment-tracking/ \n",
"* Does changing the data input size to EfficientNetB4 change its results? E.g. input image size of (380, 380) instead of (224, 224)?"
]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "\n",
- "Example: Use yellow boxes for examples that are not \n",
- "inside code cells, or use for mathematical formulas if needed.\n",
- "
"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": []
}
],
"metadata": {