Meehai commited on
Commit
293440d
1 Parent(s): 69c544e
dronescapes_reader/multitask_dataset.py CHANGED
@@ -13,7 +13,7 @@ from lovely_tensors import monkey_patch
13
 
14
  monkey_patch()
15
  BuildDatasetTuple = tuple[dict[str, list[Path]], list[str]]
16
- MultiTaskItem = tuple[dict[str, tr.Tensor], str, list[str]]
17
 
18
  class NpzRepresentation:
19
  """Generic Task with data read from/saved to npz files. Tries to read data as-is from disk and store it as well"""
@@ -24,7 +24,7 @@ class NpzRepresentation:
24
  """Reads the npz data from the disk and transforms it properly"""
25
  data = np.load(path, allow_pickle=False)
26
  data = data if isinstance(data, np.ndarray) else data["arr_0"] # in case on npz, we need this as well
27
- return tr.from_numpy(data)
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`"""
@@ -114,7 +114,7 @@ class MultiTaskDataset(Dataset):
114
  """
115
  assert all(item[2] == self.task_names for item in items), ((item[2] for item in items), self.task_names)
116
  items_name = [item[1] for item in items]
117
- res = {k: tr.zeros(len(items), *self.data_shape[k]) for k in self.task_names}
118
  for i in range(len(items)):
119
  for k in self.task_names:
120
  res[k][i] = items[i][0][k] if items[i][0][k] is not None else 0
 
13
 
14
  monkey_patch()
15
  BuildDatasetTuple = tuple[dict[str, list[Path]], list[str]]
16
+ MultiTaskItem = tuple[dict[str, tr.Tensor], str, list[str]] # [{task: data}, stem(name) | list[stem(name)], [tasks]]
17
 
18
  class NpzRepresentation:
19
  """Generic Task with data read from/saved to npz files. Tries to read data as-is from disk and store it as well"""
 
24
  """Reads the npz data from the disk and transforms it properly"""
25
  data = np.load(path, allow_pickle=False)
26
  data = data if isinstance(data, np.ndarray) else data["arr_0"] # in case on npz, we need this as well
27
+ return tr.from_numpy(data) # can be uint8, float16, float32 etc.
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`"""
 
114
  """
115
  assert all(item[2] == self.task_names for item in items), ((item[2] for item in items), self.task_names)
116
  items_name = [item[1] for item in items]
117
+ res = {k: tr.zeros(len(items), *self.data_shape[k]).float() for k in self.task_names} # float32 always
118
  for i in range(len(items)):
119
  for k in self.task_names:
120
  res[k][i] = items[i][0][k] if items[i][0][k] is not None else 0