Spaces:
Running
on
Zero
Running
on
Zero
File size: 12,107 Bytes
9e15541 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
import os
from pathlib import Path
from scenedino.datasets.kitti_360_v2 import KITTI360DatasetV2
from datasets.cityscapes.cityscapes_dataset import CityscapesSeg
from datasets.bdd.bdd_dataset import BDDSeg
from .base_dataset import BaseDataset
from .kitti_360 import KITTI360Dataset
from .old_kitti_360 import OldKITTI360Dataset
from .re10k_dataset import RealEstate10kDataset
import torch
# TODO: make more generic -> no more two function
def make_datasets(config) -> tuple[BaseDataset, BaseDataset]:
dataset_type = config.get("type", "KITTI_360")
match dataset_type:
case "KITTI_360":
if config.get("split_path", None) is None:
train_split_path = None
test_split_path = None
else:
train_split_path = Path(config["split_path"]) / "train_files.txt"
test_split_path = Path(config["split_path"]) / "val_files.txt"
train_dataset = KITTI360Dataset(
data_path=Path(config["data_path"]),
pose_path=Path(config["pose_path"]),
split_path=train_split_path,
target_image_size=tuple(config.get("image_size", (192, 640))),
return_stereo=config.get("data_stereo", True),
return_fisheye=config.get("data_fisheye", True),
frame_count=config.get("data_fc", 3),
return_depth=False,
return_segmentation=config.get("data_segmentation", False),
return_occupancy=False,
keyframe_offset=config.get("keyframe_offset", 0),
dilation=config.get("dilation", 1),
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offsets=config.get("fisheye_offset", [10]),
stereo_offsets=config.get("stereo_offset", [1]),
# color_aug=config.get("color_aug", False),
is_preprocessed=config.get("is_preprocessed", False),
)
test_dataset = KITTI360Dataset(
data_path=Path(config["data_path"]),
pose_path=Path(config["pose_path"]),
split_path=test_split_path,
target_image_size=tuple(config.get("image_size", (192, 640))),
return_stereo=config.get("data_stereo", True),
return_fisheye=config.get("data_fisheye", True),
frame_count=config.get("data_fc", 3),
return_depth=True,
return_segmentation=config.get("data_segmentation", False),
return_occupancy=config.get("occupancy", False),
keyframe_offset=config.get("keyframe_offset", 0),
dilation=config.get("dilation", 1),
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offsets=[10],
stereo_offsets=[1],
is_preprocessed=config.get("is_preprocessed", False),
)
return train_dataset, test_dataset
case "old_KITTI_360":
if config.get("split_path", None) is None:
train_split_path = None
test_split_path = None
else:
train_split_path = Path(config["split_path"]) / "train_files.txt"
test_split_path = Path(config["split_path"]) / "test_files.txt"
train_dataset = OldKITTI360Dataset(
data_path=Path(config["data_path"]),
pose_path=Path(config["pose_path"]),
split_path=train_split_path,
target_image_size=tuple(config.get("image_size", (192, 640))),
return_stereo=config.get("data_stereo", True),
return_fisheye=config.get("data_fisheye", True),
frame_count=config.get("data_fc", 3),
return_depth=False,
return_segmentation=config.get("data_segmentation", False),
keyframe_offset=config.get("keyframe_offset", 0),
dilation=config.get("dilation", 1),
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offset=config.get("fisheye_offset", [10]),
# stereo_offsets=config.get("stereo_offset", [1]),
color_aug=config.get("color_aug", False),
is_preprocessed=config.get("is_preprocessed", False),
)
test_dataset = OldKITTI360Dataset(
data_path=Path(config["data_path"]),
pose_path=Path(config["pose_path"]),
split_path=test_split_path,
target_image_size=tuple(config.get("image_size", (192, 640))),
return_stereo=config.get("data_stereo", True),
return_fisheye=config.get("data_fisheye", True),
frame_count=config.get("data_fc", 3),
return_depth=True,
return_segmentation=config.get("data_segmentation", False),
keyframe_offset=config.get("keyframe_offset", 0),
dilation=config.get("dilation", 1),
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offset=[10],
# stereo_offsets=[1],
is_preprocessed=config.get("is_preprocessed", False),
)
return train_dataset, test_dataset
case "KITTI_360_v2":
if config.get("split_path", None) is None:
train_split_path = None
test_split_path = None
else:
train_split_path = Path(config["split_path"]) / "train_files.txt"
test_split_path = Path(config["split_path"]) / "val_files.txt"
train_dataset = KITTI360DatasetV2(
data_path=Path(config["data_path"]),
pose_path=Path(config["pose_path"]),
split_path=train_split_path,
target_image_size=tuple(config.get("image_size", (192, 640))),
return_stereo=config.get("data_stereo", True),
return_fisheye=config.get("data_fisheye", True),
frame_count=config.get("data_fc", 3),
return_depth=False,
return_segmentation=config.get("data_segmentation", False),
keyframe_offset=config.get("keyframe_offset", 0),
dilation=config.get("dilation", 1),
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offset=config.get("fisheye_offset", [10]),
color_aug=config.get("color_aug", False),
is_preprocessed=config.get("is_preprocessed", False),
)
test_dataset = KITTI360DatasetV2(
data_path=Path(config["data_path"]),
pose_path=Path(config["pose_path"]),
split_path=test_split_path,
target_image_size=tuple(config.get("image_size", (192, 640))),
return_stereo=config.get("data_stereo", True),
return_fisheye=config.get("data_fisheye", True),
frame_count=config.get("data_fc", 3),
return_depth=True,
return_segmentation=config.get("data_segmentation", False),
keyframe_offset=config.get("keyframe_offset", 0),
dilation=config.get("dilation", 1),
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offset=[10],
is_preprocessed=config.get("is_preprocessed", False),
)
return train_dataset, test_dataset
case "Cityscapes_seg":
train_dataset = CityscapesSeg(
root=config["data_path"],
image_set="train",
)
test_dataset = CityscapesSeg(
root=config["data_path"],
image_set="val",
)
return train_dataset, test_dataset
case "RealEstate10K":
if config.get("split_path", None) is None:
train_split_path = None
test_split_path = None
else:
train_split_path = Path(config["split_path"]) / "train_files.txt"
test_split_path = Path(config["split_path"]) / "val_files.txt"
train_dataset = RealEstate10kDataset(
data_path=config["data_path"],
split_path=train_split_path,
image_size=config["image_size"],
)
test_dataset = RealEstate10kDataset(
data_path=config["data_path"],
split_path=test_split_path,
image_size=config["image_size"],
)
return train_dataset, test_dataset
case "BDD_seg":
train_dataset = BDDSeg(
root=config["data_path"],
image_set="train",
)
test_dataset = BDDSeg(
root=config["data_path"],
image_set="val",
)
return train_dataset, test_dataset
case _:
raise NotImplementedError(f"Unsupported dataset type: {type}")
def make_test_dataset(config):
dataset_type = config.get("type", "KITTI_Raw")
match dataset_type:
case "KITTI_360":
test_dataset = OldKITTI360Dataset(
data_path=config["data_path"],
pose_path=config["pose_path"],
split_path=os.path.join(
config.get("split_path", None), "test_files.txt"
),
target_image_size=tuple(config.get("image_size", (192, 640))),
frame_count=config.get("data_fc", 1),
return_stereo=config.get("data_stereo", False),
return_fisheye=config.get("data_fisheye", False),
return_3d_bboxes=config.get("data_3d_bboxes", False),
return_segmentation=config.get("data_segmentation", False),
keyframe_offset=0,
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offset=config.get("fisheye_offset", 1),
dilation=config.get("dilation", 1),
is_preprocessed=config.get("is_preprocessed", False),
)
return test_dataset
case "old_KITTI_360":
test_dataset = OldKITTI360Dataset(
data_path=Path(config["data_path"]),
pose_path=Path(config["pose_path"]),
split_path=os.path.join(
config.get("split_path", None), "test_files.txt"
),
target_image_size=tuple(config.get("image_size", (192, 640))),
return_stereo=config.get("data_stereo", True),
return_fisheye=config.get("data_fisheye", True),
frame_count=config.get("data_fc", 3),
return_depth=True,
return_segmentation=config.get("data_segmentation", False),
keyframe_offset=config.get("keyframe_offset", 0),
dilation=config.get("dilation", 1),
fisheye_rotation=config.get("fisheye_rotation", 0),
fisheye_offset=config.get("fisheye_offset", 1),
# stereo_offsets=[1],
is_preprocessed=config.get("is_preprocessed", False),
)
return test_dataset
case "Cityscapes_seg":
test_dataset = CityscapesSeg(
root=config["data_path"],
image_set="val",
)
return test_dataset
case "RealEstate10K":
test_dataset = RealEstate10kDataset(
data_path=config["data_path"],
image_size=config["image_size"],
)
return test_dataset
case "BDD_seg":
test_dataset = BDDSeg(
root=config["data_path"],
image_set="val",
)
return test_dataset
case _:
raise NotImplementedError(f"Unsupported dataset type: {dataset_type}")
|