Skip to content

Commit a348e33

Browse files
committed
bugfix: Fix issues in MPEG sequence preprocessing script and README documentation
1 parent 69b585c commit a348e33

File tree

8 files changed

+209
-68
lines changed

8 files changed

+209
-68
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ conda activate gscodec_studio
1818

1919
### Packages Installation
2020

21-
Please install [Pytorch](https://pytorch.org/get-started/locally/) first.
22-
23-
Then, you can install the gsplat library extended with more compression features from source code. In this way it will build the CUDA code during installation.
21+
Please install [Pytorch](https://pytorch.org/get-started/locally/) first. Then, you can install the gsplat library extended with more compression features from source code. In this way it will build the CUDA code during installation.
2422

2523
```bash
2624
pip install .
27-
# pip install -e . (develop mode)
25+
```
26+
27+
If you want to do further development based on this framework, you use following command to install Python packages in editable mode.
28+
```bash
29+
pip install -e . # (develop)
2830
```
2931

3032
## Examples
@@ -38,7 +40,10 @@ cd examples
3840
pip install -r requirements.txt
3941
# download mipnerf_360 benchmark data
4042
python datasets/download_dataset.py
41-
# or place other dataset under 'data' folder
43+
```
44+
You can download the Tanks and Temples dataset and Deep Blending dataset used in original 3DGS via [this link](https://repo-sam.inria.fr/fungraph/3d-gaussian-splatting/datasets/input/tandt_db.zip) and place these datasets under 'data' folder.
45+
```bash
46+
# place other dataset, e.g Tanks and Temples dataset, under 'data' folder
4247
ln -s data/tandt /xxxx/Dataset/tandt
4348
```
4449

@@ -67,7 +72,7 @@ bash benchmarks/compression/final_exp/mcmc_tt_sim.sh
6772

6873
**Dynamic Gaussian Splats Training and Compression**
6974

70-
First, please follow the dataset preprocessing instruction described in the [file]((mpeg_gsc_utils/multiview_video_preprocess/README.md)) for training data prepration.
75+
First, please follow the dataset preprocessing instruction described in the [file](mpeg_gsc_utils/multiview_video_preprocess/README.md) for training data prepration.
7176

7277
Next, run the script for dynamic gaussian splats training and compression.
7378
```bash

examples/benchmarks/dyngs/dyngs.sh

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
SCENE_DIR="data/GSC"
2-
SCENE_LIST="Bartender" # CBA Bartender
2+
SCENE_LIST="Cinema" # CBA Bartender Cinema
33

44
declare -A TEST_VIEWS
55
TEST_VIEWS=(
66
["CBA"]="7 22"
77
["Bartender"]="8 10 12"
8+
["Cinema"]="8 10 12"
89
)
910

1011
declare -A START_FRAMES
1112
START_FRAMES=(
1213
["CBA"]=0
1314
["Bartender"]=50
15+
["Cinema"]=235
1416
)
1517

1618
RESULT_DIR="results/dyngs"
@@ -25,22 +27,24 @@ run_single_scene() {
2527

2628
echo "Running $SCENE START_FRAME @ ${START_FRAME}"
2729

28-
# CUDA_VISIBLE_DEVICES=$GPU_ID python simple_trainer_dyngs.py compression_sim \
29-
# --model_path $RESULT_DIR/$SCENE/ \
30-
# --data_dir $SCENE_DIR/$SCENE/colmap/colmap_${START_FRAME} \
31-
# --result_dir $RESULT_DIR/$SCENE/ \
32-
# --downscale_factor 1 \
33-
# --duration $NUM_FRAME \
34-
# --batch_size 2 \
35-
# --max_steps 60_000 \
36-
# --refine_start_iter 3_000 \
37-
# --refine_stop_iter 30_000 \
38-
# --refine_every 100 \
39-
# --reset_every 6_000 \
40-
# --pause_refine_after_reset 500 \
41-
# --strategy Modified_STG_Strategy \
42-
# --test_view_id $TEST_VIEW_IDS
30+
# execute training
31+
CUDA_VISIBLE_DEVICES=$GPU_ID python simple_trainer_dyngs.py compression_sim \
32+
--model_path $RESULT_DIR/$SCENE/ \
33+
--data_dir $SCENE_DIR/$SCENE/colmap/colmap_${START_FRAME} \
34+
--result_dir $RESULT_DIR/$SCENE/ \
35+
--downscale_factor 1 \
36+
--duration $NUM_FRAME \
37+
--batch_size 2 \
38+
--max_steps 60_000 \
39+
--refine_start_iter 3_000 \
40+
--refine_stop_iter 30_000 \
41+
--refine_every 100 \
42+
--reset_every 6_000 \
43+
--pause_refine_after_reset 500 \
44+
--strategy Modified_STG_Strategy \
45+
--test_view_id $TEST_VIEW_IDS
4346

47+
# execute evaluation and compression
4448
CUDA_VISIBLE_DEVICES=$GPU_ID python simple_trainer_dyngs.py default \
4549
--model_path $RESULT_DIR/$SCENE/ \
4650
--data_dir $SCENE_DIR/$SCENE/colmap/colmap_${START_FRAME} \
@@ -53,7 +57,7 @@ run_single_scene() {
5357
--test_view_id $TEST_VIEW_IDS
5458
}
5559

56-
GPU_LIST=(6)
60+
GPU_LIST=(0)
5761
GPU_COUNT=${#GPU_LIST[@]}
5862

5963
SCENE_IDX=-1

mpeg_gsc_utils/multiview_video_preprocess/README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
**MPEG Multiview Video Dataset**
55
Please organize the data structure as follows:
66

7+
```
78
data/
89
├── GSC
910
│ ├── scene1/
@@ -14,25 +15,43 @@ data/
1415
│ │ │ ├── v00_texture_1920x1080_yuv420p10le.yuv
1516
│ │ │ ├── v01_texture_1920x1080_yuv420p10le.yuv
1617
│ │ │ ├── ...
17-
│ ├── scene1/
18+
│ ├── scene2/
1819
│ │ ├── colmap
1920
│ │ ├── mp4
2021
│ │ ├── png
2122
│ │ ├── yuv
2223
│ │ │ ├── v00_texture_1920x1080_yuv420p10le.yuv
2324
│ │ │ ├── v01_texture_1920x1080_yuv420p10le.yuv
2425
│ │ │ ├── ...
26+
```
27+
28+
## Preliminaries
29+
The following series of preprocessing operations for MPEG datasets requires **Colmap** and **ffmpeg** to be installed in advance.
2530

2631
## Operations
32+
1. Before you start, please open ``mpeg_gsc_utils/multiview_video_preprocess/scene_info.py`` and fill in some necessary metadata for the Scene you are going to convert.
33+
For now, we have already prepared the metadata for Bartender and Cinema.
34+
2735
1. Convert multiview videos in "yuv" format to "mp4" format and "png" format
2836
```bash
29-
python mpeg_gsc_utils/multiview_video_preprocess/video_preprocess.py
30-
```
37+
python mpeg_gsc_utils/multiview_video_preprocess/video_preprocess.py \
38+
--scene Cinema
39+
```
40+
41+
For the script mentioned above, you must specify the scene name. Additionally, if you haven't placed your data under ``examples/data/GSC/{scene}``, you can manually specify your base_dir by passing ``--base_dir``.
42+
3143
2. Obtain the camera intrinsic and extrinsic parameters and save as "poses_bds.npy" file
3244
```bash
33-
python mpeg_gsc_utils/multiview_video_preprocess/gen_poses_bds.py
45+
python mpeg_gsc_utils/multiview_video_preprocess/gen_poses_bds_file.py \
46+
--scene Cinema
3447
```
48+
49+
For the script mentioned above, you must specify the scene name. Additionally, if you haven't placed your data under ``examples/data/GSC/{scene}``, you can manually specify your base_dir by passing ``--base_dir``.You can also select a specific number of frames by passing ``--frame_num``.
50+
3551
3. Run colmap frame by frame to get per-frame SfM point clouds
3652
```bash
37-
python mpeg_gsc_utils/multiview_video_preprocess/run_per_frame_colmap.py
38-
```
53+
python mpeg_gsc_utils/multiview_video_preprocess/run_per_frame_colmap.py \
54+
--scene Cinema
55+
```
56+
57+
For the script mentioned above, you must specify the scene name. Additionally, if you haven't placed your data under ``examples/data/GSC/{scene}``, you can manually specify your base_dir by passing ``--base_dir``.You can also select a specific number of frames by passing ``--frame_num``.

mpeg_gsc_utils/multiview_video_preprocess/gen_poses_bds_file.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from pathlib import Path
55
import shutil
66
from tqdm import trange
7+
import tyro
8+
from dataclasses import dataclass
9+
from typing import Optional
710

811
from mpeg_gsc_utils import colmap_read_model as read_model
912
from scene_info import DATASET_INFOS
@@ -211,42 +214,74 @@ def gen_poses(basedir, match_type, factors=None):
211214

212215
return True
213216

214-
if __name__ == "__main__":
215-
SCENE = "Bartender"
216-
BASE_DIR = f"/work/Users/lisicheng/Dataset/GSC/{SCENE}"
217+
@dataclass
218+
class FramePrepConfig:
219+
"""Configuration for preparing frame data and generating poses"""
220+
scene: str
221+
"""Scene name (e.g., Bartender)"""
222+
223+
base_dir: Optional[str] = None
224+
"""Base directory path. If not provided, defaults to examples/data/GSC/{scene}"""
225+
226+
frame_num: int = 65
227+
"""Number of frames to process"""
228+
229+
match_type: str = "exhaustive_matcher"
230+
"""Matcher type for pose generation"""
231+
232+
def main(config: FramePrepConfig):
233+
# Process parameters
234+
SCENE = config.scene
235+
BASE_DIR = config.base_dir if config.base_dir else f"examples/data/GSC/{SCENE}"
217236
COLMAP_DIR = BASE_DIR + "/colmap"
218-
FRAME_NUM = 65
237+
FRAME_NUM = config.frame_num
219238
START_FRAME = DATASET_INFOS[SCENE]["start_frame"]
220239

221-
# copy png to each sub colmap dir
222-
imgs_source_dir = Path(BASE_DIR + f"/png")
240+
# Create COLMAP directory if it doesn't exist
241+
os.makedirs(COLMAP_DIR, exist_ok=True)
223242

243+
print(f"Processing scene {SCENE} with {FRAME_NUM} frames starting from {START_FRAME}")
244+
print(f"Base directory: {BASE_DIR}")
245+
print(f"Working directory: {COLMAP_DIR}")
246+
247+
# Copy png to each frame directory
248+
imgs_source_dir = Path(BASE_DIR + f"/png")
249+
250+
print("Creating frame directories and copying images...")
224251
for f_idx in trange(START_FRAME, START_FRAME+FRAME_NUM):
225252
colmap_frame_dir = COLMAP_DIR + f"/colmap_{f_idx}"
226253
os.makedirs(colmap_frame_dir, exist_ok=True)
227-
imgs_target_dir = colmap_frame_img_dir = Path(colmap_frame_dir + f"/input")
254+
imgs_target_dir = Path(colmap_frame_dir + f"/input")
228255
os.makedirs(imgs_target_dir, exist_ok=True)
229256

230257
for file in sorted(imgs_source_dir.glob(f"*{f_idx+1:03d}.png")):
231258
new_filenanme = file.name.split("_")[0] + ".png"
232259
shutil.copy2(file, imgs_target_dir / new_filenanme)
233260

234-
# just a work-around for generating poses_bounds.npy
261+
# Just a work-around for generating poses_bounds.npy
235262
if f_idx == START_FRAME:
236263
colmap_frame_dir = COLMAP_DIR + f"/colmap_{f_idx}"
237264
os.makedirs(colmap_frame_dir, exist_ok=True)
238-
imgs_target_dir = colmap_frame_img_dir = Path(colmap_frame_dir + f"/images")
265+
imgs_target_dir = Path(colmap_frame_dir + f"/images")
239266
os.makedirs(imgs_target_dir, exist_ok=True)
240267

241268
for file in sorted(imgs_source_dir.glob(f"*{f_idx+1:03d}.png")):
242269
new_filenanme = file.name.split("_")[0] + ".png"
243270
shutil.copy2(file, imgs_target_dir / new_filenanme)
244271

245-
# # get "poses_bounds.npy"
272+
# Generate poses_bounds.npy
273+
print("Generating poses_bounds.npy using COLMAP...")
246274
colmap_first_frame_dir = COLMAP_DIR + f"/colmap_{START_FRAME}"
247275
if not os.path.exists(colmap_first_frame_dir + "/poses_bounds.npy"):
248-
gen_poses(colmap_first_frame_dir, match_type="exhaustive_matcher")
276+
gen_poses(colmap_first_frame_dir, match_type=config.match_type)
249277

250-
# # move to basedir of the specific scene
278+
# Move poses_bounds.npy to the base directory
279+
print("Copying poses_bounds.npy to base directory...")
251280
shutil.copy2(colmap_first_frame_dir + "/poses_bounds.npy", COLMAP_DIR)
252-
shutil.rmtree(colmap_first_frame_dir + "/images")
281+
shutil.rmtree(colmap_first_frame_dir + "/images")
282+
283+
print("Frame preparation and pose generation completed!")
284+
285+
if __name__ == "__main__":
286+
config = tyro.cli(FramePrepConfig)
287+
main(config)

mpeg_gsc_utils/multiview_video_preprocess/run_per_frame_colmap.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import numpy as np
44
from pathlib import Path
55
from tqdm import trange
6+
import tyro
7+
from dataclasses import dataclass
8+
from typing import Optional
69

710
from scene_info import DATASET_INFOS
811
from mpeg_gsc_utils.pre_colmap import COLMAPDatabase
@@ -205,18 +208,42 @@ def getcolmapsinglen3d(folder, offset):
205208
destination_file = os.path.join(folder, "sparse", "0", file)
206209
shutil.move(source_file, destination_file)
207210

208-
if __name__ == "__main__":
209-
SCENE = "Bartender"
210-
BASE_DIR = f"/work/Users/lisicheng/Dataset/GSC/{SCENE}"
211+
@dataclass
212+
class ColmapProcessConfig:
213+
"""Configuration for processing frames with COLMAP"""
214+
scene: str
215+
"""Scene name (e.g., Bartender)"""
216+
217+
base_dir: Optional[str] = None
218+
"""Base directory path. If not provided, defaults to examples/data/GSC/{scene}"""
219+
220+
frame_num: int = 65
221+
"""Number of frames to process"""
222+
223+
def main(config: ColmapProcessConfig):
224+
# Process parameters
225+
SCENE = config.scene
226+
BASE_DIR = config.base_dir if config.base_dir else f"examples/data/GSC/{SCENE}"
211227
COLMAP_DIR = BASE_DIR + "/colmap"
212-
FRAME_NUM = 65
228+
FRAME_NUM = config.frame_num
213229
START_FRAME = DATASET_INFOS[SCENE]["start_frame"]
214230

215-
# # make sure every frame share the same camera extrinsic and intrinsic
216-
# for frame in trange(START_FRAME, START_FRAME+FRAME_NUM):
217-
# convertdynerftocolmapdb(Path(COLMAP_DIR), frame, )
231+
print(f"Processing scene {SCENE} with {FRAME_NUM} frames starting from {START_FRAME}")
232+
print(f"Base directory: {BASE_DIR}")
233+
print(f"COLMAP directory: {COLMAP_DIR}")
234+
235+
# Make sure every frame share the same camera extrinsic and intrinsic
236+
print("Converting DyNeRF format to COLMAP database for each frame...")
237+
for frame in trange(START_FRAME, START_FRAME+FRAME_NUM):
238+
convertdynerftocolmapdb(Path(COLMAP_DIR), frame)
239+
240+
# Run COLMAP for each frame to obtain initial point clouds
241+
print("Running COLMAP for each frame to obtain initial point clouds...")
242+
for frame in trange(START_FRAME, START_FRAME+FRAME_NUM):
243+
getcolmapsinglen3d(Path(COLMAP_DIR), frame)
218244

219-
# # run colmap for each frame to obtain initial point clouds
220-
# for frame in range(START_FRAME+1, START_FRAME+FRAME_NUM):
221-
# getcolmapsinglen3d(Path(COLMAP_DIR), frame, )
222-
getcolmapsinglen3d(Path(COLMAP_DIR), 50, )
245+
print("COLMAP processing completed!")
246+
247+
if __name__ == "__main__":
248+
config = tyro.cli(ColmapProcessConfig)
249+
main(config)

mpeg_gsc_utils/multiview_video_preprocess/scene_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
},
1313
"Cinema": {
1414
"start_frame": 235,
15+
"resolution": "1920x1080"
1516
},
1617
}

0 commit comments

Comments
 (0)