Skip to content

Commit 18872ea

Browse files
stephenyan1231facebook-github-bot
authored andcommitted
add data generation code for Habitat-Sim (HM3D, Gibson, MP3D)
Summary: Add training data generation code for Habitat-Sim (HM3D, Gibson, MP3D) - `tuple_gen_scannet.sh` generates tuples of RGBD views of scannet (two difficulties).`tuple_gen_hs.sh` generates tuples of RGBD views of all data in habitat-sim (HM3D, Gibson, MP3D). `metadata_gather_scannet.sh` and `metadata_gather_scannet.sh` collects the tuples to form a h5 index file Reviewed By: dilinwang820 Differential Revision: D74629224 fbshipit-source-id: 7f3538e01051afe8655d389cac4091c200a7edbe
1 parent 0d610fd commit 18872ea

27 files changed

Lines changed: 11661 additions & 7 deletions

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Please see more visual results and video on our [website](https://mv-dust3rp.git
1818

1919
## Update Logs
2020

21+
- 2025-5-10: data generation code for Habitat-Sim (HM3D, Gibson, MP3D).
2122
- 2025-1-30: data generation code of ScanNet.
2223
- 2025-1-1: A gradio demo, all checkpoints, training/evaluation code and training/evaluation trajectories of ScanNet.
2324
- 2025-1-8: demo view selection improved, better quality for multiple rooms.
@@ -86,7 +87,9 @@ some [tips](https://github.com/facebookresearch/mvdust3r/issues/5#issuecomment-2
8687

8788
We use five data for training and test: [ScanNet](https://github.com/ScanNet/ScanNet), [ScanNet++](https://kaldir.vc.in.tum.de/scannetpp/), [HM3D](https://aihabitat.org/datasets/hm3d/), [Gibson](https://github.com/StanfordVL/GibsonEnv/blob/master/gibson/data/README.md), [MP3D](https://niessner.github.io/Matterport/). Please go to their website to sign contract, download and extract them in the folder [data](https://github.com/facebookresearch/mvdust3r/tree/main/data). [Here](https://github.com/facebookresearch/mvdust3r/tree/main/data) are more instructions.
8889

89-
Currently we released the [trajectories](https://huggingface.co/Zhenggang/MV-DUSt3R/tree/main/trajectories) of ScanNet for evaluation. Please download it to the folder [trajectories](https://github.com/facebookresearch/mvdust3r/tree/main/trajectories) More trajectories for training and more data will be released later.
90+
Currently we released the [trajectories](https://huggingface.co/Zhenggang/MV-DUSt3R/tree/main/trajectories) of ScanNet for evaluation. Please download it to the folder [trajectories](https://github.com/facebookresearch/mvdust3r/tree/main/trajectories).
91+
92+
We also open-sourced the code to generate train and evaluation trajectories for ScanNet and all datasets in Habitat-Sim (HM3D, Gibson, MP3D). please check [here]. (https://github.com/facebookresearch/mvdust3r/tree/main/scripts/tuple_gen)
9093

9194
## Evaluation
9295

data/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
## Instructions for ScanNet
44

5-
Scannet is structured as many folders named `scenexxxx_xx`. create a folder `scannet` in this directory and put `scene*` inside it.
5+
Scannet is structured as folders `scenexxxx_xx`. create a folder `scannet` in this directory and put `scenexxxx_xx` inside it.
66

7-
## Instructions for other data
7+
## Instructions for other Habitat-Sim (HM3D, Gibson, MP3D)
88

9-
TBD...
9+
HM3D, Gibson, MP3D contains `*.glb` and `*.navmesh` for each scene. put them in `habitat-sim-data/hm3d/train/`, `habitat-sim-data/hm3d/val/`, `habitat-sim-data/gibson/` and `habitat-sim-data/mp3d` for hm3d train, hm3d validation, gibson and mp3d respectively.
10+
11+
Here, we have a file `hs_scene_data.json` as the scene location config.

data/hs_scene_data.json

Lines changed: 8894 additions & 0 deletions
Large diffs are not rendered by default.

datasets_preprocess/gather_metadata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
args.tgt_dir = args.data_dir
2323

2424
def extract_scene_name(x, data_name_):
25+
print(x, data_name_)
2526
if "_meta" == data_name_[-5:]:
2627
data_name = data_name_[:-5]
2728
else:
@@ -34,14 +35,14 @@ def extract_scene_name(x, data_name_):
3435
for x_ in xx:
3536
if 'scene' in x_:
3637
return x_
37-
elif "habitat_sim" in x:
38+
elif "habitat_sim" in x or "habitatSim" in x:
3839
if "gibson" in x:
3940
return 'gibson'
4041
if "mp3d" in x:
4142
return "mp3d"
4243
xx = x.split('/')
4344
for x_ in xx:
44-
if x_[5] == "-":
45+
if len(x_) >= 6 and x_[5] == "-":
4546
return x_
4647
raise NotImplementedError
4748

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Requirement already satisfied: numpy in /home/zt15/miniconda3/envs/habitat/lib/python3.9/site-packages (1.24.4)

datasets_preprocess/hs_data_gen/__init__.py

Whitespace-only changes.

datasets_preprocess/hs_data_gen/datasets/__init__.py

Whitespace-only changes.

datasets_preprocess/hs_data_gen/datasets/hs/__init__.py

Whitespace-only changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Copyright (C) 2022-present Naver Corporation. All rights reserved.
2+
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
3+
4+
"""
5+
Script to generate image pairs for a given scene reproducing poses provided in a metadata file.
6+
"""
7+
import os
8+
import sys
9+
sys.path.append("/home/zgtang/data_gen/croco/")
10+
print(sys.path)
11+
from datasets.hs.multiview_habitat_sim_generator import MultiviewHabitatSimGenerator
12+
from datasets.hs.paths import SCENES_DATASET
13+
import argparse
14+
import quaternion
15+
import PIL.Image
16+
import cv2
17+
import json
18+
from tqdm import tqdm
19+
20+
def generate_multiview_images_from_metadata(metadata_filename,
21+
output_dir,
22+
overload_params = dict(),
23+
scene_datasets_paths=None,
24+
exist_ok=False):
25+
"""
26+
Generate images from a metadata file for reproducibility purposes.
27+
"""
28+
# Reorder paths by decreasing label length, to avoid collisions when testing if a string by such label
29+
if scene_datasets_paths is not None:
30+
scene_datasets_paths = dict(sorted(scene_datasets_paths.items(), key= lambda x: len(x[0]), reverse=True))
31+
32+
with open(metadata_filename, 'r') as f:
33+
input_metadata = json.load(f)
34+
metadata = dict()
35+
for key, value in input_metadata.items():
36+
# Optionally replace some paths
37+
if key in ("scene_dataset_config_file", "scene", "navmesh") and value != "":
38+
if scene_datasets_paths is not None:
39+
for dataset_label, dataset_path in scene_datasets_paths.items():
40+
if value.startswith(dataset_label):
41+
value = os.path.normpath(os.path.join(dataset_path, os.path.relpath(value, dataset_label)))
42+
break
43+
metadata[key] = value
44+
45+
# Overload some parameters
46+
for key, value in overload_params.items():
47+
metadata[key] = value
48+
49+
generation_entries = dict([(key, value) for key, value in metadata.items() if not (key in ('multiviews', 'output_dir', 'generate_depth'))])
50+
generate_depth = metadata["generate_depth"]
51+
52+
os.makedirs(output_dir, exist_ok=exist_ok)
53+
54+
generator = MultiviewHabitatSimGenerator(**generation_entries)
55+
56+
# Generate views
57+
for idx_label, data in tqdm(metadata['multiviews'].items()):
58+
positions = data["positions"]
59+
orientations = data["orientations"]
60+
n = len(positions)
61+
for oidx in range(n):
62+
observation = generator.render_viewpoint(positions[oidx], quaternion.from_float_array(orientations[oidx]))
63+
observation_label = f"{oidx + 1}" # Leonid is indexing starting from 1
64+
# Color image saved using PIL
65+
img = PIL.Image.fromarray(observation['color'][:,:,:3])
66+
filename = os.path.join(output_dir, f"{idx_label}_{observation_label}.jpeg")
67+
img.save(filename)
68+
if generate_depth:
69+
# Depth image as EXR file
70+
filename = os.path.join(output_dir, f"{idx_label}_{observation_label}_depth.exr")
71+
cv2.imwrite(filename, observation['depth'], [cv2.IMWRITE_EXR_TYPE, cv2.IMWRITE_EXR_TYPE_HALF])
72+
# Camera parameters
73+
camera_params = dict([(key, observation[key].tolist()) for key in ("camera_intrinsics", "R_cam2world", "t_cam2world")])
74+
filename = os.path.join(output_dir, f"{idx_label}_{observation_label}_camera_params.json")
75+
with open(filename, "w") as f:
76+
json.dump(camera_params, f)
77+
# Save metadata
78+
with open(os.path.join(output_dir, "metadata.json"), "w") as f:
79+
json.dump(metadata, f)
80+
81+
generator.close()
82+
83+
if __name__ == "__main__":
84+
parser = argparse.ArgumentParser()
85+
parser.add_argument("--metadata_filename", required=True)
86+
parser.add_argument("--output_dir", required=True)
87+
args = parser.parse_args()
88+
89+
generate_multiview_images_from_metadata(metadata_filename=args.metadata_filename,
90+
output_dir=args.output_dir,
91+
scene_datasets_paths=SCENES_DATASET,
92+
overload_params=dict(),
93+
exist_ok=True)
94+
95+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (C) 2022-present Naver Corporation. All rights reserved.
2+
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
3+
4+
"""
5+
Script generating commandlines to generate image pairs from metadata files.
6+
"""
7+
import os
8+
import glob
9+
from tqdm import tqdm
10+
import argparse
11+
12+
if __name__ == "__main__":
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("--input_dir", required=True)
15+
parser.add_argument("--output_dir", required=True)
16+
parser.add_argument("--prefix", default="", help="Commanline prefix, useful e.g. to setup environment.")
17+
args = parser.parse_args()
18+
19+
input_metadata_filenames = glob.iglob(f"{args.input_dir}/**/metadata.json", recursive=True)
20+
21+
for metadata_filename in tqdm(input_metadata_filenames):
22+
output_dir = os.path.join(args.output_dir, os.path.relpath(os.path.dirname(metadata_filename), args.input_dir))
23+
# Do not process the scene if the metadata file already exists
24+
if os.path.exists(os.path.join(output_dir, "metadata.json")):
25+
continue
26+
commandline = f"{args.prefix}python datasets/habitat_sim/generate_from_metadata.py --metadata_filename={metadata_filename} --output_dir={output_dir}"
27+
print(commandline)

0 commit comments

Comments
 (0)