MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / HyperSim

Class HyperSim

dzoedepth/data/hypersim.py:98–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97
98class HyperSim(Dataset):
99 def __init__(self, data_dir_root):
100 # image paths are of the form <data_dir_root>/<scene>/images/scene_cam_#_final_preview/*.tonemap.jpg
101 # depth paths are of the form <data_dir_root>/<scene>/images/scene_cam_#_final_preview/*.depth_meters.hdf5
102 self.image_files = glob.glob(os.path.join(
103 data_dir_root, '*', 'images', 'scene_cam_*_final_preview', '*.tonemap.jpg'))
104 self.depth_files = [r.replace("_final_preview", "_geometry_hdf5").replace(
105 ".tonemap.jpg", ".depth_meters.hdf5") for r in self.image_files]
106 self.transform = ToTensor()
107
108 def __getitem__(self, idx):
109 image_path = self.image_files[idx]
110 depth_path = self.depth_files[idx]
111
112 image = np.asarray(Image.open(image_path), dtype=np.float32) / 255.0
113
114 # depth from hdf5
115 depth_fd = h5py.File(depth_path, "r")
116 # in meters (Euclidean distance)
117 distance_meters = np.array(depth_fd['dataset'])
118 depth = hypersim_distance_to_depth(
119 distance_meters) # in meters (planar depth)
120
121 # depth[depth > 8] = -1
122 depth = depth[..., None]
123
124 sample = dict(image=image, depth=depth)
125 sample = self.transform(sample)
126
127 if idx == 0:
128 print(sample["image"].shape)
129
130 return sample
131
132 def __len__(self):
133 return len(self.image_files)
134
135
136def get_hypersim_loader(data_dir_root, batch_size=1, **kwargs):

Callers 1

get_hypersim_loaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected