Skip to content

Commit 341cede

Browse files
committed
updated s3d data prep instructions
1 parent 19dd303 commit 341cede

File tree

3 files changed

+51
-45
lines changed

3 files changed

+51
-45
lines changed

prepare_data/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,9 @@ MultiScan/
194194
```bash
195195
bash prepare_data/structured3d/unzip_data.sh
196196
python prepare_data/structured3d/move_data.py
197-
python prepare_data/structured3d/move_annotation.py
198197
```
199198
This should have moved all downloaded data to one folder - Structured3D. After verifying this, we move the data into a subdirectory to be in accordance with the structure our preprocessing expects using the following commands:
200199
```bash
201-
cd Structured3D
202-
mkdir scans
203200
bash prepare_data/structured3d/move2scan.sh
204201
```
205202
At this stage data should look like this:

prepare_data/structured3d/move2scan.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#!/bin/bash
22

3-
# Define the base directory (current directory in this case)
4-
BASE_DIR="/Users/gauravpradeep/CrossOver_ScaleUp/Structured3D"
5-
3+
DATA_DIR="/Users/gauravpradeep/CrossOver_ScaleUp/extracted/Structured3D_bbox/Structured3D" #this should be where all the data was moved-basically the structured3d dir within s3d_bbox
4+
TARGET_DIR="/Users/gauravpradeep/CrossOver_ScaleUp/Structured3D" #this should be the final structured3d dir where you want to move the scans
65
# Define the target subfolder
7-
SCANS_DIR="$BASE_DIR/scans"
6+
SCANS_DIR="$TARGET_DIR/scans"
87

98
# Create the scans folder if it doesn't exist
109
mkdir -p "$SCANS_DIR"
1110

