We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Landcover.ai download link
It looks like the landcover.ai domain name expired (breaking our download). The dataset is now hosted at https://landcover.ai.linuxpolska.com/.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torchgeo/datasets/landcoverai.py`
Content:
```
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
3 
4 """LandCover.ai dataset."""
5 
6 import glob
7 import hashlib
8 import os
9 from functools import lru_cache
10 from typing import Callable, Dict, Optional
11 
12 import matplotlib.pyplot as plt
13 import numpy as np
14 import torch
15 from matplotlib.colors import ListedColormap
16 from PIL import Image
17 from torch import Tensor
18 
19 from .geo import VisionDataset
20 from .utils import download_url, extract_archive, working_dir
21 
22 
23 class LandCoverAI(VisionDataset):
24     r"""LandCover.ai dataset.
25 
26     The `LandCover.ai <https://landcover.ai/>`_ (Land Cover from Aerial Imagery)
27     dataset is a dataset for automatic mapping of buildings, woodlands, water and
28     roads from aerial images. This implementation is specifically for Version 1 of
29     Landcover.ai.
30 
31     Dataset features:
32 
33     * land cover from Poland, Central Europe
34     * three spectral bands - RGB
35     * 33 orthophotos with 25 cm per pixel resolution (~9000x9500 px)
36     * 8 orthophotos with 50 cm per pixel resolution (~4200x4700 px)
37     * total area of 216.27 km\ :sup:`2`
38 
39     Dataset format:
40 
41     * rasters are three-channel GeoTiffs with EPSG:2180 spatial reference system
42     * masks are single-channel GeoTiffs with EPSG:2180 spatial reference system
43 
44     Dataset classes:
45 
46     1. building (1.85 km\ :sup:`2`\ )
47     2. woodland (72.02 km\ :sup:`2`\ )
48     3. water (13.15 km\ :sup:`2`\ )
49     4. road (3.5 km\ :sup:`2`\ )
50 
51     If you use this dataset in your research, please cite the following paper:
52 
53     * https://arxiv.org/abs/2005.02264v3
54 
55     .. note::
56 
57        This dataset requires the following additional library to be installed:
58 
59        * `opencv-python <https://pypi.org/project/opencv-python/>`_ to generate
60          the train/val/test split
61     """
62 
63     url = "https://landcover.ai/download/landcover.ai.v1.zip"
64     filename = "landcover.ai.v1.zip"
65     md5 = "3268c89070e8734b4e91d531c0617e03"
66     sha256 = "15ee4ca9e3fd187957addfa8f0d74ac31bc928a966f76926e11b3c33ea76daa1"
67     classes = ["Background", "Building", "Woodland", "Water", "Road"]
68     cmap = ListedColormap(
69         [
70             [0.63921569, 1.0, 0.45098039],
71             [0.61176471, 0.61176471, 0.61176471],
72             [0.14901961, 0.45098039, 0.0],
73             [0.0, 0.77254902, 1.0],
74             [0.0, 0.0, 0.0],
75         ]
76     )
77 
78     def __init__(
79         self,
80         root: str = "data",
81         split: str = "train",
82         transforms: Optional[Callable[[Dict[str, Tensor]], Dict[str, Tensor]]] = None,
83         download: bool = False,
84         checksum: bool = False,
85     ) -> None:
86         """Initialize a new LandCover.ai dataset instance.
87 
88         Args:
89             root: root directory where dataset can be found
90             split: one of "train", "val", or "test"
91             transforms: a function/transform that takes input sample and its target as
92                 entry and returns a transformed version
93             download: if True, download dataset and store it in the root directory
94             checksum: if True, check the MD5 of the downloaded files (may be slow)
95 
96         Raises:
97             AssertionError: if ``split`` argument is invalid
98             RuntimeError: if ``download=False`` and data is not found, or checksums
99                 don't match
100         """
101         assert split in ["train", "val", "test"]
102 
103         self.root = root
104         self.split = split
105         self.transforms = transforms
106         self.download = download
107         self.checksum = checksum
108 
109         self._verify()
110 
111         with open(os.path.join(self.root, split + ".txt")) as f:
112             self.ids = f.readlines()
113 
114     def __getitem__(self, index: int) -> Dict[str, Tensor]:
115         """Return an index within the dataset.
116 
117         Args:
118             index: index to return
119 
120         Returns:
121             data and label at that index
122         """
123         id_ = self.ids[index].rstrip()
124         sample = {"image": self._load_image(id_), "mask": self._load_target(id_)}
125 
126         if self.transforms is not None:
127             sample = self.transforms(sample)
128 
129         return sample
130 
131     def __len__(self) -> int:
132         """Return the number of data points in the dataset.
133 
134         Returns:
135             length of the dataset
136         """
137         return len(self.ids)
138 
139     @lru_cache()
140     def _load_image(self, id_: str) -> Tensor:
141         """Load a single image.
142 
143         Args:
144             id_: unique ID of the image
145 
146         Returns:
147             the image
148         """
149         filename = os.path.join(self.root, "output", id_ + ".jpg")
150         with Image.open(filename) as img:
151             array: "np.typing.NDArray[np.int_]" = np.array(img)
152             tensor = torch.from_numpy(array)
153             # Convert from HxWxC to CxHxW
154             tensor = tensor.permute((2, 0, 1))
155             return tensor
156 
157     @lru_cache()
158     def _load_target(self, id_: str) -> Tensor:
159         """Load the target mask for a single image.
160 
161         Args:
162             id_: unique ID of the image
163 
164         Returns:
165             the target mask
166         """
167         filename = os.path.join(self.root, "output", id_ + "_m.png")
168         with Image.open(filename) as img:
169             array: "np.typing.NDArray[np.int_]" = np.array(img.convert("L"))
170             tensor = torch.from_numpy(array)
171             return tensor
172 
173     def _verify(self) -> None:
174         """Verify the integrity of the dataset.
175 
176         Raises:
177             RuntimeError: if ``download=False`` but dataset is missing or checksum fails
178         """
179         # Check if the extracted files already exist
180         jpg = os.path.join(self.root, "output", "*_*.jpg")
181         png = os.path.join(self.root, "output", "*_*_m.png")
182         if glob.glob(jpg) and glob.glob(png):
183             return
184 
185         # Check if the zip file has already been downloaded
186         pathname = os.path.join(self.root, self.filename)
187         if os.path.exists(pathname):
188             self._extract()
189             return
190 
191         # Check if the user requested to download the dataset
192         if not self.download:
193             raise RuntimeError(
194                 f"Dataset not found in `root={self.root}` and `download=False`, "
195                 "either specify a different `root` directory or use `download=True` "
196                 "to automaticaly download the dataset."
197             )
198 
199         # Download the dataset
200         self._download()
201         self._extract()
202 
203     def _download(self) -> None:
204         """Download the dataset."""
205         download_url(self.url, self.root, md5=self.md5 if self.checksum else None)
206 
207     def _extract(self) -> None:
208         """Extract the dataset.
209 
210         Raises:
211             AssertionError: if the checksum of split.py does not match
212         """
213         extract_archive(os.path.join(self.root, self.filename))
214 
215         # Generate train/val/test splits
216         # Always check the sha256 of this file before executing
217         # to avoid malicious code injection
218         with working_dir(self.root):
219             with open("split.py") as f:
220                 split = f.read().encode("utf-8")
221                 assert hashlib.sha256(split).hexdigest() == self.sha256
222                 exec(split)
223 
224     def plot(
225         self,
226         sample: Dict[str, Tensor],
227         show_titles: bool = True,
228         suptitle: Optional[str] = None,
229     ) -> plt.Figure:
230         """Plot a sample from the dataset.
231 
232         Args:
233             sample: a sample returned by :meth:`__getitem__`
234             show_titles: flag indicating whether to show titles above each panel
235             suptitle: optional string to use as a suptitle
236 
237         Returns:
238             a matplotlib Figure with the rendered sample
239 
240         .. versionadded:: 0.2
241         """
242         image = np.rollaxis(sample["image"].numpy(), 0, 3)
243         mask = sample["mask"].numpy()
244 
245         num_panels = 2
246         showing_predictions = "prediction" in sample
247         if showing_predictions:
248             predictions = sample["prediction"].numpy()
249             num_panels += 1
250 
251         fig, axs = plt.subplots(1, num_panels, figsize=(num_panels * 4, 5))
252         axs[0].imshow(image)
253         axs[0].axis("off")
254         axs[1].imshow(mask, vmin=0, vmax=4, cmap=self.cmap, interpolation="none")
255         axs[1].axis("off")
256         if show_titles:
257             axs[0].set_title("Image")
258             axs[1].set_title("Mask")
259 
260         if showing_predictions:
261             axs[2].imshow(
262                 predictions, vmin=0, vmax=4, cmap=self.cmap, interpolation="none"
263             )
264             axs[2].axis("off")
265             if show_titles:
266                 axs[2].set_title("Predictions")
267 
268         if suptitle is not None:
269             plt.suptitle(suptitle)
270         return fig
271
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torchgeo/datasets/landcoverai.py b/torchgeo/datasets/landcoverai.py
--- a/torchgeo/datasets/landcoverai.py
+++ b/torchgeo/datasets/landcoverai.py
@@ -60,7 +60,7 @@
          the train/val/test split
     """
 
