Spaces:
Running
on
Zero
Running
on
Zero
File size: 4,855 Bytes
1ea89dd |
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 |
import json
import os
import h5py
import numpy as np
import torch
from unik3d.datasets.image_dataset import ImageDataset
from unik3d.datasets.sequence_dataset import SequenceDataset
from unik3d.datasets.utils import DatasetFromList
class ETH3D(ImageDataset):
min_depth = 0.01
max_depth = 50.0
depth_scale = 1000.0
test_split = "train.txt"
train_split = "train.txt"
intrisics_file = "intrinsics.json"
hdf5_paths = ["ETH3D.hdf5"]
def __init__(
self,
image_shape,
split_file,
test_mode,
benchmark=False,
augmentations_db={},
normalize=True,
resize_method="hard",
mini=1.0,
**kwargs,
):
super().__init__(
image_shape=image_shape,
split_file=split_file,
test_mode=test_mode,
benchmark=benchmark,
normalize=normalize,
augmentations_db=augmentations_db,
resize_method=resize_method,
mini=mini,
**kwargs,
)
self.test_mode = test_mode
self.load_dataset()
def load_dataset(self):
h5file = h5py.File(
os.path.join(self.data_root, self.hdf5_paths[0]),
"r",
libver="latest",
swmr=True,
)
txt_file = np.array(h5file[self.split_file])
txt_string = txt_file.tostring().decode("ascii")[:-1] # correct the -1
intrinsics = np.array(h5file[self.intrisics_file]).tostring().decode("ascii")
intrinsics = json.loads(intrinsics)
h5file.close()
dataset = []
for line in txt_string.split("\n"):
image_filename, depth_filename = line.strip().split(" ")
intrinsics_val = torch.tensor(intrinsics[image_filename]).squeeze()[:, :3]
sample = [image_filename, depth_filename, intrinsics_val]
dataset.append(sample)
self.dataset = DatasetFromList(dataset)
self.log_load_dataset()
def pre_pipeline(self, results):
results = super().pre_pipeline(results)
results["dense"] = [True] * self.num_frames * self.num_copies
results["quality"] = [1] * self.num_frames * self.num_copies
return results
class ETH3D_F(SequenceDataset):
min_depth = 0.05
max_depth = 60.0
depth_scale = 1000.0
test_split = "train.txt"
train_split = "train.txt"
sequences_file = "sequences.json"
hdf5_paths = ["ETH3D-F.hdf5"]
def __init__(
self,
image_shape: tuple[int, int],
split_file: str,
test_mode: bool,
normalize: bool,
augmentations_db: dict[str, float],
resize_method: str,
mini: float = 1.0,
num_frames: int = 1,
benchmark: bool = False,
decode_fields: list[str] = ["image", "depth"],
inplace_fields: list[str] = ["camera_params", "cam2w"],
**kwargs,
) -> None:
super().__init__(
image_shape=image_shape,
split_file=split_file,
test_mode=test_mode,
benchmark=benchmark,
normalize=normalize,
augmentations_db=augmentations_db,
resize_method=resize_method,
mini=mini,
num_frames=num_frames,
decode_fields=(
decode_fields if not test_mode else [*decode_fields, "points"]
),
inplace_fields=inplace_fields,
**kwargs,
)
def pre_pipeline(self, results):
results = super().pre_pipeline(results)
results["dense"] = [True] * self.num_frames * self.num_copies
results["quality"] = [1] * self.num_frames * self.num_copies
return results
class ETH3DRMVD(SequenceDataset):
min_depth = 0.01
max_depth = 50.0
depth_scale = 1000.0
default_fps = 6
test_split = "test.txt"
train_split = "test.txt"
sequences_file = "sequences.json"
hdf5_paths = ["eth3d_rmvd.hdf5"]
def __init__(
self,
image_shape,
split_file,
test_mode,
crop=None,
augmentations_db={},
normalize=True,
resize_method="hard",
mini: float = 1.0,
num_frames: int = 1,
benchmark: bool = False,
decode_fields: list[str] = ["image", "depth"],
inplace_fields: list[str] = ["K", "cam2w"],
**kwargs,
):
super().__init__(
image_shape=image_shape,
split_file=split_file,
test_mode=test_mode,
benchmark=benchmark,
normalize=normalize,
augmentations_db=augmentations_db,
resize_method=resize_method,
mini=mini,
num_frames=num_frames,
decode_fields=decode_fields,
inplace_fields=inplace_fields,
**kwargs,
)
|