From 43955515da1987ad2098619e50d20018b7b909e6 Mon Sep 17 00:00:00 2001 From: Shenhan Qian Date: Tue, 29 Oct 2024 11:19:35 +0100 Subject: [PATCH] Use CUDA instead OpenGL for nvdiffrast by default to simplify installation --- README.md | 12 +++++------- pyproject.toml | 2 +- vhap/config/base.py | 2 +- vhap/export_as_nerf_dataset.py | 2 +- vhap/flame_editor.py | 4 ++-- vhap/flame_viewer.py | 4 ++-- vhap/generate_flame_uvmask.py | 2 +- vhap/util/render_nvdiffrast.py | 2 +- vhap/util/render_uvmap.py | 2 +- 9 files changed, 15 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3379385..2975960 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,11 @@ pip install -e . ``` > [!NOTE] -> - We use an adjusted version of [nvdiffrast](https://github.com/ShenhanQian/nvdiffrast/tree/backface-culling) for backface-culling. To completely remove previous versions and compiled pytorch extensions, you can execute -> -> ```shell -> pip uninstall nvdiffrast -> rm -r ~/.cache/torch_extensions/*/nvdiffrast* -> ``` -> +> - We use an adjusted version of [nvdiffrast](https://github.com/ShenhanQian/nvdiffrast/tree/backface-culling) for backface-culling. If you have other versions installed before, you can reinstall as follows: +> ```shell +> pip install nvdiffrast@git+https://github.com/ShenhanQian/nvdiffrast@backface-culling --force-reinstall +> rm -r ~/.cache/torch_extensions/*/nvdiffrast* +> ``` > - We use [STAR](https://github.com/ShenhanQian/STAR/) for landmark detection by default. Alterntively, [face-alignment](https://github.com/1adrianb/face-alignment) is faster but less accurate. ## Download diff --git a/pyproject.toml b/pyproject.toml index 06f7913..d475911 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ include = ["vhap/**/*.py"] [project] name = "VHAP" -version = "0.0.1" +version = "0.0.2" requires-python = ">=3.9" dependencies = [ "tyro", diff --git a/vhap/config/base.py b/vhap/config/base.py index 2d8d8f3..6c97657 100644 --- a/vhap/config/base.py +++ b/vhap/config/base.py @@ -92,7 +92,7 @@ class ModelConfig(Config): class RenderConfig(Config): backend: Literal['nvdiffrast', 'pytorch3d'] = 'nvdiffrast' """The rendering backend""" - use_opengl: bool = True + use_opengl: bool = False """Use OpenGL for NVDiffRast""" background_train: Literal['white', 'black', 'target'] = 'target' """Background color/image for training""" diff --git a/vhap/export_as_nerf_dataset.py b/vhap/export_as_nerf_dataset.py index ceeacdc..c8f6c4a 100644 --- a/vhap/export_as_nerf_dataset.py +++ b/vhap/export_as_nerf_dataset.py @@ -370,7 +370,7 @@ def __init__(self, cfg_model: ModelConfig, tgt_folder, background_color: str) -> self.flame_model = FlameHead(cfg_model.n_shape, cfg_model.n_expr, add_teeth=True) - self.mesh_renderer = NVDiffRenderer(use_opengl=True) + self.mesh_renderer = NVDiffRenderer(use_opengl=False) @torch.no_grad() def write(self): diff --git a/vhap/flame_editor.py b/vhap/flame_editor.py index 516a32a..5bdf5ec 100644 --- a/vhap/flame_editor.py +++ b/vhap/flame_editor.py @@ -29,7 +29,7 @@ class Config: """default GUI camera fovy""" background_color: tuple[float] = (1., 1., 1.) """default GUI background color""" - use_opengl: bool = True + use_opengl: bool = False """use OpenGL or CUDA rasterizer""" @@ -64,7 +64,7 @@ def __init__(self, cfg: Config): self.drag_button = None # rendering settings - self.mesh_renderer = NVDiffRenderer(use_opengl=False, lighting_space='camera') + self.mesh_renderer = NVDiffRenderer(use_opengl=cfg.use_opengl, lighting_space='camera') self.define_gui() diff --git a/vhap/flame_viewer.py b/vhap/flame_viewer.py index c201d63..b514162 100644 --- a/vhap/flame_viewer.py +++ b/vhap/flame_viewer.py @@ -29,7 +29,7 @@ class Config: """default GUI camera fovy""" background_color: tuple[float] = (1., 1., 1.) """default GUI background color""" - use_opengl: bool = True + use_opengl: bool = False """use OpenGL or CUDA rasterizer""" @@ -56,7 +56,7 @@ def __init__(self, cfg: Config): self.drag_button = None # rendering settings - self.mesh_renderer = NVDiffRenderer(use_opengl=False, lighting_space='camera') + self.mesh_renderer = NVDiffRenderer(use_opengl=cfg.use_opengl, lighting_space='camera') self.num_timesteps = 1 self.timestep = 0 diff --git a/vhap/generate_flame_uvmask.py b/vhap/generate_flame_uvmask.py index 9537048..69d6e7d 100644 --- a/vhap/generate_flame_uvmask.py +++ b/vhap/generate_flame_uvmask.py @@ -23,7 +23,7 @@ def main( - use_opengl: bool = True, + use_opengl: bool = False, device: Literal['cuda', 'cpu'] = 'cuda', ): n_shape = 300 diff --git a/vhap/util/render_nvdiffrast.py b/vhap/util/render_nvdiffrast.py index d65042e..2cb8c12 100644 --- a/vhap/util/render_nvdiffrast.py +++ b/vhap/util/render_nvdiffrast.py @@ -56,7 +56,7 @@ def get_SH_shading(normals, sh_coefficients, sh_const): class NVDiffRenderer(torch.nn.Module): def __init__( self, - use_opengl: bool = True, + use_opengl: bool = False, lighting_type: Literal['constant', 'front', 'front-range', 'SH'] = 'front', lighting_space: Literal['camera', 'world'] = 'world', disturb_rate_fg: Optional[float] = 0.5, diff --git a/vhap/util/render_uvmap.py b/vhap/util/render_uvmap.py index ca2f547..8e7fbbd 100644 --- a/vhap/util/render_uvmap.py +++ b/vhap/util/render_uvmap.py @@ -53,7 +53,7 @@ def render_uvmap_texmap(glctx, pos, pos_idx, verts_uv, faces_uv, tex, resolution def main( use_texmap: bool = False, - use_opengl: bool = True, + use_opengl: bool = False, ): n_shape = 300 n_expr = 100