Meehai commited on
Commit
61fd3f3
1 Parent(s): 2d35767

one more fix

Browse files
dronescapes_reader/dronescapes_representations.py CHANGED
@@ -16,7 +16,7 @@ class DepthRepresentation(NpzRepresentation):
16
 
17
  @overrides
18
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
19
- x = x.numpy()
20
  x = np.clip(x, self.min_depth, self.max_depth)
21
  x = np.nan_to_num((x - x.min()) / (x.max() - x.min()), 0)
22
  y = hot(x.squeeze())[..., 0:3]
@@ -27,7 +27,7 @@ class OpticalFlowRepresentation(NpzRepresentation):
27
  """OpticalFlowRepresentation. Implements depth task-specific stuff, like using flow_vis."""
28
  @overrides
29
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
30
- return flow_vis.flow_to_color(x.squeeze().nan_to_num(0).numpy())
31
 
32
  class SemanticRepresentation(NpzRepresentation):
33
  """SemanticRepresentation. Implements depth task-specific stuff, like using flow_vis."""
@@ -46,7 +46,7 @@ class SemanticRepresentation(NpzRepresentation):
46
 
47
  @overrides
48
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
49
- x = x.squeeze().nan_to_num(0).numpy()
50
  new_images = np.zeros((*x.shape, 3), dtype=np.uint8)
51
  for i in range(self.n_classes):
52
  new_images[x == i] = self.color_map[i]
 
16
 
17
  @overrides
18
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
19
+ x = x.detach().cpu().numpy()
20
  x = np.clip(x, self.min_depth, self.max_depth)
21
  x = np.nan_to_num((x - x.min()) / (x.max() - x.min()), 0)
22
  y = hot(x.squeeze())[..., 0:3]
 
27
  """OpticalFlowRepresentation. Implements depth task-specific stuff, like using flow_vis."""
28
  @overrides
29
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
30
+ return flow_vis.flow_to_color(x.squeeze().nan_to_num(0).detach().cpu().numpy())
31
 
32
  class SemanticRepresentation(NpzRepresentation):
33
  """SemanticRepresentation. Implements depth task-specific stuff, like using flow_vis."""
 
46
 
47
  @overrides
48
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
49
+ x = x.squeeze().nan_to_num(0).detach().cpu().numpy()
50
  new_images = np.zeros((*x.shape, 3), dtype=np.uint8)
51
  for i in range(self.n_classes):
52
  new_images[x == i] = self.color_map[i]
dronescapes_reader/multitask_dataset.py CHANGED
@@ -28,7 +28,7 @@ class NpzRepresentation:
28
 
29
  def save_to_disk(self, data: tr.Tensor, path: Path):
30
  """stores this item to the disk which can then be loaded via `load_from_disk`"""
31
- np.save(path, data.cpu().numpy(), allow_pickle=False)
32
 
33
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
34
  """very basic implementation of converting this representation to a viewable image. You should overwrite this"""
@@ -37,7 +37,7 @@ class NpzRepresentation:
37
  assert len(x.shape) == 3, x.shape # guaranteed to be (H, W, C) at this point
38
  if x.shape[-1] != 3: x = x[..., 0:1]
39
  if x.shape[-1] == 1: x = x.repeat(1, 1, 3)
40
- x = x.nan_to_num(0).cpu().numpy() # guaranteed to be (H, W, 3) at this point hopefully
41
  _min, _max = x.min((0, 1), keepdims=True), x.max((0, 1), keepdims=True)
42
  if x.dtype != np.uint8: x = np.nan_to_num((x - _min) / (_max - _min) * 255, 0).astype(np.uint8)
43
  return x
@@ -119,7 +119,7 @@ class MultiTaskDataset(Dataset):
119
  for task_name in self.task_names:
120
  t = self.task_types[task_name]
121
  try:
122
- t = t(task_name)
123
  except Exception:
124
  pass
125
  self._tasks.append(t)
 
28
 
29
  def save_to_disk(self, data: tr.Tensor, path: Path):
30
  """stores this item to the disk which can then be loaded via `load_from_disk`"""
31
+ np.save(path, data.cpu().detach().numpy(), allow_pickle=False)
32
 
33
  def plot_fn(self, x: tr.Tensor) -> np.ndarray:
34
  """very basic implementation of converting this representation to a viewable image. You should overwrite this"""
 
37
  assert len(x.shape) == 3, x.shape # guaranteed to be (H, W, C) at this point
38
  if x.shape[-1] != 3: x = x[..., 0:1]
39
  if x.shape[-1] == 1: x = x.repeat(1, 1, 3)
40
+ x = x.nan_to_num(0).cpu().detach().numpy() # guaranteed to be (H, W, 3) at this point hopefully
41
  _min, _max = x.min((0, 1), keepdims=True), x.max((0, 1), keepdims=True)
42
  if x.dtype != np.uint8: x = np.nan_to_num((x - _min) / (_max - _min) * 255, 0).astype(np.uint8)
43
  return x
 
119
  for task_name in self.task_names:
120
  t = self.task_types[task_name]
121
  try:
122
+ t = t(task_name) # hack for not isinstance(self.task_types, NpzRepresentation) but callable
123
  except Exception:
124
  pass
125
  self._tasks.append(t)