Datasets:
delete py files under project root path (#2)
Browse files- delete py files under project root path (d5800d3122e2c885f224ea0d29b7838a68a85c53)
- Delete v2b_dataset.py (a8b649566fb7ed57a8a048dea1c6b9487afafa6a)
- pyproject.toml +0 -18
- v2b_dataset.py +0 -108
pyproject.toml
DELETED
|
@@ -1,18 +0,0 @@
|
|
| 1 |
-
[project]
|
| 2 |
-
name = "v2b-demo-loader"
|
| 3 |
-
version = "0.1.0"
|
| 4 |
-
|
| 5 |
-
dependencies = [
|
| 6 |
-
"numpy",
|
| 7 |
-
"torch",
|
| 8 |
-
]
|
| 9 |
-
|
| 10 |
-
[tool.ruff.format]
|
| 11 |
-
quote-style = "single"
|
| 12 |
-
|
| 13 |
-
# [tool.uv.sources]
|
| 14 |
-
# torch = { index = "pytorch" }
|
| 15 |
-
|
| 16 |
-
# [[tool.uv.index]]
|
| 17 |
-
# name = "pytorch"
|
| 18 |
-
# url = "https://download.pytorch.org/whl/cpu"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v2b_dataset.py
DELETED
|
@@ -1,108 +0,0 @@
|
|
| 1 |
-
from collections import defaultdict
|
| 2 |
-
import dataclasses
|
| 3 |
-
from dataclasses import dataclass, field
|
| 4 |
-
from itertools import chain
|
| 5 |
-
import json
|
| 6 |
-
from pathlib import Path
|
| 7 |
-
from typing import Iterable, Literal
|
| 8 |
-
|
| 9 |
-
from torch.utils.data import Dataset
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
@dataclass
|
| 13 |
-
class JsonlEntry:
|
| 14 |
-
id: int
|
| 15 |
-
split: Literal['train', 'test']
|
| 16 |
-
modality: Literal['google', 'satellite', 'street', 'drone']
|
| 17 |
-
path: str
|
| 18 |
-
angle: int | None = None
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
@dataclass
|
| 22 |
-
class DatasetEntry:
|
| 23 |
-
id: int | None = None
|
| 24 |
-
satellite: str | None = None
|
| 25 |
-
drone_30: str | None = None
|
| 26 |
-
drone_45: str | None = None
|
| 27 |
-
street: list[str] = field(default_factory=list)
|
| 28 |
-
google: list[str] = field(default_factory=list)
|
| 29 |
-
|
| 30 |
-
def update(self, entry: JsonlEntry) -> None:
|
| 31 |
-
if self.id is None:
|
| 32 |
-
self.id = entry.id
|
| 33 |
-
else:
|
| 34 |
-
if self.id != entry.id:
|
| 35 |
-
raise ValueError(f'unmatched id {self.id=} != {entry.id=}')
|
| 36 |
-
|
| 37 |
-
path = entry.path
|
| 38 |
-
match entry.modality:
|
| 39 |
-
case 'street':
|
| 40 |
-
self.street.append(path)
|
| 41 |
-
case 'google':
|
| 42 |
-
self.google.append(path)
|
| 43 |
-
case 'satellite':
|
| 44 |
-
self.satellite = path
|
| 45 |
-
case 'drone':
|
| 46 |
-
if entry.angle == 30:
|
| 47 |
-
self.drone_30 = path
|
| 48 |
-
elif entry.angle == 45:
|
| 49 |
-
self.drone_45 = path
|
| 50 |
-
else:
|
| 51 |
-
raise ValueError(f'unexpected angle: {entry.angle}')
|
| 52 |
-
case _:
|
| 53 |
-
raise ValueError(f'unexpected modality: {entry.modality}')
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def read_all_entries(index: Path):
|
| 57 |
-
with index.open('r') as f:
|
| 58 |
-
for line in f:
|
| 59 |
-
yield json.loads(line.strip())
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
def get_indecies(root: Path, split: Literal['train', 'test']) -> list[Path]:
|
| 63 |
-
index_path = root / 'meta' / 'index'
|
| 64 |
-
res = sorted(index_path.glob(f'{split}-shard*.jsonl'))
|
| 65 |
-
if len(res) == 0:
|
| 66 |
-
raise ValueError('no index file found')
|
| 67 |
-
|
| 68 |
-
return res
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
def collect(indecies: Iterable[Path]):
|
| 72 |
-
res = defaultdict(DatasetEntry)
|
| 73 |
-
for entryobj in chain(*map(read_all_entries, indecies)):
|
| 74 |
-
assert isinstance(entryobj, dict)
|
| 75 |
-
entry = JsonlEntry(**entryobj)
|
| 76 |
-
res[entry.id].update(entry)
|
| 77 |
-
|
| 78 |
-
return res
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
class V2BDemoDataset(Dataset):
|
| 82 |
-
def __init__(self, root: str | Path, split: Literal['train', 'test']) -> None:
|
| 83 |
-
super().__init__()
|
| 84 |
-
self.root = Path(root)
|
| 85 |
-
self.split = split
|
| 86 |
-
|
| 87 |
-
self.index = collect(get_indecies(self.root, self.split))
|
| 88 |
-
self.ids = sorted(self.index.keys())
|
| 89 |
-
|
| 90 |
-
def __getitem__(self, index):
|
| 91 |
-
building_id = self.ids[index]
|
| 92 |
-
entry = self.index[building_id]
|
| 93 |
-
|
| 94 |
-
return dataclasses.asdict(entry)
|
| 95 |
-
|
| 96 |
-
def __len__(self):
|
| 97 |
-
return len(self.ids)
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
def main():
|
| 101 |
-
ds = V2BDemoDataset(Path('../'), 'train')
|
| 102 |
-
print(ds[0])
|
| 103 |
-
print(len(ds))
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
if __name__ == '__main__':
|
| 107 |
-
main()
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|