Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAD-Gaussians's performance on the nerf 360 dataset. #22

Open
chenkang455 opened this issue Sep 19, 2024 · 2 comments
Open

BAD-Gaussians's performance on the nerf 360 dataset. #22

chenkang455 opened this issue Sep 19, 2024 · 2 comments

Comments

@chenkang455
Copy link

chenkang455 commented Sep 19, 2024

Hi @LingzheZhao , thanks for your great work. While applying the BAD-Gaussian on the 360 scene like lego, I encounter the following problems and I am looking for your help.

My reconstructed scene is severely destroyed shown as below:
image

It seems that rays are blocked by something.

My default input image is shown below:
image

And my modified dataparser code is:

@dataclass
class BlenderDataParserConfig(DataParserConfig):
    """Blender dataset parser config"""

    _target: Type = field(default_factory=lambda: Blender)
    """target class to instantiate"""
    data: Path = Path("nerf_synthetic/lego")
    """Directory specifying location of data."""
    scale_factor: float = 1
    """How much to scale the camera origins by."""
    alpha_color: str = "white"
    """alpha color of background"""


@dataclass
class Blender(DataParser):
    """Blender Dataset
    Some of this code comes from https://github.com/yenchenlin/nerf-pytorch/blob/master/load_blender.py#L37.
    """

    config: BlenderDataParserConfig

    def __init__(self, config: BlenderDataParserConfig):
        super().__init__(config=config)
        self.data: Path = config.data
        self.scale_factor: float = config.scale_factor
        self.alpha_color = config.alpha_color
        if self.alpha_color is not None:
            self.alpha_color_tensor = get_color(self.alpha_color)
        else:
            self.alpha_color_tensor = None

    def _generate_dataparser_outputs(self, split="train"):
        meta = load_from_json(self.data / f"transforms_{split}.json")
        image_filenames = []
        poses = []
        sharp_folder = os.path.join(self.data,split,"blur_data")
        
        for sharp_name in tqdm(sorted(os.listdir(sharp_folder))):
            image_name = sharp_name.split('.')[0] + '.png'
            idx = int(image_name.split('.')[0])
            fname = Path(os.path.join(sharp_folder,image_name))
            image_filenames.append(fname)
            poses.append(np.array(meta['frames'][idx]["transform_matrix"]))
        poses = np.array(poses).astype(np.float32)

        img_0 = imageio.v2.imread(image_filenames[0])
        image_height, image_width = img_0.shape[:2]
        camera_angle_x = float(meta["camera_angle_x"])
        focal_length = 0.5 * image_width / np.tan(0.5 * camera_angle_x)

        cx = image_width / 2.0
        cy = image_height / 2.0
        camera_to_world = torch.from_numpy(poses[:, :3])  # camera to world transform

        # in x,y,z order
        camera_to_world[..., 3] *= self.scale_factor
        scene_box = SceneBox(aabb=torch.tensor([[-1.5, -1.5, -1.5], [1.5, 1.5, 1.5]], dtype=torch.float32))

        cameras = Cameras(
            camera_to_worlds=camera_to_world,
            fx=focal_length,
            fy=focal_length,
            cx=cx,
            cy=cy,
            camera_type=CameraType.PERSPECTIVE,
        )

        dataparser_outputs = DataparserOutputs(
            image_filenames=image_filenames,
            cameras=cameras,
            alpha_color=self.alpha_color_tensor,
            scene_box=scene_box,
            dataparser_scale=self.scale_factor,
        )

        return dataparser_outputs

Can you help me figure it out? Thx a lot. By the way, I encounter similar problems in the BAD-NeRF WU-CVGL/BAD-NeRF#9

@LingzheZhao
Copy link
Member

Hi @chenkang455, thank you very much for your continued interest in our work!

To analyze this issue, I'm curious if you used COLMAP to initialize the camera poses and point cloud with the blurred Lego images? If so, I suggest investigating the error between the estimated pose and the GT pose. Our approach may fail if COLMAP does not give a proper initialization.

Also, if possible, could you share the data so that we can reproduce and analyze this issue?

@chenkang455
Copy link
Author

Hi @chenkang455, thank you very much for your continued interest in our work!

To analyze this issue, I'm curious if you used COLMAP to initialize the camera poses and point cloud with the blurred Lego images? If so, I suggest investigating the error between the estimated pose and the GT pose. Our approach may fail if COLMAP does not give a proper initialization.

