From d579fe0c2b6b0ac680b249431115ad6cffbeaf37 Mon Sep 17 00:00:00 2001 From: Heng Fang Date: Fri, 6 Dec 2024 14:46:01 +0100 Subject: [PATCH 1/7] update tutorial for transforms --- docs/tutorials/transforms.ipynb | 45 ++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/transforms.ipynb b/docs/tutorials/transforms.ipynb index 38a9b825bbf..0f4a4ef73cd 100644 --- a/docs/tutorials/transforms.ipynb +++ b/docs/tutorials/transforms.ipynb @@ -20,6 +20,13 @@ "# Transforms" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "_Written by: Adam J. Stewart, Ashwin Nair and Heng Fang_" + ] + }, { "cell_type": "markdown", "metadata": { @@ -408,7 +415,7 @@ "id": "p28C8cTGE3dP" }, "source": [ - "Transforms are able to operate across batches of samples and singular samples. This allows them to be used inside the dataset itself or externally, chained together with other transform operations using `nn.Sequential`. " + "`torchgeo.transforms` work seamlessly with both singular samples and batches of data. They can be applied within datasets or externally and combined with other transforms using `nn.Sequential`. Built for multispectral imagery, they are fully compatible with `torchvision.transforms` and `kornia.augmentation`." ] }, { @@ -429,13 +436,39 @@ "print(x.dtype, x.min(), x.max())" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Appending Indices with `torchgeo.transforms`\n", + "\n", + "`torchgeo.transforms` support appending indices to a specified channel dimension. The following transforms are available:\n", + "\n", + "- **AppendBNDVI**\n", + "- **AppendGBNDVI**\n", + "- **AppendGNDVI**\n", + "- **AppendGRNDVI**\n", + "- **AppendNBR**\n", + "- **AppendNDBI**\n", + "- **AppendNDRE**\n", + "- **AppendNDSI**\n", + "- **AppendNDVI**\n", + "- **AppendNDWI**\n", + "- **AppendNormalizedDifferenceIndex**\n", + "- **AppendRBNDVI**\n", + "- **AppendSWI**\n", + "- **AppendTriBandNormalizedDifferenceIndex**\n", + "\n", + "For detailed usage, refer to the [official documentation](https://torchgeo.readthedocs.io/en/stable/api/transforms.html)." + ] + }, { "cell_type": "markdown", "metadata": { "id": "KRjb-u0EEmDf" }, "source": [ - "Indices can also be computed on batches of images and appended as an additional band to the specified channel dimension. Notice how the number of channels increases from 13 -> 14." + "The following example shows how indices can be computed on batches of images and appended as an additional band to the specified channel dimension. Notice how the number of channels increases from 13 -> 14." ] }, { @@ -500,7 +533,9 @@ "id": "w4ZbjxPyHoiB" }, "source": [ - "It's even possible to chain indices along with augmentations from Kornia for a single callable during training." + "It's even possible to chain indices along with augmentations from Kornia for a single callable during training.\n", + "\n", + "Check out the documentation of Kornia's augmentations [here](https://kornia.readthedocs.io/en/latest/augmentation.html)." ] }, { @@ -515,6 +550,8 @@ }, "outputs": [], "source": [ + "# When using Kornia with a dictionary input, \n", + "# you must explicitly set data_keys=None during the creation of the augmentation pipeline.\n", "transforms = K.AugmentationSequential(\n", " MinMaxNormalize(mins, maxs),\n", " indices.AppendNDBI(index_swir=11, index_nir=7),\n", @@ -717,7 +754,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.6" } }, "nbformat": 4, From 8b00b92eab7a2f8096b5353dc40b2faadbfadbb8 Mon Sep 17 00:00:00 2001 From: Heng Fang Date: Fri, 6 Dec 2024 15:44:53 +0100 Subject: [PATCH 2/7] update tutorial for pretrained_weights --- docs/tutorials/pretrained_weights.ipynb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/pretrained_weights.ipynb b/docs/tutorials/pretrained_weights.ipynb index 0c2c4a0fc48..05c2cd0323f 100644 --- a/docs/tutorials/pretrained_weights.ipynb +++ b/docs/tutorials/pretrained_weights.ipynb @@ -19,6 +19,8 @@ "source": [ "# Pretrained Weights\n", "\n", + "_Written by: Adam J. Stewart and Heng Fang_\n", + "\n", "In this tutorial, we demonstrate some available pretrained weights in TorchGeo. The implementation follows torchvisions' recently introduced [Multi-Weight API](https://pytorch.org/blog/introducing-torchvision-new-multi-weight-support-api/). We will use the [EuroSAT](https://torchgeo.readthedocs.io/en/stable/api/datasets.html#eurosat) dataset throughout this tutorial. Specifically, a subset containing only 100 images.\n", "\n", "It's recommended to run this notebook on Google Colab if you don't have your own GPU. Click the \"Open in Colab\" button above to get started." @@ -147,9 +149,11 @@ "source": [ "## Weights\n", "\n", - "Available pretrained weights are listed on the model documentation [page](https://torchgeo.readthedocs.io/en/stable/api/models.html). While some weights only accept RGB channel input, some weights have been pretrained on Sentinel 2 imagery with 13 input channels and can hence prove useful for transfer learning tasks involving Sentinel 2 data.\n", + "Pretrained weights for `torchgeo.models` are available and sorted by satellite or sensor type: sensor-agnostic, Landsat, NAIP, Sentinel-1, and Sentinel-2. Refer to the model documentation page [page](https://torchgeo.readthedocs.io/en/stable/api/models.html#pretrained-weights) for a complete list of weights. Choose from the provided pre-trained weights based on your specific use case.\n", + "\n", + "While some weights only accept RGB channel input, some weights have been pretrained on Sentinel 2 imagery with 13 input channels and can hence prove useful for transfer learning tasks involving Sentinel 2 data.\n", "\n", - "To access these weights you can do the following:" + "To use these weights, you can load them as follows:" ] }, { @@ -169,7 +173,16 @@ "id": "EIpnXuXgrMOM" }, "source": [ - "This set of weights is a torchvision `WeightEnum` and holds information such as the download url link or additional meta data. TorchGeo takes care of the downloading and initialization of models with a desired set of weights. Given that EuroSAT is a classification dataset, we can use a `ClassificationTask` object that holds the model and optimizer object as well as the training logic." + "This set of weights is a torchvision `WeightEnum` and holds information such as the download url link or additional meta data. TorchGeo takes care of the downloading and initialization of models with a desired set of weights. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`torchgeo.trainers` provides specialized task classes that simplify training workflows for common geospatial tasks. Depending on your objective, you can select the appropriate trainer class, such as `ClassificationTask` for classification, `SegmentationTask` for semantic segmentation, or other task-specific trainers. Check the [documentation](https://torchgeo.readthedocs.io/en/stable/api/trainers.html) for more information.\n", + "\n", + "Given that EuroSAT is a classification dataset, we can use a `ClassificationTask` object that holds the model and optimizer object as well as the training logic." ] }, { @@ -495,7 +508,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8" + "version": "3.11.6" }, "vscode": { "interpreter": { From 82274336b901ab102a14bbd3737148706390f0ab Mon Sep 17 00:00:00 2001 From: Heng Fang Date: Fri, 6 Dec 2024 16:02:47 +0100 Subject: [PATCH 3/7] fix tutorial of transforms --- docs/tutorials/transforms.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/tutorials/transforms.ipynb b/docs/tutorials/transforms.ipynb index 0f4a4ef73cd..ea20e9e0e67 100644 --- a/docs/tutorials/transforms.ipynb +++ b/docs/tutorials/transforms.ipynb @@ -535,7 +535,9 @@ "source": [ "It's even possible to chain indices along with augmentations from Kornia for a single callable during training.\n", "\n", - "Check out the documentation of Kornia's augmentations [here](https://kornia.readthedocs.io/en/latest/augmentation.html)." + "Check out the documentation of Kornia's augmentations [here](https://kornia.readthedocs.io/en/latest/augmentation.html).\n", + "\n", + "When using Kornia with a dictionary input, you must explicitly set data_keys=None during the creation of the augmentation pipeline." ] }, { @@ -550,8 +552,6 @@ }, "outputs": [], "source": [ - "# When using Kornia with a dictionary input, \n", - "# you must explicitly set data_keys=None during the creation of the augmentation pipeline.\n", "transforms = K.AugmentationSequential(\n", " MinMaxNormalize(mins, maxs),\n", " indices.AppendNDBI(index_swir=11, index_nir=7),\n", From 74fcdfa9198eeba1463ebd16d6b2c6948dbc16f0 Mon Sep 17 00:00:00 2001 From: Heng Fang Date: Sat, 7 Dec 2024 16:48:24 +0100 Subject: [PATCH 4/7] solve Adam's reviews --- docs/tutorials/transforms.ipynb | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/docs/tutorials/transforms.ipynb b/docs/tutorials/transforms.ipynb index ea20e9e0e67..fe6a1a09a23 100644 --- a/docs/tutorials/transforms.ipynb +++ b/docs/tutorials/transforms.ipynb @@ -442,24 +442,9 @@ "source": [ "### Appending Indices with `torchgeo.transforms`\n", "\n", - "`torchgeo.transforms` support appending indices to a specified channel dimension. The following transforms are available:\n", + "`torchgeo.transforms` support appending indices to a specified channel dimension. For example, `torchgeo.transforms.AppendNormalizedDifferenceIndex` and `torchgeo.transforms.AppendTriBandNormalizedDifferenceIndex` append indices to the last dimension of the input tensor.\n", "\n", - "- **AppendBNDVI**\n", - "- **AppendGBNDVI**\n", - "- **AppendGNDVI**\n", - "- **AppendGRNDVI**\n", - "- **AppendNBR**\n", - "- **AppendNDBI**\n", - "- **AppendNDRE**\n", - "- **AppendNDSI**\n", - "- **AppendNDVI**\n", - "- **AppendNDWI**\n", - "- **AppendNormalizedDifferenceIndex**\n", - "- **AppendRBNDVI**\n", - "- **AppendSWI**\n", - "- **AppendTriBandNormalizedDifferenceIndex**\n", - "\n", - "For detailed usage, refer to the [official documentation](https://torchgeo.readthedocs.io/en/stable/api/transforms.html)." + "For detailed usage of all available transforms, refer to the [official documentation](https://torchgeo.readthedocs.io/en/stable/api/transforms.html)." ] }, { @@ -535,8 +520,6 @@ "source": [ "It's even possible to chain indices along with augmentations from Kornia for a single callable during training.\n", "\n", - "Check out the documentation of Kornia's augmentations [here](https://kornia.readthedocs.io/en/latest/augmentation.html).\n", - "\n", "When using Kornia with a dictionary input, you must explicitly set data_keys=None during the creation of the augmentation pipeline." ] }, @@ -726,6 +709,14 @@ "print(f\"Class Label: {dataset.classes[sample['label']]}\")\n", "image.resize((256, 256), resample=Image.BILINEAR)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Additional Reading\n", + "1. Documentation of Kornia's augmentations: https://kornia.readthedocs.io/en/latest/augmentation.html" + ] } ], "metadata": { From 5aed209758248628adaebddefb2cd2f1c502c2d4 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Sun, 8 Dec 2024 07:43:55 -0500 Subject: [PATCH 5/7] Change to original author --- docs/tutorials/pretrained_weights.ipynb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/tutorials/pretrained_weights.ipynb b/docs/tutorials/pretrained_weights.ipynb index 05c2cd0323f..3a7023f0ee9 100644 --- a/docs/tutorials/pretrained_weights.ipynb +++ b/docs/tutorials/pretrained_weights.ipynb @@ -1,14 +1,15 @@ { "cells": [ { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "id": "p63J-QmUrMN-" }, + "outputs": [], "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." + "# Copyright (c) Microsoft Corporation. All rights reserved.\n", + "# Licensed under the MIT License." ] }, { @@ -19,7 +20,7 @@ "source": [ "# Pretrained Weights\n", "\n", - "_Written by: Adam J. Stewart and Heng Fang_\n", + "_Written by: Nils Lehmann_\n", "\n", "In this tutorial, we demonstrate some available pretrained weights in TorchGeo. The implementation follows torchvisions' recently introduced [Multi-Weight API](https://pytorch.org/blog/introducing-torchvision-new-multi-weight-support-api/). We will use the [EuroSAT](https://torchgeo.readthedocs.io/en/stable/api/datasets.html#eurosat) dataset throughout this tutorial. Specifically, a subset containing only 100 images.\n", "\n", @@ -149,9 +150,9 @@ "source": [ "## Weights\n", "\n", - "Pretrained weights for `torchgeo.models` are available and sorted by satellite or sensor type: sensor-agnostic, Landsat, NAIP, Sentinel-1, and Sentinel-2. Refer to the model documentation page [page](https://torchgeo.readthedocs.io/en/stable/api/models.html#pretrained-weights) for a complete list of weights. Choose from the provided pre-trained weights based on your specific use case.\n", + "Pretrained weights for `torchgeo.models` are available and sorted by satellite or sensor type: sensor-agnostic, Landsat, NAIP, Sentinel-1, and Sentinel-2. Refer to the [model documentation](https://torchgeo.readthedocs.io/en/stable/api/models.html#pretrained-weights) for a complete list of weights. Choose from the provided pre-trained weights based on your specific use case.\n", "\n", - "While some weights only accept RGB channel input, some weights have been pretrained on Sentinel 2 imagery with 13 input channels and can hence prove useful for transfer learning tasks involving Sentinel 2 data.\n", + "While some weights only accept RGB channel input, some weights have been pretrained on Sentinel-2 imagery with 13 input channels and can hence prove useful for transfer learning tasks involving Sentinel-2 data.\n", "\n", "To use these weights, you can load them as follows:" ] @@ -180,9 +181,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "`torchgeo.trainers` provides specialized task classes that simplify training workflows for common geospatial tasks. Depending on your objective, you can select the appropriate trainer class, such as `ClassificationTask` for classification, `SegmentationTask` for semantic segmentation, or other task-specific trainers. Check the [documentation](https://torchgeo.readthedocs.io/en/stable/api/trainers.html) for more information.\n", + "`torchgeo.trainers` provides specialized task classes that simplify training workflows for common geospatial tasks. Depending on your objective, you can select the appropriate trainer class, such as `ClassificationTask` for classification, `SemanticSegmentationTask` for semantic segmentation, or other task-specific trainers. Check the [trainers documentation](https://torchgeo.readthedocs.io/en/stable/api/trainers.html) for more information.\n", "\n", - "Given that EuroSAT is a classification dataset, we can use a `ClassificationTask` object that holds the model and optimizer object as well as the training logic." + "Given that EuroSAT is a classification dataset, we can use a `ClassificationTask` object that holds the model and optimizer as well as the training logic." ] }, { @@ -508,7 +509,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.6" + "version": "3.13.0" }, "vscode": { "interpreter": { @@ -517,5 +518,5 @@ } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } From 22e794eb94364c2a9d638cf08a49c68624ca0baf Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Sun, 8 Dec 2024 07:52:58 -0500 Subject: [PATCH 6/7] Change to original author, add more readings --- docs/tutorials/transforms.ipynb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/tutorials/transforms.ipynb b/docs/tutorials/transforms.ipynb index fe6a1a09a23..e53058f20a9 100644 --- a/docs/tutorials/transforms.ipynb +++ b/docs/tutorials/transforms.ipynb @@ -1,14 +1,15 @@ { "cells": [ { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "id": "DYndcZst_kdr" }, + "outputs": [], "source": [ - "Copyright (c) Microsoft Corporation. All rights reserved.\n", - "\n", - "Licensed under the MIT License." + "# Copyright (c) Microsoft Corporation. All rights reserved.\n", + "# Licensed under the MIT License." ] }, { @@ -24,7 +25,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "_Written by: Adam J. Stewart, Ashwin Nair and Heng Fang_" + "_Written by: Isaac A. Corley_" ] }, { @@ -440,11 +441,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Appending Indices with `torchgeo.transforms`\n", + "### Appending Indices\n", "\n", - "`torchgeo.transforms` support appending indices to a specified channel dimension. For example, `torchgeo.transforms.AppendNormalizedDifferenceIndex` and `torchgeo.transforms.AppendTriBandNormalizedDifferenceIndex` append indices to the last dimension of the input tensor.\n", + "`torchgeo.transforms` support appending indices to a specified channel dimension.\n", "\n", - "For detailed usage of all available transforms, refer to the [official documentation](https://torchgeo.readthedocs.io/en/stable/api/transforms.html)." + "For detailed usage of all available transforms, refer to the [transforms documentation](https://torchgeo.readthedocs.io/en/stable/api/transforms.html)." ] }, { @@ -715,7 +716,11 @@ "metadata": {}, "source": [ "## Additional Reading\n", - "1. Documentation of Kornia's augmentations: https://kornia.readthedocs.io/en/latest/augmentation.html" + "\n", + "To learn more about preprocessing and data augmentation transforms, the following external resources may be helpful:\n", + "\n", + "* [Kornia augmentations](https://kornia.readthedocs.io/en/latest/augmentation.html)\n", + "* [torchvision transforms](https://pytorch.org/vision/main/transforms.html)" ] } ], @@ -745,9 +750,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.6" + "version": "3.13.0" } }, "nbformat": 4, - "nbformat_minor": 0 + "nbformat_minor": 4 } From c51af12921b21c5a087b6cd191cf1360a6c5aee9 Mon Sep 17 00:00:00 2001 From: "Adam J. Stewart" Date: Sun, 8 Dec 2024 07:54:13 -0500 Subject: [PATCH 7/7] Code formatting --- docs/tutorials/transforms.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/transforms.ipynb b/docs/tutorials/transforms.ipynb index e53058f20a9..42a16e26e24 100644 --- a/docs/tutorials/transforms.ipynb +++ b/docs/tutorials/transforms.ipynb @@ -521,7 +521,7 @@ "source": [ "It's even possible to chain indices along with augmentations from Kornia for a single callable during training.\n", "\n", - "When using Kornia with a dictionary input, you must explicitly set data_keys=None during the creation of the augmentation pipeline." + "When using Kornia with a dictionary input, you must explicitly set `data_keys=None` during the creation of the augmentation pipeline." ] }, {