1211
# Move all files and directories (except "scans" itself) into the scans folder
13-
for item in "$BASE_DIR"/*; do
12+
for item in "$DATA_DIR"/*; do
1413
# Skip the scans directory
1514
if [[ "$(basename "$item")" == "scans" ]]; then
1615
continue
Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,79 @@
11
import os
22
import shutil
3-
4-
def combine_files(base_folder_1, base_folder_2):
3+
import os.path as osp
4+
def combine_files(in_folder, out_folder):
55
count = 0
66
# Iterate through scenes in the first base folder
7-
for scene in os.listdir(base_folder_1):
8-
scene_path_1 = os.path.join(base_folder_1, scene)
9-
scene_path_2 = os.path.join(base_folder_2, scene) # Corresponding scene in the second base folder
10-
11-
if not os.path.isdir(scene_path_1) or not os.path.isdir(scene_path_2):
7+
for scene in os.listdir(in_folder):
8+
scene_path_in = os.path.join(in_folder, scene)
9+
scene_path_out = os.path.join(out_folder, scene) # Corresponding scene in the second base folder
10+
print(f"Processing scene: {scene_path_in} -> {scene_path_out}")
11+
if not os.path.isdir(scene_path_in) or not os.path.isdir(scene_path_out):
1212
continue
13+
annotation_file_in = os.path.join(scene_path_in, "annotation_3d.json")
14+
annotation_file_out = os.path.join(scene_path_out, "annotation_3d.json")
15+
# print(f"Annotation file in: {annotation_file_in}, Annotation file out: {annotation_file_out}")
16+
shutil.move(annotation_file_in, annotation_file_out)
17+
print(f"Moved {annotation_file_in} to {annotation_file_out}")
1318

14-
rendering_path_1 = os.path.join(scene_path_1, "2D_rendering")
15-
rendering_path_2 = os.path.join(scene_path_2, "2D_rendering")
16-
17-
if not os.path.exists(rendering_path_1) or not os.path.exists(rendering_path_2):
19+
rendering_path_in = os.path.join(scene_path_in, "2D_rendering")
20+
rendering_path_out = os.path.join(scene_path_out, "2D_rendering")
21+
print(f"Rendering path in: {rendering_path_in}, Rendering path out: {rendering_path_out}")
22+
if not os.path.exists(rendering_path_in) or not os.path.exists(rendering_path_out):
1823
continue
1924

2025
# Iterate through render IDs
21-
for render_id in os.listdir(rendering_path_1):
22-
render_path_1 = os.path.join(rendering_path_1, render_id)
23-
render_path_2 = os.path.join(rendering_path_2, render_id)
26+
for render_id in os.listdir(rendering_path_in):
27+
print("hello")
28+
render_path_in = os.path.join(rendering_path_in, render_id)
29+
render_path_out = os.path.join(rendering_path_out, render_id)
2430

25-
perspective_path_1 = os.path.join(render_path_1, "perspective", "full")
26-
perspective_path_2 = os.path.join(render_path_2, "perspective", "full")
31+
perspective_path_in = os.path.join(render_path_in, "perspective", "full")
32+
perspective_path_out = os.path.join(render_path_out, "perspective", "full")
33+
print(f"Perspective path in: {perspective_path_in}, Perspective path out: {perspective_path_out}")
2734

28-
if not os.path.exists(perspective_path_1) or not os.path.exists(perspective_path_2):
35+
if not os.path.exists(perspective_path_in) or not os.path.exists(perspective_path_out):
2936
continue
30-
37+
print(f"Processing render ID: {render_id} -> {render_path_in} -> {render_path_out}")
3138
# Iterate through views in the perspective folder
32-
for view in os.listdir(perspective_path_1):
33-
view_path_1 = os.path.join(perspective_path_1, view)
34-
view_path_2 = os.path.join(perspective_path_2, view)
39+
for view in os.listdir(perspective_path_in):
40+
view_path_in = os.path.join(perspective_path_in, view)
41+
view_path_out = os.path.join(perspective_path_out, view)
42+
print(f"Processing view: {view_path_in} -> {view_path_out}")
3543

36-
if not os.path.isdir(view_path_1) or not os.path.isdir(view_path_2):
44+
if not os.path.isdir(view_path_in) or not os.path.isdir(view_path_out):
3745
continue
3846

3947
# Check if instance.png exists in the target perspective folder
40-
instance_file = os.path.join(view_path_2, "instance.png")
48+
instance_file = os.path.join(view_path_out, "instance.png")
4149
if not os.path.exists(instance_file):
42-
print(f"No instance.png found in {view_path_2}. Skipping.")
50+
print(f"No instance.png found in {view_path_out}. Skipping.")
4351
continue
4452

4553
# Move all files from the source folder to the target folder
46-
for file_name in os.listdir(view_path_1):
47-
source_file = os.path.join(view_path_1, file_name)
48-
target_file = os.path.join(view_path_2, file_name)
54+
for file_name in os.listdir(view_path_in):
55+
source_file = os.path.join(view_path_in, file_name)
56+
target_file = os.path.join(view_path_out, file_name)
4957

5058
if os.path.isfile(source_file):
5159
print(f"Moving {source_file} to {target_file}")
5260
shutil.move(source_file, target_file)
5361

5462
# Optionally: Remove the now-empty view folder
55-
if not os.listdir(view_path_1):
56-
print(f"Removing empty folder: {view_path_1}")
57-
os.rmdir(view_path_1)
63+
if not os.listdir(view_path_in):
64+
print(f"Removing empty folder: {view_path_in}")
65+
os.rmdir(view_path_in)
5866
count += 1
5967
print(f"Processed {count} scenes.")
6068

6169
if __name__ == "__main__":
62-
DIR_PREFIX='/Users/gauravpradeep/CrossOver_ScaleUp/'
63-
base_folder_2 = DIR_PREFIX+"Structured3D" # Directory with perspective instance.png
64-
# base_folder_1 = "Structured3D-1" # Directory with albedo.png, etc.
65-
66-
for folder in ["Structured3D-1", "Structured3D-2", "Structured3D-3", "Structured3D-4", "Structured3D-5", "Structured3D-6", "Structured3D-7", "Structured3D-8", "Structured3D-9", "Structured3D-11", "Structured3D-12", "Structured3D-13", "Structured3D-14", "Structured3D-15", "Structured3D-16", "Structured3D-17", "Structured3D-18"]:
67-
base_folder_1 = DIR_PREFIX+folder
68-
combine_files(base_folder_1, base_folder_2)
70+
EXTRACTED_DIR='/Users/gauravpradeep/CrossOver_ScaleUp/extracted'
71+
out_dir = osp.join(EXTRACTED_DIR,"Structured3D_bbox/Structured3D") # this dir is the one that has perspective instance.png and bbox3d.json
72+
print(out_dir)
73+
for folder in os.listdir(EXTRACTED_DIR):
74+
if folder == 'Structured3D_bbox':
75+
continue
76+
in_folder = osp.join(EXTRACTED_DIR, folder, "Structured3D")
77+
print(f"Processing folder: {in_folder}")
78+
combine_files(in_folder, out_dir)
6979

0 commit comments

Comments
 (0)