зеркало из https://github.com/microsoft/torchgeo.git
Adapt CDL cmap to match ordinal label mapping (#1368)
* outline downstream dataset * revert commit * outline downstream dataset * revert commit * ordinal cmap and missing fig return * Fix cmap * I hate 0-indexed programming languages * L7 Irish/L8 Biome: don't interpolate cmap * list -> dict * None means the default, which is antialiasing * Undo changes to other datasets --------- Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
This commit is contained in:
Родитель
9e4f7d12d4
Коммит
0a564dd4b2
|
@ -9,6 +9,7 @@ from typing import Any, Callable, Optional
|
|||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from matplotlib.colors import ListedColormap
|
||||
from rasterio.crs import CRS
|
||||
|
||||
from .geo import RasterDataset
|
||||
|
@ -73,255 +74,133 @@ class CDL(RasterDataset):
|
|||
4: (255, 158, 11, 255),
|
||||
5: (38, 112, 0, 255),
|
||||
6: (255, 255, 0, 255),
|
||||
7: (0, 0, 0, 255),
|
||||
8: (0, 0, 0, 255),
|
||||
9: (0, 0, 0, 255),
|
||||
10: (112, 165, 0, 255),
|
||||
11: (0, 175, 75, 255),
|
||||
12: (221, 165, 11, 255),
|
||||
13: (221, 165, 11, 255),
|
||||
14: (126, 211, 255, 255),
|
||||
15: (0, 0, 0, 255),
|
||||
16: (0, 0, 0, 255),
|
||||
17: (0, 0, 0, 255),
|
||||
18: (0, 0, 0, 255),
|
||||
19: (0, 0, 0, 255),
|
||||
20: (0, 0, 0, 255),
|
||||
21: (226, 0, 124, 255),
|
||||
22: (137, 98, 84, 255),
|
||||
23: (216, 181, 107, 255),
|
||||
24: (165, 112, 0, 255),
|
||||
25: (214, 158, 188, 255),
|
||||
26: (112, 112, 0, 255),
|
||||
27: (172, 0, 124, 255),
|
||||
28: (160, 89, 137, 255),
|
||||
29: (112, 0, 73, 255),
|
||||
7: (112, 165, 0, 255),
|
||||
8: (0, 175, 75, 255),
|
||||
9: (221, 165, 11, 255),
|
||||
10: (221, 165, 11, 255),
|
||||
11: (126, 211, 255, 255),
|
||||
12: (226, 0, 124, 255),
|
||||
13: (137, 98, 84, 255),
|
||||
14: (216, 181, 107, 255),
|
||||
15: (165, 112, 0, 255),
|
||||
16: (214, 158, 188, 255),
|
||||
17: (112, 112, 0, 255),
|
||||
18: (172, 0, 124, 255),
|
||||
19: (160, 89, 137, 255),
|
||||
20: (112, 0, 73, 255),
|
||||
21: (214, 158, 188, 255),
|
||||
22: (209, 255, 0, 255),
|
||||
23: (126, 153, 255, 255),
|
||||
24: (214, 214, 0, 255),
|
||||
25: (209, 255, 0, 255),
|
||||
26: (0, 175, 75, 255),
|
||||
27: (255, 165, 226, 255),
|
||||
28: (165, 242, 140, 255),
|
||||
29: (0, 175, 75, 255),
|
||||
30: (214, 158, 188, 255),
|
||||
31: (209, 255, 0, 255),
|
||||
32: (126, 153, 255, 255),
|
||||
33: (214, 214, 0, 255),
|
||||
34: (209, 255, 0, 255),
|
||||
35: (0, 175, 75, 255),
|
||||
36: (255, 165, 226, 255),
|
||||
37: (165, 242, 140, 255),
|
||||
38: (0, 175, 75, 255),
|
||||
39: (214, 158, 188, 255),
|
||||
40: (0, 0, 0, 255),
|
||||
41: (168, 0, 228, 255),
|
||||
42: (165, 0, 0, 255),
|
||||
43: (112, 38, 0, 255),
|
||||
44: (0, 175, 75, 255),
|
||||
45: (177, 126, 255, 255),
|
||||
46: (112, 38, 0, 255),
|
||||
47: (255, 102, 102, 255),
|
||||
48: (255, 102, 102, 255),
|
||||
49: (255, 204, 102, 255),
|
||||
50: (255, 102, 102, 255),
|
||||
51: (0, 175, 75, 255),
|
||||
52: (0, 221, 175, 255),
|
||||
53: (84, 255, 0, 255),
|
||||
54: (242, 163, 119, 255),
|
||||
55: (255, 102, 102, 255),
|
||||
56: (0, 175, 75, 255),
|
||||
57: (126, 211, 255, 255),
|
||||
58: (232, 191, 255, 255),
|
||||
59: (175, 255, 221, 255),
|
||||
60: (0, 175, 75, 255),
|
||||
61: (191, 191, 119, 255),
|
||||
62: (0, 0, 0, 255),
|
||||
63: (147, 204, 147, 255),
|
||||
64: (198, 214, 158, 255),
|
||||
65: (204, 191, 163, 255),
|
||||
66: (255, 0, 255, 255),
|
||||
67: (255, 142, 170, 255),
|
||||
68: (186, 0, 79, 255),
|
||||
69: (112, 68, 137, 255),
|
||||
70: (0, 119, 119, 255),
|
||||
71: (177, 154, 112, 255),
|
||||
72: (255, 255, 126, 255),
|
||||
73: (0, 0, 0, 255),
|
||||
74: (181, 112, 91, 255),
|
||||
75: (0, 165, 130, 255),
|
||||
76: (233, 214, 175, 255),
|
||||
77: (177, 154, 112, 255),
|
||||
78: (0, 0, 0, 255),
|
||||
79: (0, 0, 0, 255),
|
||||
80: (0, 0, 0, 255),
|
||||
81: (242, 242, 242, 255),
|
||||
82: (154, 154, 154, 255),
|
||||
83: (75, 112, 163, 255),
|
||||
84: (0, 0, 0, 255),
|
||||
85: (0, 0, 0, 255),
|
||||
86: (0, 0, 0, 255),
|
||||
87: (126, 177, 177, 255),
|
||||
88: (232, 255, 191, 255),
|
||||
89: (0, 0, 0, 255),
|
||||
90: (0, 0, 0, 255),
|
||||
91: (0, 0, 0, 255),
|
||||
92: (0, 255, 255, 255),
|
||||
93: (0, 0, 0, 255),
|
||||
94: (0, 0, 0, 255),
|
||||
95: (0, 0, 0, 255),
|
||||
96: (0, 0, 0, 255),
|
||||
97: (0, 0, 0, 255),
|
||||
98: (0, 0, 0, 255),
|
||||
99: (0, 0, 0, 255),
|
||||
100: (0, 0, 0, 255),
|
||||
101: (0, 0, 0, 255),
|
||||
102: (0, 0, 0, 255),
|
||||
103: (0, 0, 0, 255),
|
||||
104: (0, 0, 0, 255),
|
||||
105: (0, 0, 0, 255),
|
||||
106: (0, 0, 0, 255),
|
||||
107: (0, 0, 0, 255),
|
||||
108: (0, 0, 0, 255),
|
||||
109: (0, 0, 0, 255),
|
||||
110: (0, 0, 0, 255),
|
||||
111: (75, 112, 163, 255),
|
||||
112: (211, 226, 249, 255),
|
||||
113: (0, 0, 0, 255),
|
||||
114: (0, 0, 0, 255),
|
||||
115: (0, 0, 0, 255),
|
||||
116: (0, 0, 0, 255),
|
||||
117: (0, 0, 0, 255),
|
||||
118: (0, 0, 0, 255),
|
||||
119: (0, 0, 0, 255),
|
||||
120: (0, 0, 0, 255),
|
||||
121: (154, 154, 154, 255),
|
||||
122: (154, 154, 154, 255),
|
||||
123: (154, 154, 154, 255),
|
||||
124: (154, 154, 154, 255),
|
||||
125: (0, 0, 0, 255),
|
||||
126: (0, 0, 0, 255),
|
||||
127: (0, 0, 0, 255),
|
||||
128: (0, 0, 0, 255),
|
||||
129: (0, 0, 0, 255),
|
||||
130: (0, 0, 0, 255),
|
||||
131: (204, 191, 163, 255),
|
||||
132: (0, 0, 0, 255),
|
||||
133: (0, 0, 0, 255),
|
||||
134: (0, 0, 0, 255),
|
||||
135: (0, 0, 0, 255),
|
||||
136: (0, 0, 0, 255),
|
||||
137: (0, 0, 0, 255),
|
||||
138: (0, 0, 0, 255),
|
||||
139: (0, 0, 0, 255),
|
||||
140: (0, 0, 0, 255),
|
||||
141: (147, 204, 147, 255),
|
||||
142: (147, 204, 147, 255),
|
||||
143: (147, 204, 147, 255),
|
||||
144: (0, 0, 0, 255),
|
||||
145: (0, 0, 0, 255),
|
||||
146: (0, 0, 0, 255),
|
||||
147: (0, 0, 0, 255),
|
||||
148: (0, 0, 0, 255),
|
||||
149: (0, 0, 0, 255),
|
||||
150: (0, 0, 0, 255),
|
||||
151: (0, 0, 0, 255),
|
||||
152: (198, 214, 158, 255),
|
||||
153: (0, 0, 0, 255),
|
||||
154: (0, 0, 0, 255),
|
||||
155: (0, 0, 0, 255),
|
||||
156: (0, 0, 0, 255),
|
||||
157: (0, 0, 0, 255),
|
||||
158: (0, 0, 0, 255),
|
||||
159: (0, 0, 0, 255),
|
||||
160: (0, 0, 0, 255),
|
||||
161: (0, 0, 0, 255),
|
||||
162: (0, 0, 0, 255),
|
||||
163: (0, 0, 0, 255),
|
||||
164: (0, 0, 0, 255),
|
||||
165: (0, 0, 0, 255),
|
||||
166: (0, 0, 0, 255),
|
||||
167: (0, 0, 0, 255),
|
||||
168: (0, 0, 0, 255),
|
||||
169: (0, 0, 0, 255),
|
||||
170: (0, 0, 0, 255),
|
||||
171: (0, 0, 0, 255),
|
||||
172: (0, 0, 0, 255),
|
||||
173: (0, 0, 0, 255),
|
||||
174: (0, 0, 0, 255),
|
||||
175: (0, 0, 0, 255),
|
||||
176: (232, 255, 191, 255),
|
||||
177: (0, 0, 0, 255),
|
||||
178: (0, 0, 0, 255),
|
||||
179: (0, 0, 0, 255),
|
||||
180: (0, 0, 0, 255),
|
||||
181: (0, 0, 0, 255),
|
||||
182: (0, 0, 0, 255),
|
||||
183: (0, 0, 0, 255),
|
||||
184: (0, 0, 0, 255),
|
||||
185: (0, 0, 0, 255),
|
||||
186: (0, 0, 0, 255),
|
||||
187: (0, 0, 0, 255),
|
||||
188: (0, 0, 0, 255),
|
||||
189: (0, 0, 0, 255),
|
||||
190: (126, 177, 177, 255),
|
||||
191: (0, 0, 0, 255),
|
||||
192: (0, 0, 0, 255),
|
||||
193: (0, 0, 0, 255),
|
||||
194: (0, 0, 0, 255),
|
||||
195: (126, 177, 177, 255),
|
||||
196: (0, 0, 0, 255),
|
||||
197: (0, 0, 0, 255),
|
||||
198: (0, 0, 0, 255),
|
||||
199: (0, 0, 0, 255),
|
||||
200: (0, 0, 0, 255),
|
||||
201: (0, 0, 0, 255),
|
||||
202: (0, 0, 0, 255),
|
||||
203: (0, 0, 0, 255),
|
||||
204: (0, 255, 140, 255),
|
||||
205: (214, 158, 188, 255),
|
||||
206: (255, 102, 102, 255),
|
||||
207: (255, 102, 102, 255),
|
||||
208: (255, 102, 102, 255),
|
||||
209: (255, 102, 102, 255),
|
||||
210: (255, 142, 170, 255),
|
||||
211: (51, 73, 51, 255),
|
||||
212: (228, 112, 38, 255),
|
||||
213: (255, 102, 102, 255),
|
||||
214: (255, 102, 102, 255),
|
||||
215: (102, 153, 76, 255),
|
||||
216: (255, 102, 102, 255),
|
||||
217: (177, 154, 112, 255),
|
||||
218: (255, 142, 170, 255),
|
||||
219: (255, 102, 102, 255),
|
||||
220: (255, 142, 170, 255),
|
||||
221: (255, 102, 102, 255),
|
||||
222: (255, 102, 102, 255),
|
||||
223: (255, 142, 170, 255),
|
||||
224: (0, 175, 75, 255),
|
||||
225: (255, 211, 0, 255),
|
||||
226: (255, 211, 0, 255),
|
||||
227: (255, 102, 102, 255),
|
||||
228: (255, 210, 0, 255),
|
||||
229: (255, 102, 102, 255),
|
||||
230: (137, 98, 84, 255),
|
||||
231: (255, 102, 102, 255),
|
||||
232: (255, 38, 38, 255),
|
||||
233: (226, 0, 124, 255),
|
||||
234: (255, 158, 11, 255),
|
||||
235: (255, 158, 11, 255),
|
||||
236: (165, 112, 0, 255),
|
||||
237: (255, 211, 0, 255),
|
||||
238: (165, 112, 0, 255),
|
||||
239: (38, 112, 0, 255),
|
||||
240: (38, 112, 0, 255),
|
||||
241: (255, 211, 0, 255),
|
||||
242: (0, 0, 153, 255),
|
||||
243: (255, 102, 102, 255),
|
||||
244: (255, 102, 102, 255),
|
||||
245: (255, 102, 102, 255),
|
||||
246: (255, 102, 102, 255),
|
||||
247: (255, 102, 102, 255),
|
||||
248: (255, 102, 102, 255),
|
||||
249: (255, 102, 102, 255),
|
||||
250: (255, 102, 102, 255),
|
||||
251: (0, 0, 0, 255),
|
||||
252: (0, 0, 0, 255),
|
||||
253: (0, 0, 0, 255),
|
||||
254: (38, 112, 0, 255),
|
||||
255: (0, 0, 0, 255),
|
||||
31: (168, 0, 228, 255),
|
||||
32: (165, 0, 0, 255),
|
||||
33: (112, 38, 0, 255),
|
||||
34: (0, 175, 75, 255),
|
||||
35: (177, 126, 255, 255),
|
||||
36: (112, 38, 0, 255),
|
||||
37: (255, 102, 102, 255),
|
||||
38: (255, 102, 102, 255),
|
||||
39: (255, 204, 102, 255),
|
||||
40: (255, 102, 102, 255),
|
||||
41: (0, 175, 75, 255),
|
||||
42: (0, 221, 175, 255),
|
||||
43: (84, 255, 0, 255),
|
||||
44: (242, 163, 119, 255),
|
||||
45: (255, 102, 102, 255),
|
||||
46: (0, 175, 75, 255),
|
||||
47: (126, 211, 255, 255),
|
||||
48: (232, 191, 255, 255),
|
||||
49: (175, 255, 221, 255),
|
||||
50: (0, 175, 75, 255),
|
||||
51: (191, 191, 119, 255),
|
||||
52: (147, 204, 147, 255),
|
||||
53: (198, 214, 158, 255),
|
||||
54: (204, 191, 163, 255),
|
||||
55: (255, 0, 255, 255),
|
||||
56: (255, 142, 170, 255),
|
||||
57: (186, 0, 79, 255),
|
||||
58: (112, 68, 137, 255),
|
||||
59: (0, 119, 119, 255),
|
||||
60: (177, 154, 112, 255),
|
||||
61: (255, 255, 126, 255),
|
||||
62: (181, 112, 91, 255),
|
||||
63: (0, 165, 130, 255),
|
||||
64: (233, 214, 175, 255),
|
||||
65: (177, 154, 112, 255),
|
||||
66: (242, 242, 242, 255),
|
||||
67: (154, 154, 154, 255),
|
||||
68: (75, 112, 163, 255),
|
||||
69: (126, 177, 177, 255),
|
||||
70: (232, 255, 191, 255),
|
||||
71: (0, 255, 255, 255),
|
||||
72: (75, 112, 163, 255),
|
||||
73: (211, 226, 249, 255),
|
||||
74: (154, 154, 154, 255),
|
||||
75: (154, 154, 154, 255),
|
||||
76: (154, 154, 154, 255),
|
||||
77: (154, 154, 154, 255),
|
||||
78: (204, 191, 163, 255),
|
||||
79: (147, 204, 147, 255),
|
||||
80: (147, 204, 147, 255),
|
||||
81: (147, 204, 147, 255),
|
||||
82: (198, 214, 158, 255),
|
||||
83: (232, 255, 191, 255),
|
||||
84: (126, 177, 177, 255),
|
||||
85: (126, 177, 177, 255),
|
||||
86: (0, 255, 140, 255),
|
||||
87: (214, 158, 188, 255),
|
||||
88: (255, 102, 102, 255),
|
||||
89: (255, 102, 102, 255),
|
||||
90: (255, 102, 102, 255),
|
||||
91: (255, 102, 102, 255),
|
||||
92: (255, 142, 170, 255),
|
||||
93: (51, 73, 51, 255),
|
||||
94: (228, 112, 38, 255),
|
||||
95: (255, 102, 102, 255),
|
||||
96: (255, 102, 102, 255),
|
||||
97: (102, 153, 76, 255),
|
||||
98: (255, 102, 102, 255),
|
||||
99: (177, 154, 112, 255),
|
||||
100: (255, 142, 170, 255),
|
||||
101: (255, 102, 102, 255),
|
||||
102: (255, 142, 170, 255),
|
||||
103: (255, 102, 102, 255),
|
||||
104: (255, 102, 102, 255),
|
||||
105: (255, 142, 170, 255),
|
||||
106: (0, 175, 75, 255),
|
||||
107: (255, 211, 0, 255),
|
||||
108: (255, 211, 0, 255),
|
||||
109: (255, 102, 102, 255),
|
||||
110: (255, 210, 0, 255),
|
||||
111: (255, 102, 102, 255),
|
||||
112: (137, 98, 84, 255),
|
||||
113: (255, 102, 102, 255),
|
||||
114: (255, 38, 38, 255),
|
||||
115: (226, 0, 124, 255),
|
||||
116: (255, 158, 11, 255),
|
||||
117: (255, 158, 11, 255),
|
||||
118: (165, 112, 0, 255),
|
||||
119: (255, 211, 0, 255),
|
||||
120: (165, 112, 0, 255),
|
||||
121: (38, 112, 0, 255),
|
||||
122: (38, 112, 0, 255),
|
||||
123: (255, 211, 0, 255),
|
||||
124: (0, 0, 153, 255),
|
||||
125: (255, 102, 102, 255),
|
||||
126: (255, 102, 102, 255),
|
||||
127: (255, 102, 102, 255),
|
||||
128: (255, 102, 102, 255),
|
||||
129: (255, 102, 102, 255),
|
||||
130: (255, 102, 102, 255),
|
||||
131: (255, 102, 102, 255),
|
||||
132: (255, 102, 102, 255),
|
||||
133: (38, 112, 0, 255),
|
||||
}
|
||||
|
||||
ordinal_label_map = {
|
||||
|
@ -613,32 +492,33 @@ class CDL(RasterDataset):
|
|||
mask = sample["mask"].squeeze().numpy()
|
||||
ncols = 1
|
||||
|
||||
cmap: "np.typing.NDArray[np.int_]" = np.array(
|
||||
[self.cmap[i] for i in range(len(self.cmap))]
|
||||
)
|
||||
mask = cmap[mask]
|
||||
|
||||
showing_predictions = "prediction" in sample
|
||||
if showing_predictions:
|
||||
pred = sample["prediction"].squeeze().numpy()
|
||||
pred = cmap[pred]
|
||||
ncols = 2
|
||||
|
||||
fig, axs = plt.subplots(nrows=1, ncols=ncols, figsize=(ncols * 4, 4))
|
||||
kwargs = {
|
||||
"cmap": ListedColormap(np.array(list(self.cmap.values())) / 255),
|
||||
"vmin": 0,
|
||||
"vmax": len(self.cmap) - 1,
|
||||
"interpolation": "none",
|
||||
}
|
||||
|
||||
fig, axs = plt.subplots(
|
||||
nrows=1, ncols=ncols, figsize=(ncols * 4, 4), squeeze=False
|
||||
)
|
||||
|
||||
axs[0, 0].imshow(mask, **kwargs)
|
||||
axs[0, 0].axis("off")
|
||||
|
||||
if show_titles:
|
||||
axs[0, 0].set_title("Mask")
|
||||
|
||||
if showing_predictions:
|
||||
axs[0].imshow(mask)
|
||||
axs[0].axis("off")
|
||||
axs[1].imshow(pred)
|
||||
axs[1].axis("off")
|
||||
axs[0, 1].imshow(pred, **kwargs)
|
||||
axs[0, 1].axis("off")
|
||||
if show_titles:
|
||||
axs[0].set_title("Mask")
|
||||
axs[1].set_title("Prediction")
|
||||
else:
|
||||
axs.imshow(mask)
|
||||
axs.axis("off")
|
||||
if show_titles:
|
||||
axs.set_title("Mask")
|
||||
axs[0, 1].set_title("Prediction")
|
||||
|
||||
if suptitle is not None:
|
||||
plt.suptitle(suptitle)
|
||||
|
|
Загрузка…
Ссылка в новой задаче