Meehai commited on
Commit
2d0b865
·
1 Parent(s): 36c3da8
scripts/semantic_mapper/semantic_mapper.py CHANGED
@@ -19,10 +19,10 @@ def plot_one(data: MultiTaskItem, title: str, order: list[str] | None,
19
  """simple plot function: plot_one(reader[0][0], reader[0][1], None, reader.name_to_task)"""
20
  def vre_plot_fn(rgb_img: np.ndarray, x: tr.Tensor, node: Representation) -> np.ndarray:
21
  node.data = ReprOut(frames=rgb_img, output=MemoryData(x.cpu().detach().numpy()[None]), key=[0])
22
- res = node.make_images()[0]
23
  return res
24
  name_to_task["rgb"].data = ReprOut(frames=None, output=MemoryData(data["rgb"].detach().numpy())[None], key=[0])
25
- rgb_img = name_to_task["rgb"].make_images()
26
  img_data = {k: vre_plot_fn(rgb_img, v, name_to_task[k]) for k, v in data.items()}
27
  img_data = reorder_dict(img_data, order) if order is not None else img_data
28
  titles = [title if len(title) < 40 else f"{title[0:19]}..{title[-19:]}" for title in img_data]
@@ -134,8 +134,8 @@ class SemanticMask2FormerMapillaryConvertedPaper(TaskMapper, NpIORepresentation)
134
  return self.n_classes
135
 
136
  @overrides
137
- def make_images(self) -> np.ndarray:
138
- return colorize_semantic_segmentation(self.data.output.argmax(-1), self.classes, self.color_map)
139
 
140
  @overrides
141
  def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
@@ -193,8 +193,8 @@ class SemanticMask2FormerCOCOConverted(TaskMapper, NpIORepresentation):
193
  return self.n_classes
194
 
195
  @overrides
196
- def make_images(self) -> np.ndarray:
197
- return colorize_semantic_segmentation(self.data.output.argmax(-1), self.classes, self.color_map)
198
 
199
  @overrides
200
  def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
@@ -235,8 +235,8 @@ class BinaryMapper(TaskMapper, NpIORepresentation):
235
  self.output_dtype = "bool"
236
 
237
  @overrides
238
- def make_images(self) -> np.ndarray:
239
- x = self.data.output.argmax(-1) if self.load_mode == "one_hot" else (self.data.output > 0.5).astype(int)
240
  x = x[..., 0] if x.shape[-1] == 1 else x
241
  return colorize_semantic_segmentation(x, self.classes, self.color_map)
242
 
@@ -299,8 +299,8 @@ class SemanticMedian(TaskMapper, NpIORepresentation):
299
  return MemoryData(np.eye(self.n_classes)[sum(dep_data).argmax(-1)].astype(np.uint8))
300
 
301
  @overrides
302
- def make_images(self) -> np.ndarray:
303
- return colorize_semantic_segmentation(self.data.output.argmax(-1), self.classes, self.color_map)
304
 
305
  class SafeLandingAreas(BinaryMapper, NpIORepresentation):
306
  def __init__(self, name: str, depth: DepthRepresentation, camera_normals: NormalsRepresentation,
 
19
  """simple plot function: plot_one(reader[0][0], reader[0][1], None, reader.name_to_task)"""
20
  def vre_plot_fn(rgb_img: np.ndarray, x: tr.Tensor, node: Representation) -> np.ndarray:
21
  node.data = ReprOut(frames=rgb_img, output=MemoryData(x.cpu().detach().numpy()[None]), key=[0])
22
+ res = node.make_images(node.data)[0]
23
  return res
24
  name_to_task["rgb"].data = ReprOut(frames=None, output=MemoryData(data["rgb"].detach().numpy())[None], key=[0])
25
+ rgb_img = name_to_task["rgb"].make_images(name_to_task["rgb"].data)
26
  img_data = {k: vre_plot_fn(rgb_img, v, name_to_task[k]) for k, v in data.items()}
27
  img_data = reorder_dict(img_data, order) if order is not None else img_data
28
  titles = [title if len(title) < 40 else f"{title[0:19]}..{title[-19:]}" for title in img_data]
 
134
  return self.n_classes
135
 
136
  @overrides
137
+ def make_images(self, data: ReprOut) -> np.ndarray:
138
+ return colorize_semantic_segmentation(data.output.argmax(-1), self.classes, self.color_map)
139
 
140
  @overrides
141
  def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
 
193
  return self.n_classes
194
 
195
  @overrides
196
+ def make_images(self, data: ReprOut) -> np.ndarray:
197
+ return colorize_semantic_segmentation(data.output.argmax(-1), self.classes, self.color_map)
198
 
199
  @overrides
200
  def merge_fn(self, dep_data: list[MemoryData]) -> MemoryData:
 
235
  self.output_dtype = "bool"
236
 
237
  @overrides
238
+ def make_images(self, data: ReprOut) -> np.ndarray:
239
+ x = data.output.argmax(-1) if self.load_mode == "one_hot" else (data.output > 0.5).astype(int)
240
  x = x[..., 0] if x.shape[-1] == 1 else x
241
  return colorize_semantic_segmentation(x, self.classes, self.color_map)
242
 
 
299
  return MemoryData(np.eye(self.n_classes)[sum(dep_data).argmax(-1)].astype(np.uint8))
300
 
301
  @overrides
302
+ def make_images(self, data: ReprOut) -> np.ndarray:
303
+ return colorize_semantic_segmentation(data.output.argmax(-1), self.classes, self.color_map)
304
 
305
  class SafeLandingAreas(BinaryMapper, NpIORepresentation):
306
  def __init__(self, name: str, depth: DepthRepresentation, camera_normals: NormalsRepresentation,