From 332649c73abfd279cb88ef28a52388b9309900cc Mon Sep 17 00:00:00 2001 From: Daniel Bourke Date: Sat, 4 Jun 2022 12:23:07 +1000 Subject: [PATCH] add more annotations for 07 --- 07_pytorch_experiment_tracking.ipynb | 494 ++++++++++++++++++--------- 1 file changed, 337 insertions(+), 157 deletions(-) diff --git a/07_pytorch_experiment_tracking.ipynb b/07_pytorch_experiment_tracking.ipynb index d5d68db..88c35bb 100644 --- a/07_pytorch_experiment_tracking.ipynb +++ b/07_pytorch_experiment_tracking.ipynb @@ -125,7 +125,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -163,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -179,7 +179,7 @@ "PosixPath('data/pizza_steak_sushi')" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -276,18 +276,18 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(,\n", - " ,\n", + "(,\n", + " ,\n", " ['pizza', 'steak', 'sushi'])" ] }, - "execution_count": 51, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -334,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -359,7 +359,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -394,7 +394,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -439,7 +439,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -476,7 +476,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -595,13 +595,13 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "8aeb1c9ee1614bc387a5beb5651e008d", + "model_id": "464d02414f9f4599a7e201702013f1c6", "version_major": 2, "version_minor": 0 }, @@ -616,11 +616,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "Epoch: 1 | train_loss: 0.6792 | train_acc: 0.9023 | test_loss: 0.7201 | test_acc: 0.8873\n", - "Epoch: 2 | train_loss: 0.7398 | train_acc: 0.7266 | test_loss: 0.6405 | test_acc: 0.9176\n", - "Epoch: 3 | train_loss: 0.6312 | train_acc: 0.7773 | test_loss: 0.5622 | test_acc: 0.8968\n", - "Epoch: 4 | train_loss: 0.5676 | train_acc: 0.8711 | test_loss: 0.5712 | test_acc: 0.8864\n", - "Epoch: 5 | train_loss: 0.6329 | train_acc: 0.7305 | test_loss: 0.5846 | test_acc: 0.8456\n" + "Epoch: 1 | train_loss: 1.0904 | train_acc: 0.4219 | test_loss: 0.9086 | test_acc: 0.5085\n", + "Epoch: 2 | train_loss: 0.9228 | train_acc: 0.6133 | test_loss: 0.7942 | test_acc: 0.8049\n", + "Epoch: 3 | train_loss: 0.7823 | train_acc: 0.7344 | test_loss: 0.6708 | test_acc: 0.9072\n", + "Epoch: 4 | train_loss: 0.6842 | train_acc: 0.8477 | test_loss: 0.6611 | test_acc: 0.8049\n", + "Epoch: 5 | train_loss: 0.7166 | train_acc: 0.6992 | test_loss: 0.6622 | test_acc: 0.7850\n" ] } ], @@ -650,31 +650,31 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'train_loss': [0.6791654154658318,\n", - " 0.7398175299167633,\n", - " 0.6312201134860516,\n", - " 0.5675686299800873,\n", - " 0.6329038292169571],\n", - " 'train_acc': [0.90234375, 0.7265625, 0.77734375, 0.87109375, 0.73046875],\n", - " 'test_loss': [0.7201185425122579,\n", - " 0.6404749552408854,\n", - " 0.5622232655684153,\n", - " 0.5712322692076365,\n", - " 0.5846467117468516],\n", - " 'test_acc': [0.8873106060606061,\n", - " 0.9176136363636364,\n", - " 0.8967803030303031,\n", - " 0.8863636363636364,\n", - " 0.8456439393939394]}" + "{'train_loss': [1.09035424888134,\n", + " 0.9228200018405914,\n", + " 0.7823289185762405,\n", + " 0.6842461675405502,\n", + " 0.7166478410363197],\n", + " 'train_acc': [0.421875, 0.61328125, 0.734375, 0.84765625, 0.69921875],\n", + " 'test_loss': [0.9086348017056783,\n", + " 0.7941891352335612,\n", + " 0.6708019773165385,\n", + " 0.6610560615857443,\n", + " 0.6622093121210734],\n", + " 'test_acc': [0.5085227272727273,\n", + " 0.8049242424242425,\n", + " 0.9071969696969697,\n", + " 0.8049242424242425,\n", + " 0.7850378787878788]}" ] }, - "execution_count": 55, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -726,7 +726,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -778,7 +778,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -833,7 +833,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -877,7 +877,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -1084,7 +1084,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### TK - 7.3 Load and prepare different datasets\n", + "### TK - 7.3 Download different datasets\n", "\n", "Before we start running our series of experiments, we need to make sure our datasets are ready.\n", "\n", @@ -1103,7 +1103,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -1137,7 +1137,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -1168,6 +1168,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "### TK - 7.4 Transform Datasets and create DataLoaders\n", + "\n", "Next we'll create a series of transforms to prepare our images for our model(s).\n", "\n", "The transform will resize all the images (we'll start with 224, 224 but this could be changed), turn them into tensors and normalize them in way so their distributions are inline with the ImageNet dataset (we do this because our models from [`torchvision.models`](https://pytorch.org/vision/stable/models.html) have been pretrained on ImageNet)." @@ -1175,7 +1177,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -1197,12 +1199,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "UPTOHERE: creating dataloaders - potentially this could be a different section, e.g. 7.3, 7.4 - break them down more so they have less but better content" + "Transform ready!\n", + "\n", + "Now let's create our DataLoaders using the `create_dataloaders()` function from `data_setup.py` we created in [05. PyTorch Going Modular section 2](https://www.learnpytorch.io/05_pytorch_going_modular/#2-create-datasets-and-dataloaders-data_setuppy). \n", + "\n", + "We'll create the DataLoaders with a batch size of 32.\n", + "\n", + "For all of our experiments we'll be using the same `test_dataloader` (to keep comparisons consistent)." ] }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -1219,14 +1227,14 @@ "source": [ "BATCH_SIZE = 32\n", "\n", - "# Create 10% training data dataloaders\n", + "# Create 10% training and test 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", + " test_dir=test_dir, \n", " transform=simple_transform,\n", " batch_size=BATCH_SIZE\n", ")\n", "\n", - "# Create 20% training data dataloaders\n", + "# Create 20% training and test data DataLoders\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", @@ -1244,20 +1252,202 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### TK Setup models\n", + "### TK 7.5 Create feature extractor models\n", "\n", - "* **Note:** Many modern models can handle input images of varying sizes thanks to [`torch.nn.AdaptiveAvgPool2d()`](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveAvgPool2d.html), this layer adaptively adjusts the `output_size` of a given input as required. You can try this out by passing different size input images to `summary()` or your models.\n", + "Time to start building our models.\n", "\n", - "* TK get a comparison of the different model sizes to each other (e.g. number of parameters in effnetb0 vs number of parameters in effnetb2)" + "We're going to create two feature extractor models: \n", + "\n", + "1. `torchvision.models.efficientnet_b0(pretrained=True)` (EffNetB0 for short) backbone + custom classifier head \n", + "2. `torchvision.models.efficientnet_b2(pretrained=True)` (EffNetB2 for short) backbone + custom classifier head\n", + "\n", + "To do this, we'll freeze the base layers (the feature layers) and update the model's classifier heads (output layers) to suit our problem just like we did in [06. PyTorch Transfer Learning section 3.4](https://www.learnpytorch.io/06_pytorch_transfer_learning/#34-freezing-the-base-model-and-changing-the-output-layer-to-suit-our-needs).\n", + "\n", + "We saw in the previous chapter the `in_features` parameter to the classifier head of EffNetB0 is `1280` (the backbone turns the input image into a feature vector of size `1280`).\n", + "\n", + "Since EffNetB2 has a different number of layers and parameters, we'll need to adapt it accordingly.\n", + "\n", + "> **Note:** Whenever you use a different model, one of the first things you should inspect is the input and output shapes. That way you'll know how you'll have to prepare your input data/update the model to have the correct output shape.\n", + "\n", + "We can find the input and output shapes of EffNetB2 using [`torchinfo.summary()`](https://github.com/TylerYep/torchinfo) and passing in the `input_size=(32, 3, 224, 224)` parameter (`(32, 3, 224, 224)` is equivalent to `(batch_size, color_channels, height, width)`, i.e we pass in an example of what a single batch of data would be to our model).\n", + "\n", + "> **Note:** Many modern models can handle input images of varying sizes thanks to [`torch.nn.AdaptiveAvgPool2d()`](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveAvgPool2d.html), this layer adaptively adjusts the `output_size` of a given input as required. You can try this out by passing different size input images to `torchinfo.summary()` or your models.\n", + "\n", + "To find the required input shape to the final layer of EffNetB2, let's:\n", + "1. Create an instance of `torchvision.models.efficientnet_b2(pretrained=True)`\n", + "2. See the various input and output shapes by running `torchinfo.summary()`\n", + "3. Print out the number of `in_features` by inspecting `state_dict()` of the classifier portion of EffNetB2 and printing the length of the weight matrix.\n" ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of in_features to final layer of EfficientNetB2: 1408\n" + ] + } + ], + "source": [ + "import torchvision\n", + "from torchinfo import summary\n", + "\n", + "# 1. Create an instance of EffNetB2\n", + "effnetb2 = torchvision.models.efficientnet_b2(pretrained=True)\n", + "\n", + "# 2. Get a summary of standard EffNetB2 from torchvision.models (uncomment for full output)\n", + "# summary(model=effnetb2, \n", + "# input_size=(32, 3, 224, 224), # make sure this is \"input_size\", not \"input_shape\"\n", + "# # col_names=[\"input_size\"], # uncomment for smaller output\n", + "# col_names=[\"input_size\", \"output_size\", \"num_params\", \"trainable\"],\n", + "# col_width=20,\n", + "# row_settings=[\"var_names\"]\n", + "# ) \n", + "\n", + "# 3. Get the number of in_features of the EfficientNetB2 classifier layer\n", + "print(f\"Number of in_features to final layer of EfficientNetB2: {len(effnetb2.classifier.state_dict()['1.weight'][0])}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "TK image - of the output of `summary()`\n", + "\n", + "Now we know the required number of `in_features` for the EffNetB2 model, let's create a couple of helper functions to setup our EffNetB0 and EffNetB2 feature extractor models.\n", + "\n", + "We want these functions to:\n", + "1. Get the base model from `torchvision.models`\n", + "2. Freeze the base layers in the model (set `requires_grad=False`)\n", + "3. Set the random seeds (we don't *need* to do this but since we're running a series of experiments and initalizing a new layer with random weights, we want the randomness to be similar for each experiment)\n", + "4. Change the classifier head (to suit our problem)\n", + "5. Give the model a name (e.g. \"effnetb0\" for EffNetB0)\n", + "\n", + "Let's do it." + ] + }, + { + "cell_type": "code", + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ - "effnetb2 = torchvision.models.efficientnet_b2(pretrained=True).to(device)\n", + "import torchvision\n", + "from torch import nn\n", + "\n", + "# Get num out features (one for each class pizza, steak, sushi)\n", + "OUT_FEATURES = len(class_names)\n", + "\n", + "# Create an EffNetB0 feature extractor\n", + "def create_effnetb0():\n", + " # 1. Get the base mdoel\n", + " model = torchvision.models.efficientnet_b0(pretrained=True).to(device)\n", + "\n", + " # 2. Freeze the base model layers\n", + " for param in model.features.parameters():\n", + " param.requires_grad = False\n", + "\n", + " # 3. Set the seeds\n", + " set_seeds()\n", + "\n", + " # 4. Change the classifier head\n", + " model.classifier = nn.Sequential(\n", + " nn.Dropout(p=0.2),\n", + " nn.Linear(in_features=1280, out_features=OUT_FEATURES)\n", + " ).to(device)\n", + "\n", + " # 5. Give the model a name\n", + " model.name = \"effnetb0\"\n", + " print(f\"[INFO] Creating new {model.name} model.\")\n", + " return model\n", + "\n", + "# Create an EffNetB2 feature extractor\n", + "def create_effnetb2():\n", + " # 1. Get the base model\n", + " model = torchvision.models.efficientnet_b2(pretrained=True).to(device)\n", + "\n", + " # 2. Freeze the base model layers\n", + " for param in model.features.parameters():\n", + " param.requires_grad = False\n", + "\n", + " # 3. Set the seeds\n", + " set_seeds()\n", + "\n", + " # 4. Change the classifier head\n", + " model.classifier = nn.Sequential(\n", + " nn.Dropout(p=0.3),\n", + " nn.Linear(in_features=1408, out_features=OUT_FEATURES)\n", + " ).to(device)\n", + "\n", + " # 5. Give the model a name\n", + " model.name = \"effnetb2\"\n", + " print(f\"[INFO] Creating new {model.name} model.\")\n", + " return model" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Those are some nice looking functions!\n", + "\n", + "Let's test them out by creating an instance of EffNetB0 and EffNetB2 and checking out their `summary()`." + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[INFO] Creating new effnetb0 model.\n" + ] + } + ], + "source": [ + "effnetb0 = create_effnetb0() \n", + "\n", + "# Get an output summary of the layers in our EffNetB0 feature extractor model (uncomment to view full output)\n", + "# summary(model=effnetb0, \n", + "# input_size=(32, 3, 224, 224), # make sure this is \"input_size\", not \"input_shape\"\n", + "# # col_names=[\"input_size\"], # uncomment for smaller output\n", + "# col_names=[\"input_size\", \"output_size\", \"num_params\", \"trainable\"],\n", + "# col_width=20,\n", + "# row_settings=[\"var_names\"]\n", + "# ) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "TK image - output of model summary for effnetb0" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[INFO] Creating new effnetb2 model.\n" + ] + } + ], + "source": [ + "effnetb2 = create_effnetb2()\n", + "\n", + "# Get an output summary of the layers in our EffNetB2 feature extractor model (uncomment to view full output)\n", "# summary(model=effnetb2, \n", "# input_size=(32, 3, 224, 224), # make sure this is \"input_size\", not \"input_shape\"\n", "# # col_names=[\"input_size\"], # uncomment for smaller output\n", @@ -1268,108 +1458,81 @@ ] }, { - "cell_type": "code", - "execution_count": 44, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1408" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "# Get the number of in_features of the EfficientNetB2 classifier layer\n", - "len(effnetb2.classifier.state_dict()[\"1.weight\"][0])" - ] - }, - { - "cell_type": "code", - "execution_count": 45, - "metadata": {}, - "outputs": [], - "source": [ - "import torchvision\n", - "from torch import nn\n", - "\n", - "# Get num out features\n", - "OUT_FEATURES = len(class_names)\n", - "\n", - "# EfficientNetB0\n", - "def create_effnetb0():\n", - " # Get the base mdoel\n", - " model = torchvision.models.efficientnet_b0(pretrained=True).to(device)\n", - "\n", - " # Free the base model layers\n", - " for param in model.features.parameters():\n", - " param.requires_grad = False\n", - "\n", - " # Change the classifier head\n", - " set_seeds()\n", - " model.classifier = nn.Sequential(\n", - " nn.Dropout(p=0.2),\n", - " nn.Linear(in_features=1280, out_features=OUT_FEATURES)\n", - " ).to(device)\n", - "\n", - " # Give the model a name\n", - " model.name = \"effnetb0\"\n", - " print(f\"[INFO] Creating new {model.name} model.\")\n", - " return model\n", - "\n", - "# EfficientNetB2\n", - "def create_effnetb2():\n", - " # Get the base model\n", - " model = torchvision.models.efficientnet_b2(pretrained=True).to(device)\n", - "\n", - " # Change the classifier head\n", - " set_seeds()\n", - " model.classifier = nn.Sequential(\n", - " nn.Dropout(p=0.3),\n", - " nn.Linear(in_features=1408, out_features=OUT_FEATURES)\n", - " ).to(device)\n", - "\n", - " # Free the base model layers\n", - " for param in model.features.parameters():\n", - " param.requires_grad = False\n", - "\n", - " # Give the model a name\n", - " model.name = \"effnetb2\"\n", - " print(f\"[INFO] Creating new {model.name} model.\")\n", - " return model" + "TK image - output of model summary for effnetb2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### TK - Create experiments and set up training code" + "Looking at the outputs of the summaries, it seems the EffNetB2 backbone has nearly double the amount of parameters as EffNetB0.\n", + "\n", + "| Model | Total parameters (before freezing/changing head) | Total parameters (after freezing/changing head) | Total trainable parameters (after freezing/changing head) |\n", + "| ----- | ----- | ----- | ----- |\n", + "| `torchvision.models.efficientnet_b0(pretrained=True)` | 5,288,548 | 4,011,391 | 3,843 | \n", + "| `torchvision.models.efficientnet_b2(pretrained=True)` | 9,109,994 | 7,705,221 | 4,227 |\n", + "\n", + "This gives the backbone of the EffNetB2 model more opportunities to form a representation of our pizza, steak and sushi data.\n", + "\n", + "However, the trainable parameters for each model (the classifier heads) aren't very different.\n", + "\n", + "Will these extra parameters lead to better results?\n", + "\n", + "We'll have to wait and see... \n", + "\n", + "> **Note:** In the spirit of experimenting, you really could try almost any model from `torchvision.models` in a similar fashion to what we're doing here. I've only chosen EffNetB0 and EffNetB2 as examples. Perhaps you might want to throw something like `torchvision.models.convnext_tiny()` or `torchvision.models.convnext_small()` into the mix.\n", + "\n", + "TK image - effnetb0 + effnetb2 feature extractor models" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### TK - 7.6 Create experiments and set up training code\n", + "\n", + "We've prepared our data and prepared our models, the time has come to setup some experiments!\n", + "\n", + "We'll start by creating two lists and a dictionary:\n", + "1. A list of the number of epochs we'd like to test (`[5, 10]`)\n", + "2. A list of the models we'd like to test (`[\"effnetb0\", \"effnetb2\"]`)\n", + "3. A dictionary of the different training DataLoaders" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ - "# Create epochs list\n", + "# 1. Create epochs list\n", "num_epochs = [5, 10]\n", "\n", - "# Create models list (need to create a new model for each experiment)\n", + "# 2. Create models list (need to create a new model for each experiment)\n", "models = [\"effnetb0\", \"effnetb2\"]\n", "\n", - "# Create dataloaders dictionary for various dataloaders\n", + "# 3. Create dataloaders dictionary for various dataloaders\n", "train_dataloaders = {\"data_10_percent\": train_dataloader_10_percent,\n", " \"data_20_percent\": train_dataloader_20_percent}" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Lists and dictionary created!\n", + "\n", + "Now we can write code to iterate through each of the different options and try out each of the different combinations.\n", + "\n", + "UPTOHERE... writing code to iterate through experiments, track the results and save the trained model at the end of each experiment" + ] + }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -1381,13 +1544,13 @@ "[INFO] DataLoader: data_10_percent\n", "[INFO] Training for 5 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb0/5_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_10_percent/effnetb0/5_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "22fa4b3b64a1412283c4fe3365f31cb9", + "model_id": "cc8964778c7544b4852f8ff033ef6d56", "version_major": 2, "version_minor": 0 }, @@ -1415,13 +1578,13 @@ "[INFO] DataLoader: data_10_percent\n", "[INFO] Training for 5 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb2/5_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_10_percent/effnetb2/5_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "84d43c55bd0d449dbd89342b9714e2eb", + "model_id": "5178dfd761384633b24dc26d936e1ec6", "version_major": 2, "version_minor": 0 }, @@ -1449,13 +1612,13 @@ "[INFO] DataLoader: data_10_percent\n", "[INFO] Training for 10 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb0/10_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_10_percent/effnetb0/10_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "bda0cea43afa466691557a2582d2f61c", + "model_id": "5e6e13dc6eb8489d8abfee348dea8bab", "version_major": 2, "version_minor": 0 }, @@ -1488,13 +1651,13 @@ "[INFO] DataLoader: data_10_percent\n", "[INFO] Training for 10 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_10_percent/effnetb2/10_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_10_percent/effnetb2/10_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "7217e45ae841404685e06b34ba4f48e4", + "model_id": "ad2081cc018e4febac72e788a1b1d2f2", "version_major": 2, "version_minor": 0 }, @@ -1527,13 +1690,13 @@ "[INFO] DataLoader: data_20_percent\n", "[INFO] Training for 5 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb0/5_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_20_percent/effnetb0/5_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e50fa786facb4351b77b28445cdcfad1", + "model_id": "cb4a70bb37eb4489a926d26bc3699f70", "version_major": 2, "version_minor": 0 }, @@ -1561,13 +1724,13 @@ "[INFO] DataLoader: data_20_percent\n", "[INFO] Training for 5 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb2/5_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_20_percent/effnetb2/5_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "ca0159cbcdff43c99e3d6f2304343da4", + "model_id": "8af63629be6e4d238e9b351041904715", "version_major": 2, "version_minor": 0 }, @@ -1595,13 +1758,13 @@ "[INFO] DataLoader: data_20_percent\n", "[INFO] Training for 10 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb0/10_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_20_percent/effnetb0/10_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "f7e034a9e2f749229fd359939e06793b", + "model_id": "c6c0e83ad89140fd83a99d9d574985bf", "version_major": 2, "version_minor": 0 }, @@ -1634,13 +1797,13 @@ "[INFO] DataLoader: data_20_percent\n", "[INFO] Training for 10 epochs\n", "----------\n", - "Created SummaryWriter and saving to runs/2022-06-03/data_20_percent/effnetb2/10_epochs...\n" + "[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_20_percent/effnetb2/10_epochs...\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "969b861a30e04ef8abef8189ca5be6a2", + "model_id": "2cac013b0b02400f87dcab3da67fae9f", "version_major": 2, "version_minor": 0 }, @@ -1656,7 +1819,24 @@ "output_type": "stream", "text": [ "Epoch: 1 | train_loss: 0.9819 | train_acc: 0.5604 | test_loss: 0.7775 | test_acc: 0.8049\n", - "Epoch: 2 | train_loss: 0.7298 | train_acc: 0.8021 | test_loss: 0.6665 | test_acc: 0.8873\n", + "Epoch: 2 | train_loss: 0.7298 | train_acc: 0.8021 | test_loss: 0.6665 | test_acc: 0.8873\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Exception ignored in: \n", + "Traceback (most recent call last):\n", + " File \"/home/daniel/code/pytorch/env/lib/python3.9/logging/__init__.py\", line 227, in _releaseLock\n", + " def _releaseLock():\n", + "KeyboardInterrupt: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "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", @@ -1668,8 +1848,8 @@ "[INFO] Saving model to: models/07_effnetb2_data_20_percent_10_epochs.pth\n", "----------\n", "\n", - "CPU times: user 36.5 s, sys: 46.2 s, total: 1min 22s\n", - "Wall time: 1min 36s\n" + "CPU times: user 37.2 s, sys: 48.4 s, total: 1min 25s\n", + "Wall time: 1min 40s\n" ] } ], @@ -1691,9 +1871,9 @@ "\n", " # Select the model\n", " if model_name == \"effnetb0\":\n", - " model = create_effnetb0()\n", + " model = create_effnetb0() # creates a new model each time (important because we want each experiment to start from scratch)\n", " else:\n", - " model = create_effnetb2()\n", + " model = create_effnetb2() # creates a new model each time (important because we want each experiment to start from scratch)\n", " \n", " # Create information print outs\n", " print(f\"[INFO] Model: {model_name}\")\n", @@ -1742,7 +1922,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1806,7 +1986,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1836,7 +2016,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1904,7 +2084,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "metadata": {}, "outputs": [ {