mirror of
https://github.com/mrdbourke/pytorch-deep-learning.git
synced 2026-11-27 06:07:09 +00:00
add annotations for 07
This commit is contained in:
1 parent
f2695afeee
commit
bbb25d0ca6
1 file changed
+262
-77
@@ -407,7 +407,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### TK Adjust training function to track results with `SummaryWriter`\n",
|
||||
"### TK Adjust `train()` function to track results with `SummaryWriter()`\n",
|
||||
"\n",
|
||||
"Beautiful!\n",
|
||||
"\n",
|
||||
@@ -433,7 +433,7 @@
|
||||
"\n",
|
||||
"TensorBoard is a part of the TensorFlow deep learning library and is an excellent way to visualize different parts of your model.\n",
|
||||
"\n",
|
||||
"Let's import part of our training code from [`engine.py`](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/going_modular/going_modular/engine.py) and create a default `SummaryWriter()` instance.\n",
|
||||
"Let's import part of our training code from [`engine.py`](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/going_modular/going_modular/engine.py) (namely `train_step()` and `test_step()` as these are required for `train()`) and create a default `SummaryWriter()` instance.\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
@@ -465,12 +465,13 @@
|
||||
"We can do this with [`writer.add_scalars(main_tag, tag_scalar_dict)`](https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_scalars), where:\n",
|
||||
"* `main_tag` (string) - the name for the scalars being tracked (e.g. \"Accuracy\")\n",
|
||||
"* `tag_scalar_dict` (dict) - a dictionary of the values being tracked (e.g. `{\"train_loss\": 0.3454}`)\n",
|
||||
" * > **Note:** The method is called `add_scalars()` because our loss and accuracy values are generally scalars (single values).\n",
|
||||
"\n",
|
||||
"Once we've finished tracking values, we'll call `writer.close()` to tell the `writer` to stop looking for values to track. \n",
|
||||
"\n",
|
||||
"> **Note:** You can track information about your model almost anywhere in your code. But quite often experiments will be tracked *while* a model is training (inside a training/testing loop).\n",
|
||||
">\n",
|
||||
"> The `torch.utils.tensorboard.SummaryWriter()` class also has many different methods to track different things about your model/data, such as [`add_graph()`](https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_graph) which tracks the computation graph of your model. For more options, [check the PyTorch documentation](https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter)."
|
||||
"> The `torch.utils.tensorboard.SummaryWriter()` class also has many different methods to track different things about your model/data, such as [`add_graph()`](https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter.add_graph) which tracks the computation graph of your model. For more options, [check the `SummaryWriter()` documentation](https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter)."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -754,47 +755,70 @@
|
||||
"source": [
|
||||
"## TK 6. Create a helper function to build `SummaryWriter()` instances\n",
|
||||
"\n",
|
||||
"UPTOHERE"
|
||||
"The `SummaryWriter()` class logs various information to a directory specified by the `log_dir` parameter.\n",
|
||||
"\n",
|
||||
"How about we make a helper function to create a custom directory per experiment?\n",
|
||||
"\n",
|
||||
"For example, say we'd like to track things like:\n",
|
||||
"* Experiment date/timestamp - when did the experiment take place?\n",
|
||||
"* Experiment name - is there something we'd like to call the experiment?\n",
|
||||
"* Model name - what model was used?\n",
|
||||
"* Extra - should anything else be tracked?\n",
|
||||
"\n",
|
||||
"You could track almost anything here and be as creative as you want but these should be enough to start.\n",
|
||||
"\n",
|
||||
"Let's create a helper function called `create_writer()` that produces a `SummaryWriter()` instance tracking to a custom `log_dir`.\n",
|
||||
"\n",
|
||||
"Ideally, we'd like the `log_dir` to be something like: \n",
|
||||
"\n",
|
||||
"`runs/YYYY-MM-DD/experiment_name/model_name/extra` \n",
|
||||
"\n",
|
||||
"Where `YYYY-MM-DD` is the date the experiment was run (you could add the time as well)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 36,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'2022-06-03'"
|
||||
]
|
||||
},
|
||||
"execution_count": 36,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from datetime import datetime\n",
|
||||
"datetime.now().strftime(\"%Y-%m-%d\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"execution_count": 60,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def create_writer(experiment_name, model_name, extra=None):\n",
|
||||
" # TK - docstring\n",
|
||||
"def create_writer(experiment_name: str, \n",
|
||||
" model_name: str, \n",
|
||||
" extra: str=None) -> torch.utils.tensorboard.writer.SummaryWriter():\n",
|
||||
" \"\"\"Creates a torch.utils.tensorboard.writer.SummaryWriter() instance saving to a specific log_dir.\n",
|
||||
"\n",
|
||||
" log_dir is combination of runs/timestamp_experiment_name_model_name_extra.\n",
|
||||
"\n",
|
||||
" Where timestamp is the current date in YYYY-MM-DD format.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" experiment_name (str): Name of experiment.\n",
|
||||
" model_name (str): Name of model.\n",
|
||||
" extra (str, optional): Anything extra to add to the directory. Defaults to None.\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" torch.utils.tensorboard.writer.SummaryWriter(): Instance of a writer saving to log_dir.\n",
|
||||
"\n",
|
||||
" Example usage:\n",
|
||||
" writer = create_writer(experiment_name=\"data_10_percent\",\n",
|
||||
" model_name=\"effnetb2\",\n",
|
||||
" extra=\"5_epochs\")\n",
|
||||
" This is the same as:\n",
|
||||
" writer = SummaryWriter(log_dir=\"runs/2022-06-04/data_10_percent/effnetb2/5_epochs/\")\n",
|
||||
" \"\"\"\n",
|
||||
" from datetime import datetime\n",
|
||||
" import os\n",
|
||||
"\n",
|
||||
" # Get timestamp of current date (all experiments on certain day live in same folder)\n",
|
||||
" timestamp = datetime.now().strftime(\"%Y-%m-%d\")\n",
|
||||
" timestamp = datetime.now().strftime(\"%Y-%m-%d\") # returns current date in YYYY-MM-DD format\n",
|
||||
"\n",
|
||||
" if extra:\n",
|
||||
" # Create log directory path\n",
|
||||
" log_dir = os.path.join(\"runs\", timestamp, experiment_name, model_name, extra)\n",
|
||||
" else:\n",
|
||||
" log_dir = os.path.join(\"runs\", timestamp, experiment_name, model_name)\n",
|
||||
" print(f\"Created SummaryWriter and saving to {log_dir}...\")\n",
|
||||
" \n",
|
||||
" print(f\"[INFO] Created SummaryWriter and saving to {log_dir}...\")\n",
|
||||
" return SummaryWriter(log_dir=log_dir)"
|
||||
]
|
||||
},
|
||||
@@ -802,12 +826,58 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### TK 6.1 Update the `train()` function to include `create_writer()` "
|
||||
"Beautiful!\n",
|
||||
"\n",
|
||||
"Now we've got a `create_writer()` function, let's try it out."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"execution_count": 62,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[INFO] Created SummaryWriter and saving to runs/2022-06-04/data_10_percent/effnetb0/5_epochs...\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create an example writer\n",
|
||||
"example_writer = create_writer(experiment_name=\"data_10_percent\",\n",
|
||||
" model_name=\"effnetb0\",\n",
|
||||
" extra=\"5_epochs\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Looking good, now we've got a way to log and trace back our various experiments."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### TK 6.1 Update the `train()` function to include a `writer` parameter\n",
|
||||
"\n",
|
||||
"Our `create_writer()` function works fantastic.\n",
|
||||
"\n",
|
||||
"How about we incorporate the ability for our `train()` function to take in a `writer` parameter so we actively update the `SummaryWriter()` instance we're using each time we call `train()`.\n",
|
||||
"\n",
|
||||
"For example, say we're running a series of experiments, calling `train()` multiple times for multiple different models, it would be good if each experiment used a different `writer`.\n",
|
||||
"\n",
|
||||
"One `writer` per experiment.\n",
|
||||
"\n",
|
||||
"To adjust the `train()` function we'll add a `writer` parameter to the function and then we'll add some code to see if there's a `writer` and if so, we'll track our information there."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 63,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -824,12 +894,15 @@
|
||||
" device: torch.device, \n",
|
||||
" writer: torch.utils.tensorboard.writer.SummaryWriter) -> Dict[str, List]:\n",
|
||||
" \"\"\"Trains and tests a PyTorch model.\n",
|
||||
"\n",
|
||||
" Passes a target PyTorch models through train_step() and test_step()\n",
|
||||
" functions for a number of epochs, training and testing the model\n",
|
||||
" in the same epoch loop.\n",
|
||||
"\n",
|
||||
" Calculates, prints and stores evaluation metrics throughout.\n",
|
||||
"\n",
|
||||
" Stores metrics to specified writer log_dir if present.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" model: A PyTorch model to be trained and tested.\n",
|
||||
" train_dataloader: A DataLoader instance for the model to be trained on.\n",
|
||||
@@ -838,6 +911,7 @@
|
||||
" loss_fn: A PyTorch loss function to calculate loss on both datasets.\n",
|
||||
" epochs: An integer indicating how many epochs to train for.\n",
|
||||
" device: A target device to compute on (e.g. \"cuda\" or \"cpu\").\n",
|
||||
" writer: A SummaryWriter() instance to log model results to.\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" A dictionary of training and testing loss as well as training and\n",
|
||||
@@ -887,6 +961,9 @@
|
||||
" results[\"test_loss\"].append(test_loss)\n",
|
||||
" results[\"test_acc\"].append(test_acc)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" ### New ###\n",
|
||||
" # See if there's a writer, if so, log to it\n",
|
||||
" if writer:\n",
|
||||
" # Add results to SummaryWriter\n",
|
||||
" writer.add_scalars(main_tag=\"Loss\", \n",
|
||||
@@ -916,19 +993,72 @@
|
||||
"source": [
|
||||
"## TK - 7. Setting up a series of modelling experiments\n",
|
||||
"\n",
|
||||
"TK - turn this into a table...\n",
|
||||
"It's to step things up a notch.\n",
|
||||
"\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",
|
||||
"Previously we've been running various experiments and inspecting the results one by one.\n",
|
||||
"\n",
|
||||
"TK - things to know about running experiments (generally, the quicker the better)\n",
|
||||
"But what if we could run multiple experiments and then inspect the results all together?\n",
|
||||
"\n",
|
||||
"TK - where did data come from? - https://github.com/mrdbourke/pytorch-deep-learning/blob/main/extras/04_custom_data_creation.ipynb \n",
|
||||
"Well, that's what we're going to set up."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 7.2 What kind of experiments should you run?\n",
|
||||
"\n",
|
||||
"| Experiment number | Dataset | Model | Number of epochs |\n",
|
||||
"That's the million dollar question in machine learning.\n",
|
||||
"\n",
|
||||
"Because there's really no limit to the experiments you can run.\n",
|
||||
"\n",
|
||||
"Such a freedom is why machine learning is so exciting and terrifying at the same time.\n",
|
||||
"\n",
|
||||
"This where you'll have to put on your scientist hat and remember the machine learning practitioner's motto: *experiment, experiment, experiment!*\n",
|
||||
"\n",
|
||||
"Every hyperparameter stands as a starting point for a different experiment: \n",
|
||||
"* Change the number of epochs.\n",
|
||||
"* Change the number of layers/hidden units.\n",
|
||||
"* Change the amount of data.\n",
|
||||
"* Change the learning rate.\n",
|
||||
"* Try different kinds of data augmentation.\n",
|
||||
"* Train for a different number of epochs.\n",
|
||||
"* Choose a different model architecture. \n",
|
||||
"\n",
|
||||
"With practice and running many different experiments, you'll start to build an intuition of what *might* help your model.\n",
|
||||
"\n",
|
||||
"I say *might* on purpose because there's no guarantees.\n",
|
||||
"\n",
|
||||
"But generally, in light of [*The Bitter Lesson*](http://www.incompleteideas.net/IncIdeas/BitterLesson.html) (I've mentioned this twice now because it's an important essay in the world of AI), the bigger your model (more learnable parameters) and the more data you have (more opportunities to learn), the better the performance.\n",
|
||||
"\n",
|
||||
"However, when you're first approaching a machine learning problem: start small and if something works, scale it up.\n",
|
||||
"\n",
|
||||
"Your first batch of experiments should take no longer than a few seconds to a few minutes to run.\n",
|
||||
"\n",
|
||||
"The quicker you can experiment, the faster you can work out what *doesn't* work, in turn, the faster you can work out what *does* work.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"### 7.2 What experiments are we going to run?\n",
|
||||
"\n",
|
||||
"Our goal is to improve the model powering FoodVision Mini without it getting too big.\n",
|
||||
"\n",
|
||||
"In essence, our ideal model achieves a high level of accuracy (90%+) but doesn't take too long to train/performance inference.\n",
|
||||
"\n",
|
||||
"We've got plenty of options but how about we keep things simple?\n",
|
||||
"\n",
|
||||
"Let's try a combination of:\n",
|
||||
"1. A different amount of data (10% of Pizza, Steak, Sushi vs. 20%)\n",
|
||||
"2. A different model ([`torchvision.models.efficientnet_b0`](https://pytorch.org/vision/stable/generated/torchvision.models.efficientnet_b0.html#torchvision.models.efficientnet_b0) vs. [`torchvision.models.efficientnet_b2`](https://pytorch.org/vision/stable/generated/torchvision.models.efficientnet_b2.html#torchvision.models.efficientnet_b2))\n",
|
||||
"3. A different training time (5 epochs vs. 10 epochs)\n",
|
||||
"\n",
|
||||
"Breaking these down we get: \n",
|
||||
"\n",
|
||||
"| Experiment number | Training Dataset | Model (pretrained on ImageNet) | Number of epochs |\n",
|
||||
"| ----- | ----- | ----- | ----- |\n",
|
||||
"| 1 | Pizza, Steak, Sushi 10% percent | EfficientNetB0 | 5 |\n",
|
||||
"| 2 | Pizza, Steak, Sushi 10% percent | EfficientNetB2 | 5 | \n",
|
||||
@@ -939,50 +1069,41 @@
|
||||
"| 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",
|
||||
"Notice how we're slowly scaling things up. \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"
|
||||
"With each experiment we 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",
|
||||
"\n",
|
||||
"> **Note:** I want to be clear that there truly is no limit to amount of experiments you can run. What we've designed here is only a very small subset of options. However, you can't test *everything* so best to try a few things to begin with and then follow the ones which work the best.\n",
|
||||
">\n",
|
||||
"> And as a reminder, the datasets we're using are a subset of the Food101 dataset (3 classes, pizza, steak, suhsi, instead of 101) and 10% and 20% of the images rather than 100%. If our experiments work, we could start to run more on more data (though this will take longer to compute). You can see how the datasets were created via the [`04_custom_data_creation.ipynb` notebook](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/extras/04_custom_data_creation.ipynb). \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### TK - Load and prepare different datasets\n",
|
||||
"### TK - 7.3 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",
|
||||
"Before we start running our series of experiments, we need to make sure our datasets are ready.\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",
|
||||
"``` "
|
||||
"We'll need two forms of a training set:\n",
|
||||
"1. A training set with **10% of the data** of Food101 pizza, steak, sushi images (we've already created this above but we'll do it again for completeness).\n",
|
||||
"2. A training set with **20% of the data** of Food101 pizza, steak, sushi images.\n",
|
||||
"\n",
|
||||
"For consistency, all experiments will use the same testing dataset (the one from the 10% data split).\n",
|
||||
"\n",
|
||||
"We'll start by downloading the various datasets we need using the `download_data()` function we created earlier.\n",
|
||||
"\n",
|
||||
"Both datasets are available from the course GitHub:\n",
|
||||
"1. [Pizza, steak, sushi 10% training data](https://github.com/mrdbourke/pytorch-deep-learning/raw/main/data/pizza_steak_sushi.zip).\n",
|
||||
"2. [Pizza, steak, sushi 20% training data](https://github.com/mrdbourke/pytorch-deep-learning/raw/main/data/pizza_steak_sushi_20_percent.zip). "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from torchvision import transforms\n",
|
||||
"\n",
|
||||
"normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],\n",
|
||||
" std=[0.229, 0.224, 0.225])\n",
|
||||
"\n",
|
||||
"simple_transform = transforms.Compose([\n",
|
||||
" transforms.Resize((224, 224)),\n",
|
||||
" transforms.ToTensor(),\n",
|
||||
" normalize\n",
|
||||
"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 40,
|
||||
"execution_count": 64,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1004,17 +1125,79 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 41,
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"Data downloaded!\n",
|
||||
"\n",
|
||||
"Now let's setup the filepaths to data we'll be using for the different experiments.\n",
|
||||
"\n",
|
||||
"We'll create different training directory paths but we'll only need one testing directory path since all experiments will be using the same test dataset (the test dataset from pizza, steak, sushi 10%)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 65,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Training directory 10%: data/pizza_steak_sushi/train\n",
|
||||
"Training directory 20%: data/pizza_steak_sushi_20_percent/train\n",
|
||||
"Testing directory: data/pizza_steak_sushi/test\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Setup training directory paths\n",
|
||||
"train_dir_10_percent = data_10_percent_path / \"train\"\n",
|
||||
"train_dir_20_percent = data_20_percent_path / \"train\"\n",
|
||||
"\n",
|
||||
"# Setup testing directory paths (note: use the same test dataset for both to compare the results)\n",
|
||||
"test_dir = data_10_percent_path / \"test\""
|
||||
"test_dir = data_10_percent_path / \"test\"\n",
|
||||
"\n",
|
||||
"# Check the directories\n",
|
||||
"print(f\"Training directory 10%: {train_dir_10_percent}\")\n",
|
||||
"print(f\"Training directory 20%: {train_dir_20_percent}\")\n",
|
||||
"print(f\"Testing directory: {test_dir}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"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)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from torchvision import transforms\n",
|
||||
"\n",
|
||||
"# Create a transform to normalize data distribution to be inline with ImageNet\n",
|
||||
"normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], # values per colour channel [red, green, blue]\n",
|
||||
" std=[0.229, 0.224, 0.225]) # values per colour channel [red, green, blue]\n",
|
||||
"\n",
|
||||
"# Compose transforms into a pipeline\n",
|
||||
"simple_transform = transforms.Compose([\n",
|
||||
" transforms.Resize((224, 224)),\n",
|
||||
" transforms.ToTensor(),\n",
|
||||
" normalize\n",
|
||||
"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1063,7 +1246,9 @@
|
||||
"source": [
|
||||
"### TK Setup 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."
|
||||
"* **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",
|
||||
"\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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user