added back task_types
Browse files
dronescapes_reader/multitask_dataset.py
CHANGED
@@ -69,7 +69,7 @@ class MultiTaskDataset(Dataset):
|
|
69 |
"""
|
70 |
|
71 |
def __init__(self, path: Path, task_names: list[str] | None = None, handle_missing_data: str = "fill_none",
|
72 |
-
files_suffix: str = "npz"):
|
73 |
assert Path(path).exists(), f"Provided path '{path}' doesn't exist!"
|
74 |
assert handle_missing_data in ("drop", "fill_none"), f"Invalid handle_missing_data mode: {handle_missing_data}"
|
75 |
assert files_suffix == "npz", "Only npz supported right now (though trivial to update)"
|
@@ -77,10 +77,14 @@ class MultiTaskDataset(Dataset):
|
|
77 |
self.handle_missing_data = handle_missing_data
|
78 |
self.suffix = files_suffix
|
79 |
self.files_per_repr, self.file_names = self._build_dataset()
|
|
|
|
|
|
|
80 |
|
81 |
if task_names is None:
|
82 |
task_names = list(self.files_per_repr.keys())
|
83 |
logger.debug(f"No explicit tasks provided. Using all of them as read from the paths ({len(task_names)}).")
|
|
|
84 |
assert all(isinstance(x, str) for x in task_names), tuple(zip(task_names, (type(x) for x in task_names)))
|
85 |
self.task_names = sorted(task_names)
|
86 |
self._data_shape: tuple[int, ...] | None = None
|
@@ -105,7 +109,7 @@ class MultiTaskDataset(Dataset):
|
|
105 |
"""
|
106 |
if self._tasks is not None:
|
107 |
return self._tasks
|
108 |
-
self._tasks = [
|
109 |
return self._tasks
|
110 |
|
111 |
def collate_fn(self, items: list[MultiTaskItem]) -> MultiTaskItem:
|
|
|
69 |
"""
|
70 |
|
71 |
def __init__(self, path: Path, task_names: list[str] | None = None, handle_missing_data: str = "fill_none",
|
72 |
+
files_suffix: str = "npz", task_types: dict[str, type] = None):
|
73 |
assert Path(path).exists(), f"Provided path '{path}' doesn't exist!"
|
74 |
assert handle_missing_data in ("drop", "fill_none"), f"Invalid handle_missing_data mode: {handle_missing_data}"
|
75 |
assert files_suffix == "npz", "Only npz supported right now (though trivial to update)"
|
|
|
77 |
self.handle_missing_data = handle_missing_data
|
78 |
self.suffix = files_suffix
|
79 |
self.files_per_repr, self.file_names = self._build_dataset()
|
80 |
+
if task_types is None:
|
81 |
+
logger.debug("No explicit task types. Defaulting all of them to NpzRepresentation.")
|
82 |
+
task_types = {}
|
83 |
|
84 |
if task_names is None:
|
85 |
task_names = list(self.files_per_repr.keys())
|
86 |
logger.debug(f"No explicit tasks provided. Using all of them as read from the paths ({len(task_names)}).")
|
87 |
+
self.task_types = {k: task_types.get(k, NpzRepresentation) for k in task_names}
|
88 |
assert all(isinstance(x, str) for x in task_names), tuple(zip(task_names, (type(x) for x in task_names)))
|
89 |
self.task_names = sorted(task_names)
|
90 |
self._data_shape: tuple[int, ...] | None = None
|
|
|
109 |
"""
|
110 |
if self._tasks is not None:
|
111 |
return self._tasks
|
112 |
+
self._tasks = [self.task_types[task_name](task_name) for task_name in self.task_names]
|
113 |
return self._tasks
|
114 |
|
115 |
def collate_fn(self, items: list[MultiTaskItem]) -> MultiTaskItem:
|
scripts/dronescapes_viewer.ipynb
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
scripts/dronescapes_viewer.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
import sys
|
3 |
from pathlib import Path
|
|
|
4 |
from dronescapes_reader import MultiTaskDataset
|
5 |
from pprint import pprint
|
6 |
from torch.utils.data import DataLoader
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
import sys
|
3 |
from pathlib import Path
|
4 |
+
sys.path.append(Path.cwd().parent.__str__())
|
5 |
from dronescapes_reader import MultiTaskDataset
|
6 |
from pprint import pprint
|
7 |
from torch.utils.data import DataLoader
|