diff --git a/06_pytorch_transfer_learning_v2.ipynb b/06_pytorch_transfer_learning_v2.ipynb index 279db8e..8555670 100644 --- a/06_pytorch_transfer_learning_v2.ipynb +++ b/06_pytorch_transfer_learning_v2.ipynb @@ -166,37 +166,26 @@ }, { "cell_type": "code", - "execution_count": 1, - "id": "ff75d19e", + "execution_count": 2, + "id": "8ed820be", "metadata": {}, "outputs": [], "source": [ - "# # Nightly versions of torch and torchvision required\n", - "# !pip3 install -U --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "id": "8ed820be", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "torch version: 1.13.0.dev20220606 (should be 0.12+)\n", - "torchvision version: 0.14.0.dev20220606 (should be 0.13+)\n" - ] - } - ], - "source": [ - "# Check versions of torch and torchvision\n", - "import torch\n", - "import torchvision \n", - "\n", - "print(f\"torch version: {torch.__version__} (should be 0.12+)\") \n", - "print(f\"torchvision version: {torchvision.__version__} (should be 0.13+)\")" + "# For this notebook to run with updated APIs, we need torch 1.12+ and torchvision 0.13+\n", + "try:\n", + " import torch\n", + " import torchvision\n", + " assert int(torch.__version__.split(\".\")[1]) >= 12, \"torch version should be 1.12+\"\n", + " assert int(torchvision.__version__.split(\".\")[1]) >= 13, \"torchvision version should be 0.13+\"\n", + " print(f\"torch version: {torch.__version__}\")\n", + " print(f\"torchvision version: {torchvision.__version__}\")\n", + "except:\n", + " print(f\"[INFO] torch/torchvision versions not as required, installing nightly versions.\")\n", + " !pip3 install -U --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113\n", + " import torch\n", + " import torchvision\n", + " print(f\"torch version: {torch.__version__}\")\n", + " print(f\"torchvision version: {torchvision.__version__}\")" ] }, { @@ -206,6 +195,7 @@ "metadata": {}, "outputs": [], "source": [ + "# Continue with regular imports\n", "import matplotlib.pyplot as plt\n", "import torch\n", "import torchvision\n", diff --git a/07_pytorch_experiment_tracking_v2.ipynb b/07_pytorch_experiment_tracking_v2.ipynb index 04ff282..79f7351 100644 --- a/07_pytorch_experiment_tracking_v2.ipynb +++ b/07_pytorch_experiment_tracking_v2.ipynb @@ -128,47 +128,54 @@ "\n", "Let's start by download all of the modules we'll need for this section.\n", "\n", - "To save us writing extra code, we're going to be leveraging some of the Python scripts (such as `data_setup.py` and `engine.py`) we created in the previous section, [05. PyTorch Going Modular](https://www.learnpytorch.io/05_pytorch_going_modular/).\n", + "To save us writing extra code, we're going to be leveraging some of the Python scripts (such as `data_setup.py` and `engine.py`) we created in section, [05. PyTorch Going Modular](https://www.learnpytorch.io/05_pytorch_going_modular/).\n", "\n", "Specifically, we're going to download the [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular) directory from the `pytorch-deep-learning` repository (if we don't already have it).\n", "\n", "We'll also get the [`torchinfo`](https://github.com/TylerYep/torchinfo) package if it's not available. \n", "\n", - "`torchinfo` will help later on to give us a visual representation of our model." + "`torchinfo` will help later on to give us a visual representation of our model.\n", + "\n", + "And since we're using a newer version of the `torchvision` package (as of June 2022), we'll make sure we've got the latest versions." ] }, { "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "# TK - update this to be a try/except block so the nightly version is installed if necessary\n", - "# # Nightly versions of torch and torchvision required\n", - "# !pip3 install -U --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113" - ] - }, - { - "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "torch version: 1.13.0.dev20220606 (should be 0.12+)\n", - "torchvision version: 0.14.0.dev20220606 (should be 0.13+)\n" + "torch version: 1.13.0.dev20220606\n", + "torchvision version: 0.14.0.dev20220606\n" ] } ], "source": [ - "# Check versions of torch and torchvision\n", - "import torch\n", - "import torchvision \n", - "\n", - "print(f\"torch version: {torch.__version__} (should be 0.12+)\") \n", - "print(f\"torchvision version: {torchvision.__version__} (should be 0.13+)\")" + "# For this notebook to run with updated APIs, we need torch 1.12+ and torchvision 0.13+\n", + "try:\n", + " import torch\n", + " import torchvision\n", + " assert int(torch.__version__.split(\".\")[1]) >= 12, \"torch version should be 1.12+\"\n", + " assert int(torchvision.__version__.split(\".\")[1]) >= 13, \"torchvision version should be 0.13+\"\n", + " print(f\"torch version: {torch.__version__}\")\n", + " print(f\"torchvision version: {torchvision.__version__}\")\n", + "except:\n", + " print(f\"[INFO] torch/torchvision versions not as required, installing nightly versions.\")\n", + " !pip3 install -U --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113\n", + " import torch\n", + " import torchvision\n", + " print(f\"torch version: {torch.__version__}\")\n", + " print(f\"torchvision version: {torchvision.__version__}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "> **Note:** If you're using Google Colab, you may have to restart your runtime after running the above cell. After restarting, you can run the cell again and verify you've got the right versions of `torch` and `torchvision`." ] }, { @@ -177,6 +184,7 @@ "metadata": {}, "outputs": [], "source": [ + "# Continue with regular imports\n", "import matplotlib.pyplot as plt\n", "import torch\n", "import torchvision\n",