Also, if possible, could you share the data so that we can reproduce and analyze this issue?

Hi @LingzheZhao , thanks for your reply! I didn't use the COLMAP to initialize the camera pose. I utilize the trasform.json from the Blender directly like the vanilla nerf.

I have tried applying the ns-process on the sharp image folder to get the camera pose by the COLMAP but it failed owing to some reasons.

My lego dataset can be downloaded from this link: https://pan.baidu.com/s/1U7qUCEzJYRI2sGaJ-jWNhA?pwd=8poe .

And my code modification from the BAD-Gaussain is shown below:


"""Data parser for blender dataset"""
from __future__ import annotations

from dataclasses import dataclass, field
from pathlib import Path
from typing import Type

import imageio
import numpy as np
import torch
import os
from tqdm import tqdm

from nerfstudio.cameras.cameras import Cameras, CameraType
from nerfstudio.data.dataparsers.base_dataparser import DataParser, DataParserConfig, DataparserOutputs
from nerfstudio.data.scene_box import SceneBox
from nerfstudio.utils.colors import get_color
from nerfstudio.utils.io import load_from_json


@dataclass
class BlenderDataParserConfig(DataParserConfig):
    """Blender dataset parser config"""

    _target: Type = field(default_factory=lambda: Blender)
    """target class to instantiate"""
    data: Path = Path("nerf_synthetic/lego")
    """Directory specifying location of data."""
    scale_factor: float = 0.5
    """How much to scale the camera origins by."""
    alpha_color: str = "white"
    """alpha color of background"""


@dataclass
class Blender(DataParser):
    """Blender Dataset
    Some of this code comes from https://github.com/yenchenlin/nerf-pytorch/blob/master/load_blender.py#L37.
    """

    config: BlenderDataParserConfig

    def __init__(self, config: BlenderDataParserConfig):
        super().__init__(config=config)
        self.data: Path = config.data
        self.scale_factor: float = config.scale_factor
        self.alpha_color = config.alpha_color
        if self.alpha_color is not None:
            self.alpha_color_tensor = get_color(self.alpha_color)
        else:
            self.alpha_color_tensor = None

    def _generate_dataparser_outputs(self, split="train"):
        meta = load_from_json(self.data / f"transforms_{split}.json")
        image_filenames = []
        poses = []
        blur_folder = os.path.join(self.data,split,"blur_data")
        
        for blur_name in tqdm(sorted(os.listdir(blur_folder))):
            image_name = blur_name.split('.')[0] + '.png'
            idx = int(image_name.split('.')[0])
            fname = Path(os.path.join(blur_folder,image_name))
            image_filenames.append(fname)
            poses.append(np.array(meta['frames'][idx]["transform_matrix"]))
        poses = np.array(poses).astype(np.float32)

        img_0 = imageio.v2.imread(image_filenames[0])
        image_height, image_width = img_0.shape[:2]
        camera_angle_x = float(meta["camera_angle_x"])
        focal_length = 0.5 * image_width / np.tan(0.5 * camera_angle_x)

        cx = image_width / 2.0
        cy = image_height / 2.0
        camera_to_world = torch.from_numpy(poses[:, :3])  # camera to world transform

        # in x,y,z order
        camera_to_world[..., 3] *= self.scale_factor
        scene_box = SceneBox(aabb=torch.tensor([[-1.5, -1.5, -1.5], [1.5, 1.5, 1.5]], dtype=torch.float32))

        cameras = Cameras(
            camera_to_worlds=camera_to_world,
            fx=focal_length,
            fy=focal_length,
            cx=cx,
            cy=cy,
            camera_type=CameraType.PERSPECTIVE,
        )

        dataparser_outputs = DataparserOutputs(
            image_filenames=image_filenames,
            cameras=cameras,
            alpha_color=self.alpha_color_tensor,
            scene_box=scene_box,
            dataparser_scale=self.scale_factor,
        )

        return dataparser_outputs

It should be noted that the filename in transform.json is wrong. While reading the pose, I utilize the idx to index poses.append(np.array(meta['frames'][idx]["transform_matrix"])).

This dataset reading format has been shown correct on the vanilla nerf/3dgs, so you can believe that this data reading format is correct.

Thanks a lot for your help!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants