We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Predict zero for nodata pixels on semantic segmentation


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `rastervision/task/semantic_segmentation.py`
Content:
```
1 from typing import List
2 import logging
3 
4 import numpy as np
5 
6 from .task import Task
7 from rastervision.core.box import Box
8 from rastervision.data.scene import Scene
9 from rastervision.data.label import SemanticSegmentationLabels
10 
11 log = logging.getLogger(__name__)
12 
13 
14 def get_random_sample_train_windows(label_store, chip_size, class_map, extent,
15                                     chip_options, filter_windows):
16     prob = chip_options.negative_survival_probability
17     target_count_threshold = chip_options.target_count_threshold
18     target_classes = chip_options.target_classes
19     chips_per_scene = chip_options.chips_per_scene
20 
21     if not target_classes:
22         all_class_ids = [item.id for item in class_map.get_items()]
23         target_classes = all_class_ids
24 
25     windows = []
26     attempts = 0
27     while (attempts < chips_per_scene):
28         candidate_window = extent.make_random_square(chip_size)
29         if not filter_windows([candidate_window]):
30             continue
31         attempts = attempts + 1
32 
33         if (prob >= 1.0):
34             windows.append(candidate_window)
35         elif attempts == chips_per_scene and len(windows) == 0:
36             windows.append(candidate_window)
37         else:
38             good = label_store.enough_target_pixels(
39                 candidate_window, target_count_threshold, target_classes)
40             if good or (np.random.rand() < prob):
41                 windows.append(candidate_window)
42 
43     return windows
44 
45 
46 class SemanticSegmentation(Task):
47     """Task-derived type that implements the semantic segmentation task."""
48 
49     def get_train_windows(self, scene: Scene) -> List[Box]:
50         """Get training windows covering a scene.
51 
52         Args:
53              scene: The scene over-which windows are to be generated.
54 
55         Returns:
56              A list of windows, list(Box)
57 
58         """
59 
60         def filter_windows(windows):
61             if scene.aoi_polygons:
62                 windows = Box.filter_by_aoi(windows, scene.aoi_polygons)
63             return windows
64 
65         raster_source = scene.raster_source
66         extent = raster_source.get_extent()
67         label_store = scene.ground_truth_label_source
68         chip_size = self.config.chip_size
69 
70         chip_options = self.config.chip_options
71 
72         if chip_options.window_method == 'random_sample':
73             return get_random_sample_train_windows(
74                 label_store, chip_size, self.config.class_map, extent,
75                 chip_options, filter_windows)
76         elif chip_options.window_method == 'sliding':
77             stride = chip_options.stride
78             if stride is None:
79                 stride = chip_size / 2
80 
81             return list(
82                 filter_windows((extent.get_windows(chip_size, stride))))
83 
84     def get_train_labels(self, window: Box, scene: Scene) -> np.ndarray:
85         """Get the training labels for the given window in the given scene.
86 
87         Args:
88              window: The window over-which the labels are to be
89                   retrieved.
90              scene: The scene from-which the window of labels is to be
91                   extracted.
92 
93         Returns:
94              An appropriately-shaped 2d np.ndarray with the labels
95              encoded as packed pixels.
96 
97         """
98         label_store = scene.ground_truth_label_source
99         return label_store.get_labels(window)
100 
101     def get_predict_windows(self, extent: Box) -> List[Box]:
102         """Get windows over-which predictions will be calculated.
103 
104         Args:
105              extent: The overall extent of the area.
106 
107         Returns:
108              An sequence of windows.
109 
110         """
111         chip_size = self.config.chip_size
112         return extent.get_windows(chip_size, chip_size)
113 
114     def post_process_predictions(self, labels, scene):
115         return labels
116 
117     def save_debug_predict_image(self, scene, debug_dir_uri):
118         # TODO implement this
119         pass
120 
121     def predict_scene(self, scene, tmp_dir):
122         """Predict on a single scene, and return the labels."""
123         log.info('Making predictions for scene')
124         raster_source = scene.raster_source
125         windows = self.get_predict_windows(raster_source.get_extent())
126 
127         def label_fn(window):
128             chip = raster_source.get_chip(window)
129             if np.any(chip):
130                 chip = raster_source.get_chip(window)
131                 labels = self.backend.predict([chip], [window], tmp_dir)
132                 label_arr = labels.get_label_arr(window)
133             else:
134                 label_arr = np.zeros((window.get_height(), window.get_width()))
135             print('.', end='', flush=True)
136             return label_arr
137 
138         return SemanticSegmentationLabels(windows, label_fn)
139
```
--- 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/rastervision/task/semantic_segmentation.py b/rastervision/task/semantic_segmentation.py
--- a/rastervision/task/semantic_segmentation.py
+++ b/rastervision/task/semantic_segmentation.py
@@ -126,12 +126,12 @@
 
         def label_fn(window):
             chip = raster_source.get_chip(window)