-    url = "https://landcover.ai/download/landcover.ai.v1.zip"
+    url = "https://landcover.ai.linuxpolska.com/download/landcover.ai.v1.zip"
     filename = "landcover.ai.v1.zip"
     md5 = "3268c89070e8734b4e91d531c0617e03"
     sha256 = "15ee4ca9e3fd187957addfa8f0d74ac31bc928a966f76926e11b3c33ea76daa1"

{"golden_diff": "diff --git a/torchgeo/datasets/landcoverai.py b/torchgeo/datasets/landcoverai.py\n--- a/torchgeo/datasets/landcoverai.py\n+++ b/torchgeo/datasets/landcoverai.py\n@@ -60,7 +60,7 @@\n          the train/val/test split\n     \"\"\"\n \n-    url = \"https://landcover.ai/download/landcover.ai.v1.zip\"\n+    url = \"https://landcover.ai.linuxpolska.com/download/landcover.ai.v1.zip\"\n     filename = \"landcover.ai.v1.zip\"\n     md5 = \"3268c89070e8734b4e91d531c0617e03\"\n     sha256 = \"15ee4ca9e3fd187957addfa8f0d74ac31bc928a966f76926e11b3c33ea76daa1\"\n", "issue": "Landcover.ai download link\nIt looks like the landcover.ai domain name expired (breaking our download). The dataset is now hosted at https://landcover.ai.linuxpolska.com/.\n", "before_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n\n\"\"\"LandCover.ai dataset.\"\"\"\n\nimport glob\nimport hashlib\nimport os\nfrom functools import lru_cache\nfrom typing import Callable, Dict, Optional\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport torch\nfrom matplotlib.colors import ListedColormap\nfrom PIL import Image\nfrom torch import Tensor\n\nfrom .geo import VisionDataset\nfrom .utils import download_url, extract_archive, working_dir\n\n\nclass LandCoverAI(VisionDataset):\n    r\"\"\"LandCover.ai dataset.\n\n    The `LandCover.ai <https://landcover.ai/>`_ (Land Cover from Aerial Imagery)\n    dataset is a dataset for automatic mapping of buildings, woodlands, water and\n    roads from aerial images. This implementation is specifically for Version 1 of\n    Landcover.ai.\n\n    Dataset features:\n\n    * land cover from Poland, Central Europe\n    * three spectral bands - RGB\n    * 33 orthophotos with 25 cm per pixel resolution (~9000x9500 px)\n    * 8 orthophotos with 50 cm per pixel resolution (~4200x4700 px)\n    * total area of 216.27 km\\ :sup:`2`\n\n    Dataset format:\n\n    * rasters are three-channel GeoTiffs with EPSG:2180 spatial reference system\n    * masks are single-channel GeoTiffs with EPSG:2180 spatial reference system\n\n    Dataset classes:\n\n    1. building (1.85 km\\ :sup:`2`\\ )\n    2. woodland (72.02 km\\ :sup:`2`\\ )\n    3. water (13.15 km\\ :sup:`2`\\ )\n    4. road (3.5 km\\ :sup:`2`\\ )\n\n    If you use this dataset in your research, please cite the following paper:\n\n    * https://arxiv.org/abs/2005.02264v3\n\n    .. note::\n\n       This dataset requires the following additional library to be installed:\n\n       * `opencv-python <https://pypi.org/project/opencv-python/>`_ to generate\n         the train/val/test split\n    \"\"\"\n\n    url = \"https://landcover.ai/download/landcover.ai.v1.zip\"\n    filename = \"landcover.ai.v1.zip\"\n    md5 = \"3268c89070e8734b4e91d531c0617e03\"\n    sha256 = \"15ee4ca9e3fd187957addfa8f0d74ac31bc928a966f76926e11b3c33ea76daa1\"\n    classes = [\"Background\", \"Building\", \"Woodland\", \"Water\", \"Road\"]\n    cmap = ListedColormap(\n        [\n            [0.63921569, 1.0, 0.45098039],\n            [0.61176471, 0.61176471, 0.61176471],\n            [0.14901961, 0.45098039, 0.0],\n            [0.0, 0.77254902, 1.0],\n            [0.0, 0.0, 0.0],\n        ]\n    )\n\n    def __init__(\n        self,\n        root: str = \"data\",\n        split: str = \"train\",\n        transforms: Optional[Callable[[Dict[str, Tensor]], Dict[str, Tensor]]] = None,\n        download: bool = False,\n        checksum: bool = False,\n    ) -> None:\n        \"\"\"Initialize a new LandCover.ai dataset instance.\n\n        Args:\n            root: root directory where dataset can be found\n            split: one of \"train\", \"val\", or \"test\"\n            transforms: a function/transform that takes input sample and its target as\n                entry and returns a transformed version\n            download: if True, download dataset and store it in the root directory\n            checksum: if True, check the MD5 of the downloaded files (may be slow)\n\n        Raises:\n            AssertionError: if ``split`` argument is invalid\n            RuntimeError: if ``download=False`` and data is not found, or checksums\n                don't match\n        \"\"\"\n        assert split in [\"train\", \"val\", \"test\"]\n\n        self.root = root\n        self.split = split\n        self.transforms = transforms\n        self.download = download\n        self.checksum = checksum\n\n        self._verify()\n\n        with open(os.path.join(self.root, split + \".txt\")) as f:\n            self.ids = f.readlines()\n\n    def __getitem__(self, index: int) -> Dict[str, Tensor]:\n        \"\"\"Return an index within the dataset.\n\n        Args:\n            index: index to return\n\n        Returns:\n            data and label at that index\n        \"\"\"\n        id_ = self.ids[index].rstrip()\n        sample = {\"image\": self._load_image(id_), \"mask\": self._load_target(id_)}\n\n        if self.transforms is not None:\n            sample = self.transforms(sample)\n\n        return sample\n\n    def __len__(self) -> int:\n        \"\"\"Return the number of data points in the dataset.\n\n        Returns:\n            length of the dataset\n        \"\"\"\n        return len(self.ids)\n\n    @lru_cache()\n    def _load_image(self, id_: str) -> Tensor:\n        \"\"\"Load a single image.\n\n        Args:\n            id_: unique ID of the image\n\n        Returns:\n            the image\n        \"\"\"\n        filename = os.path.join(self.root, \"output\", id_ + \".jpg\")\n        with Image.open(filename) as img:\n            array: \"np.typing.NDArray[np.int_]\" = np.array(img)\n            tensor = torch.from_numpy(array)\n            # Convert from HxWxC to CxHxW\n            tensor = tensor.permute((2, 0, 1))\n            return tensor\n\n    @lru_cache()\n    def _load_target(self, id_: str) -> Tensor:\n        \"\"\"Load the target mask for a single image.\n\n        Args:\n            id_: unique ID of the image\n\n        Returns:\n            the target mask\n        \"\"\"\n        filename = os.path.join(self.root, \"output\", id_ + \"_m.png\")\n        with Image.open(filename) as img:\n            array: \"np.typing.NDArray[np.int_]\" = np.array(img.convert(\"L\"))\n            tensor = torch.from_numpy(array)\n            return tensor\n\n    def _verify(self) -> None:\n        \"\"\"Verify the integrity of the dataset.\n\n        Raises:\n            RuntimeError: if ``download=False`` but dataset is missing or checksum fails\n        \"\"\"\n        # Check if the extracted files already exist\n        jpg = os.path.join(self.root, \"output\", \"*_*.jpg\")\n        png = os.path.join(self.root, \"output\", \"*_*_m.png\")\n        if glob.glob(jpg) and glob.glob(png):\n            return\n\n        # Check if the zip file has already been downloaded\n        pathname = os.path.join(self.root, self.filename)\n        if os.path.exists(pathname):\n            self._extract()\n            return\n\n        # Check if the user requested to download the dataset\n        if not self.download:\n            raise RuntimeError(\n                f\"Dataset not found in `root={self.root}` and `download=False`, \"\n                \"either specify a different `root` directory or use `download=True` \"\n                \"to automaticaly download the dataset.\"\n            )\n\n        # Download the dataset\n        self._download()\n        self._extract()\n\n    def _download(self) -> None:\n        \"\"\"Download the dataset.\"\"\"\n        download_url(self.url, self.root, md5=self.md5 if self.checksum else None)\n\n    def _extract(self) -> None:\n        \"\"\"Extract the dataset.\n\n        Raises:\n            AssertionError: if the checksum of split.py does not match\n        \"\"\"\n        extract_archive(os.path.join(self.root, self.filename))\n\n        # Generate train/val/test splits\n        # Always check the sha256 of this file before executing\n        # to avoid malicious code injection\n        with working_dir(self.root):\n            with open(\"split.py\") as f:\n                split = f.read().encode(\"utf-8\")\n                assert hashlib.sha256(split).hexdigest() == self.sha256\n                exec(split)\n\n    def plot(\n        self,\n        sample: Dict[str, Tensor],\n        show_titles: bool = True,\n        suptitle: Optional[str] = None,\n    ) -> plt.Figure:\n        \"\"\"Plot a sample from the dataset.\n\n        Args:\n            sample: a sample returned by :meth:`__getitem__`\n            show_titles: flag indicating whether to show titles above each panel\n            suptitle: optional string to use as a suptitle\n\n        Returns:\n            a matplotlib Figure with the rendered sample\n\n        .. versionadded:: 0.2\n        \"\"\"\n        image = np.rollaxis(sample[\"image\"].numpy(), 0, 3)\n        mask = sample[\"mask\"].numpy()\n\n        num_panels = 2\n        showing_predictions = \"prediction\" in sample\n        if showing_predictions:\n            predictions = sample[\"prediction\"].numpy()\n            num_panels += 1\n\n        fig, axs = plt.subplots(1, num_panels, figsize=(num_panels * 4, 5))\n        axs[0].imshow(image)\n        axs[0].axis(\"off\")\n        axs[1].imshow(mask, vmin=0, vmax=4, cmap=self.cmap, interpolation=\"none\")\n        axs[1].axis(\"off\")\n        if show_titles:\n            axs[0].set_title(\"Image\")\n            axs[1].set_title(\"Mask\")\n\n        if showing_predictions:\n            axs[2].imshow(\n                predictions, vmin=0, vmax=4, cmap=self.cmap, interpolation=\"none\"\n            )\n            axs[2].axis(\"off\")\n            if show_titles:\n                axs[2].set_title(\"Predictions\")\n\n        if suptitle is not None:\n            plt.suptitle(suptitle)\n        return fig\n", "path": "torchgeo/datasets/landcoverai.py"}], "after_files": [{"content": "# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License.\n\n\"\"\"LandCover.ai dataset.\"\"\"\n\nimport glob\nimport hashlib\nimport os\nfrom functools import lru_cache\nfrom typing import Callable, Dict, Optional\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport torch\nfrom matplotlib.colors import ListedColormap\nfrom PIL import Image\nfrom torch import Tensor\n\nfrom .geo import VisionDataset\nfrom .utils import download_url, extract_archive, working_dir\n\n\nclass LandCoverAI(VisionDataset):\n    r\"\"\"LandCover.ai dataset.\n\n    The `LandCover.ai <https://landcover.ai/>`_ (Land Cover from Aerial Imagery)\n    dataset is a dataset for automatic mapping of buildings, woodlands, water and\n    roads from aerial images. This implementation is specifically for Version 1 of\n    Landcover.ai.\n\n    Dataset features:\n\n    * land cover from Poland, Central Europe\n    * three spectral bands - RGB\n    * 33 orthophotos with 25 cm per pixel resolution (~9000x9500 px)\n    * 8 orthophotos with 50 cm per pixel resolution (~4200x4700 px)\n    * total area of 216.27 km\\ :sup:`2`\n\n    Dataset format:\n\n    * rasters are three-channel GeoTiffs with EPSG:2180 spatial reference system\n    * masks are single-channel GeoTiffs with EPSG:2180 spatial reference system\n\n    Dataset classes:\n\n    1. building (1.85 km\\ :sup:`2`\\ )\n    2. woodland (72.02 km\\ :sup:`2`\\ )\n    3. water (13.15 km\\ :sup:`2`\\ )\n    4. road (3.5 km\\ :sup:`2`\\ )\n\n    If you use this dataset in your research, please cite the following paper:\n\n    * https://arxiv.org/abs/2005.02264v3\n\n    .. note::\n\n       This dataset requires the following additional library to be installed:\n\n       * `opencv-python <https://pypi.org/project/opencv-python/>`_ to generate\n         the train/val/test split\n    \"\"\"\n\n    url = \"https://landcover.ai.linuxpolska.com/download/landcover.ai.v1.zip\"\n    filename = \"landcover.ai.v1.zip\"\n    md5 = \"3268c89070e8734b4e91d531c0617e03\"\n    sha256 = \"15ee4ca9e3fd187957addfa8f0d74ac31bc928a966f76926e11b3c33ea76daa1\"\n    classes = [\"Background\", \"Building\", \"Woodland\", \"Water\", \"Road\"]\n    cmap = ListedColormap(\n        [\n            [0.63921569, 1.0, 0.45098039],\n            [0.61176471, 0.61176471, 0.61176471],\n            [0.14901961, 0.45098039, 0.0],\n            [0.0, 0.77254902, 1.0],\n            [0.0, 0.0, 0.0],\n        ]\n    )\n\n    def __init__(\n        self,\n        root: str = \"data\",\n        split: str = \"train\",\n        transforms: Optional[Callable[[Dict[str, Tensor]], Dict[str, Tensor]]] = None,\n        download: bool = False,\n        checksum: bool = False,\n    ) -> None:\n        \"\"\"Initialize a new LandCover.ai dataset instance.\n\n        Args:\n            root: root directory where dataset can be found\n            split: one of \"train\", \"val\", or \"test\"\n            transforms: a function/transform that takes input sample and its target as\n                entry and returns a transformed version\n            download: if True, download dataset and store it in the root directory\n            checksum: if True, check the MD5 of the downloaded files (may be slow)\n\n        Raises:\n            AssertionError: if ``split`` argument is invalid\n            RuntimeError: if ``download=False`` and data is not found, or checksums\n                don't match\n        \"\"\"\n        assert split in [\"train\", \"val\", \"test\"]\n\n        self.root = root\n        self.split = split\n        self.transforms = transforms\n        self.download = download\n        self.checksum = checksum\n\n        self._verify()\n\n        with open(os.path.join(self.root, split + \".txt\")) as f:\n            self.ids = f.readlines()\n\n    def __getitem__(self, index: int) -> Dict[str, Tensor]:\n        \"\"\"Return an index within the dataset.\n\n        Args:\n            index: index to return\n\n        Returns:\n            data and label at that index\n        \"\"\"\n        id_ = self.ids[index].rstrip()\n        sample = {\"image\": self._load_image(id_), \"mask\": self._load_target(id_)}\n\n        if self.transforms is not None:\n            sample = self.transforms(sample)\n\n        return sample\n\n    def __len__(self) -> int:\n        \"\"\"Return the number of data points in the dataset.\n\n        Returns:\n            length of the dataset\n        \"\"\"\n        return len(self.ids)\n\n    @lru_cache()\n    def _load_image(self, id_: str) -> Tensor:\n        \"\"\"Load a single image.\n\n        Args:\n            id_: unique ID of the image\n\n        Returns:\n            the image\n        \"\"\"\n        filename = os.path.join(self.root, \"output\", id_ + \".jpg\")\n        with Image.open(filename) as img:\n            array: \"np.typing.NDArray[np.int_]\" = np.array(img)\n            tensor = torch.from_numpy(array)\n            # Convert from HxWxC to CxHxW\n            tensor = tensor.permute((2, 0, 1))\n            return tensor\n\n    @lru_cache()\n    def _load_target(self, id_: str) -> Tensor:\n        \"\"\"Load the target mask for a single image.\n\n        Args:\n            id_: unique ID of the image\n\n        Returns:\n            the target mask\n        \"\"\"\n        filename = os.path.join(self.root, \"output\", id_ + \"_m.png\")\n        with Image.open(filename) as img:\n            array: \"np.typing.NDArray[np.int_]\" = np.array(img.convert(\"L\"))\n            tensor = torch.from_numpy(array)\n            return tensor\n\n    def _verify(self) -> None:\n        \"\"\"Verify the integrity of the dataset.\n\n        Raises:\n            RuntimeError: if ``download=False`` but dataset is missing or checksum fails\n        \"\"\"\n        # Check if the extracted files already exist\n        jpg = os.path.join(self.root, \"output\", \"*_*.jpg\")\n        png = os.path.join(self.root, \"output\", \"*_*_m.png\")\n        if glob.glob(jpg) and glob.glob(png):\n            return\n\n        # Check if the zip file has already been downloaded\n        pathname = os.path.join(self.root, self.filename)\n        if os.path.exists(pathname):\n            self._extract()\n            return\n\n        # Check if the user requested to download the dataset\n        if not self.download:\n            raise RuntimeError(\n                f\"Dataset not found in `root={self.root}` and `download=False`, \"\n                \"either specify a different `root` directory or use `download=True` \"\n                \"to automaticaly download the dataset.\"\n            )\n\n        # Download the dataset\n        self._download()\n        self._extract()\n\n    def _download(self) -> None:\n        \"\"\"Download the dataset.\"\"\"\n        download_url(self.url, self.root, md5=self.md5 if self.checksum else None)\n\n    def _extract(self) -> None:\n        \"\"\"Extract the dataset.\n\n        Raises:\n            AssertionError: if the checksum of split.py does not match\n        \"\"\"\n        extract_archive(os.path.join(self.root, self.filename))\n\n        # Generate train/val/test splits\n        # Always check the sha256 of this file before executing\n        # to avoid malicious code injection\n        with working_dir(self.root):\n            with open(\"split.py\") as f:\n                split = f.read().encode(\"utf-8\")\n                assert hashlib.sha256(split).hexdigest() == self.sha256\n                exec(split)\n\n    def plot(\n        self,\n        sample: Dict[str, Tensor],\n        show_titles: bool = True,\n        suptitle: Optional[str] = None,\n    ) -> plt.Figure:\n        \"\"\"Plot a sample from the dataset.\n\n        Args:\n            sample: a sample returned by :meth:`__getitem__`\n            show_titles: flag indicating whether to show titles above each panel\n            suptitle: optional string to use as a suptitle\n\n        Returns:\n            a matplotlib Figure with the rendered sample\n\n        .. versionadded:: 0.2\n        \"\"\"\n        image = np.rollaxis(sample[\"image\"].numpy(), 0, 3)\n        mask = sample[\"mask\"].numpy()\n\n        num_panels = 2\n        showing_predictions = \"prediction\" in sample\n        if showing_predictions:\n            predictions = sample[\"prediction\"].numpy()\n            num_panels += 1\n\n        fig, axs = plt.subplots(1, num_panels, figsize=(num_panels * 4, 5))\n        axs[0].imshow(image)\n        axs[0].axis(\"off\")\n        axs[1].imshow(mask, vmin=0, vmax=4, cmap=self.cmap, interpolation=\"none\")\n        axs[1].axis(\"off\")\n        if show_titles:\n            axs[0].set_title(\"Image\")\n            axs[1].set_title(\"Mask\")\n\n        if showing_predictions:\n            axs[2].imshow(\n                predictions, vmin=0, vmax=4, cmap=self.cmap, interpolation=\"none\"\n            )\n            axs[2].axis(\"off\")\n            if show_titles:\n                axs[2].set_title(\"Predictions\")\n\n        if suptitle is not None:\n            plt.suptitle(suptitle)\n        return fig\n", "path": "torchgeo/datasets/landcoverai.py"}]}