-            if np.any(chip):
-                chip = raster_source.get_chip(window)
-                labels = self.backend.predict([chip], [window], tmp_dir)
-                label_arr = labels.get_label_arr(window)
-            else:
-                label_arr = np.zeros((window.get_height(), window.get_width()))
+            labels = self.backend.predict([chip], [window], tmp_dir)
+            label_arr = labels.get_label_arr(window)
+
+            # Set NODATA pixels in imagery to predicted value of 0 (ie. ignore)
+            label_arr[np.sum(chip, axis=2) == 0] = 0
+
             print('.', end='', flush=True)
             return label_arr

{"golden_diff": "diff --git a/rastervision/task/semantic_segmentation.py b/rastervision/task/semantic_segmentation.py\n--- a/rastervision/task/semantic_segmentation.py\n+++ b/rastervision/task/semantic_segmentation.py\n@@ -126,12 +126,12 @@\n \n         def label_fn(window):\n             chip = raster_source.get_chip(window)\n-            if np.any(chip):\n-                chip = raster_source.get_chip(window)\n-                labels = self.backend.predict([chip], [window], tmp_dir)\n-                label_arr = labels.get_label_arr(window)\n-            else:\n-                label_arr = np.zeros((window.get_height(), window.get_width()))\n+            labels = self.backend.predict([chip], [window], tmp_dir)\n+            label_arr = labels.get_label_arr(window)\n+\n+            # Set NODATA pixels in imagery to predicted value of 0 (ie. ignore)\n+            label_arr[np.sum(chip, axis=2) == 0] = 0\n+\n             print('.', end='', flush=True)\n             return label_arr\n", "issue": "Predict zero for nodata pixels on semantic segmentation\n\n", "before_files": [{"content": "from typing import List\nimport logging\n\nimport numpy as np\n\nfrom .task import Task\nfrom rastervision.core.box import Box\nfrom rastervision.data.scene import Scene\nfrom rastervision.data.label import SemanticSegmentationLabels\n\nlog = logging.getLogger(__name__)\n\n\ndef get_random_sample_train_windows(label_store, chip_size, class_map, extent,\n                                    chip_options, filter_windows):\n    prob = chip_options.negative_survival_probability\n    target_count_threshold = chip_options.target_count_threshold\n    target_classes = chip_options.target_classes\n    chips_per_scene = chip_options.chips_per_scene\n\n    if not target_classes:\n        all_class_ids = [item.id for item in class_map.get_items()]\n        target_classes = all_class_ids\n\n    windows = []\n    attempts = 0\n    while (attempts < chips_per_scene):\n        candidate_window = extent.make_random_square(chip_size)\n        if not filter_windows([candidate_window]):\n            continue\n        attempts = attempts + 1\n\n        if (prob >= 1.0):\n            windows.append(candidate_window)\n        elif attempts == chips_per_scene and len(windows) == 0:\n            windows.append(candidate_window)\n        else:\n            good = label_store.enough_target_pixels(\n                candidate_window, target_count_threshold, target_classes)\n            if good or (np.random.rand() < prob):\n                windows.append(candidate_window)\n\n    return windows\n\n\nclass SemanticSegmentation(Task):\n    \"\"\"Task-derived type that implements the semantic segmentation task.\"\"\"\n\n    def get_train_windows(self, scene: Scene) -> List[Box]:\n        \"\"\"Get training windows covering a scene.\n\n        Args:\n             scene: The scene over-which windows are to be generated.\n\n        Returns:\n             A list of windows, list(Box)\n\n        \"\"\"\n\n        def filter_windows(windows):\n            if scene.aoi_polygons:\n                windows = Box.filter_by_aoi(windows, scene.aoi_polygons)\n            return windows\n\n        raster_source = scene.raster_source\n        extent = raster_source.get_extent()\n        label_store = scene.ground_truth_label_source\n        chip_size = self.config.chip_size\n\n        chip_options = self.config.chip_options\n\n        if chip_options.window_method == 'random_sample':\n            return get_random_sample_train_windows(\n                label_store, chip_size, self.config.class_map, extent,\n                chip_options, filter_windows)\n        elif chip_options.window_method == 'sliding':\n            stride = chip_options.stride\n            if stride is None:\n                stride = chip_size / 2\n\n            return list(\n                filter_windows((extent.get_windows(chip_size, stride))))\n\n    def get_train_labels(self, window: Box, scene: Scene) -> np.ndarray:\n        \"\"\"Get the training labels for the given window in the given scene.\n\n        Args:\n             window: The window over-which the labels are to be\n                  retrieved.\n             scene: The scene from-which the window of labels is to be\n                  extracted.\n\n        Returns:\n             An appropriately-shaped 2d np.ndarray with the labels\n             encoded as packed pixels.\n\n        \"\"\"\n        label_store = scene.ground_truth_label_source\n        return label_store.get_labels(window)\n\n    def get_predict_windows(self, extent: Box) -> List[Box]:\n        \"\"\"Get windows over-which predictions will be calculated.\n\n        Args:\n             extent: The overall extent of the area.\n\n        Returns:\n             An sequence of windows.\n\n        \"\"\"\n        chip_size = self.config.chip_size\n        return extent.get_windows(chip_size, chip_size)\n\n    def post_process_predictions(self, labels, scene):\n        return labels\n\n    def save_debug_predict_image(self, scene, debug_dir_uri):\n        # TODO implement this\n        pass\n\n    def predict_scene(self, scene, tmp_dir):\n        \"\"\"Predict on a single scene, and return the labels.\"\"\"\n        log.info('Making predictions for scene')\n        raster_source = scene.raster_source\n        windows = self.get_predict_windows(raster_source.get_extent())\n\n        def label_fn(window):\n            chip = raster_source.get_chip(window)\n            if np.any(chip):\n                chip = raster_source.get_chip(window)\n                labels = self.backend.predict([chip], [window], tmp_dir)\n                label_arr = labels.get_label_arr(window)\n            else:\n                label_arr = np.zeros((window.get_height(), window.get_width()))\n            print('.', end='', flush=True)\n            return label_arr\n\n        return SemanticSegmentationLabels(windows, label_fn)\n", "path": "rastervision/task/semantic_segmentation.py"}], "after_files": [{"content": "from typing import List\nimport logging\n\nimport numpy as np\n\nfrom .task import Task\nfrom rastervision.core.box import Box\nfrom rastervision.data.scene import Scene\nfrom rastervision.data.label import SemanticSegmentationLabels\n\nlog = logging.getLogger(__name__)\n\n\ndef get_random_sample_train_windows(label_store, chip_size, class_map, extent,\n                                    chip_options, filter_windows):\n    prob = chip_options.negative_survival_probability\n    target_count_threshold = chip_options.target_count_threshold\n    target_classes = chip_options.target_classes\n    chips_per_scene = chip_options.chips_per_scene\n\n    if not target_classes:\n        all_class_ids = [item.id for item in class_map.get_items()]\n        target_classes = all_class_ids\n\n    windows = []\n    attempts = 0\n    while (attempts < chips_per_scene):\n        candidate_window = extent.make_random_square(chip_size)\n        if not filter_windows([candidate_window]):\n            continue\n        attempts = attempts + 1\n\n        if (prob >= 1.0):\n            windows.append(candidate_window)\n        elif attempts == chips_per_scene and len(windows) == 0:\n            windows.append(candidate_window)\n        else:\n            good = label_store.enough_target_pixels(\n                candidate_window, target_count_threshold, target_classes)\n            if good or (np.random.rand() < prob):\n                windows.append(candidate_window)\n\n    return windows\n\n\nclass SemanticSegmentation(Task):\n    \"\"\"Task-derived type that implements the semantic segmentation task.\"\"\"\n\n    def get_train_windows(self, scene: Scene) -> List[Box]:\n        \"\"\"Get training windows covering a scene.\n\n        Args:\n             scene: The scene over-which windows are to be generated.\n\n        Returns:\n             A list of windows, list(Box)\n\n        \"\"\"\n\n        def filter_windows(windows):\n            if scene.aoi_polygons:\n                windows = Box.filter_by_aoi(windows, scene.aoi_polygons)\n            return windows\n\n        raster_source = scene.raster_source\n        extent = raster_source.get_extent()\n        label_store = scene.ground_truth_label_source\n        chip_size = self.config.chip_size\n\n        chip_options = self.config.chip_options\n\n        if chip_options.window_method == 'random_sample':\n            return get_random_sample_train_windows(\n                label_store, chip_size, self.config.class_map, extent,\n                chip_options, filter_windows)\n        elif chip_options.window_method == 'sliding':\n            stride = chip_options.stride\n            if stride is None:\n                stride = chip_size / 2\n\n            return list(\n                filter_windows((extent.get_windows(chip_size, stride))))\n\n    def get_train_labels(self, window: Box, scene: Scene) -> np.ndarray:\n        \"\"\"Get the training labels for the given window in the given scene.\n\n        Args:\n             window: The window over-which the labels are to be\n                  retrieved.\n             scene: The scene from-which the window of labels is to be\n                  extracted.\n\n        Returns:\n             An appropriately-shaped 2d np.ndarray with the labels\n             encoded as packed pixels.\n\n        \"\"\"\n        label_store = scene.ground_truth_label_source\n        return label_store.get_labels(window)\n\n    def get_predict_windows(self, extent: Box) -> List[Box]:\n        \"\"\"Get windows over-which predictions will be calculated.\n\n        Args:\n             extent: The overall extent of the area.\n\n        Returns:\n             An sequence of windows.\n\n        \"\"\"\n        chip_size = self.config.chip_size\n        return extent.get_windows(chip_size, chip_size)\n\n    def post_process_predictions(self, labels, scene):\n        return labels\n\n    def save_debug_predict_image(self, scene, debug_dir_uri):\n        # TODO implement this\n        pass\n\n    def predict_scene(self, scene, tmp_dir):\n        \"\"\"Predict on a single scene, and return the labels.\"\"\"\n        log.info('Making predictions for scene')\n        raster_source = scene.raster_source\n        windows = self.get_predict_windows(raster_source.get_extent())\n\n        def label_fn(window):\n            chip = raster_source.get_chip(window)\n            labels = self.backend.predict([chip], [window], tmp_dir)\n            label_arr = labels.get_label_arr(window)\n\n            # Set NODATA pixels in imagery to predicted value of 0 (ie. ignore)\n            label_arr[np.sum(chip, axis=2) == 0] = 0\n\n            print('.', end='', flush=True)\n            return label_arr\n\n        return SemanticSegmentationLabels(windows, label_fn)\n", "path": "rastervision/task/semantic_segmentation.py"}]}