Code for PhySG: Inverse Rendering with Spherical Gaussians for Physics-based Relighting and Material Editing

Related tags

Deep Learning PhySG
Overview

PhySG: Inverse Rendering with Spherical Gaussians for Physics-based Relighting and Material Editing

Quick start

  • Create conda environment
conda env create -f environment.yml
conda activate PhySG
  • Download example data from google drive.

  • Optimize for geometry and material given a set of posed images and object segmentation masks

cd code
~~python training/exp_runner.py --conf confs_sg/default.conf \
                              --data_split_dir ../example_data/kitty/train \
                              --expname kitty \
                              --nepoch 2000 --max_niter 200001 \
                              --gamma 1.0
  • Render novel views, relighting and mesh extraction, etc.
cd code
# use same lighting as training
python evaluation/eval.py --conf confs_sg/default.conf \
                              --data_split_dir ../example_data/kitty/test \
                              --expname kitty \
                              --gamma 1.0 --resolution 256 --save_exr
# plug in new lighting                              
python evaluation/eval.py --conf confs_sg/default.conf \
                              --data_split_dir ../example_data/kitty/test \
                              --expname kitty \
                              --gamma 1.0 --resolution 256 --save_exr \
                              --light_sg ./envmaps/envmap3_sg_fit/tmp_lgtSGs_100.npy

Tips: for viewing exr images, you can use tev hdr viewer.

Some important pointers

  • code/model/sg_render.py: core of the appearance modelling that evaluates rendering equation using spherical Gaussians.
    • code/model/sg_envmap_convention.png: coordinate system convention for the envmap.
  • code/model/sg_envmap_material.py: optimizable parameters for the material part.
  • code/model/implicit_differentiable_renderer.py: optimizable parameters for the geometry part; it also contains our foward rendering code.
  • code/training/idr_train.py: SGD optimization of unknown geometry and material.
  • code/evaluation/eval.py: novel view rendering, relighting, mesh extraction, etc.
  • code/envmaps/fit_envmap_with_sg.py: represent an envmap with mixture of spherical Gaussians. We provide three envmaps represented by spherical Gaussians optimized via this script in the 'code/envmaps' folder.

Prepare your own data

  • Organize the images and masks in the same way as the provided data.
  • As to camera parameters, we follow the same convention as NeRF++ to use OpenCV conventions.

Acknowledgements: this codebase borrows a lot from the awesome IDR work; we thank the authors for releasing their code.

Comments
  • IDR rendering module

    IDR rendering module

    Hi and congratulations for your interesting work!

    I would like to ask you about the participation of the IDR rendering module in the optimization process. From reading the paper I assumed that material properties (including the diffuse albedo) are estimated by the MaterialEnvmap module you introduce in your paper. However, in your code , you utilize both your module and IDR's rendering module (which both estimate rgb values basically). In addition, color values calculated by both IDR's rendering module and the MaterialEnvmap module participate in the loss calculation.

    Do you train both modules (IDR Rendering and MaterialEnvmap) for a specific reason, or just for comparison?

    PS: In addition, I can't seem to find if EnvmapMaterial module's weights are initialized. Could you help? Thanks for your time.

    opened by ankarako 4
  • Setting SG parameter for NDF

    Setting SG parameter for NDF

    Thanks for the great work and releasing the code!

    A quick question for the renderer: in line 175 of sg_rendering.py, why did you use $\frac{1}{roughness ^4 \cdot \pi}$ instead of 1 as the value of $\mu$? Are you using Blinn-Phong's model for the shape of D?

    opened by HollyDQWang 4
  • The lobe of fs is wr rather than normal?

    The lobe of fs is wr rather than normal?

    Hi Kai, I really appreciate your excellent work! I just have a question about the implementation of sg rendering code: here

    final_lobes, final_lambdas, final_mus = lambda_trick(lgtSGLobes, lgtSGLambdas, lgtSGMus, warpBrdfSGLobes, warpBrdfSGLambdas, warpBrdfSGMus)

    warpBrdfSGLobes here is the reflection direction of views, rather than surface normals. But in the paper, Eq(8) tells that the Gaussian is aligned with surface normal. Is this a little bug or something I misunderstand?

    Screenshot from 2022-10-17 23-43-22

    By the way, I am looking forward to your future works!

    opened by yihua7 2
  • Preparing DTU Dataset

    Preparing DTU Dataset

    Dear authors, I noticed that you did experiments on DTU dataset. But I am wondering how to prepare the proper DTU Dataset to fit the model. Could you please provide the preprocessed scan114 buddha object dataset or provide the script to prepare the DTU dataset. Thx.

    opened by ThreeSRR 1
  • What is the color space?

    What is the color space?

    It seems that the ground truth images saved by plot_to_disk look different from them showed in tev.exe and paper. I find that the images saved by plot_to_disk are not corrected by gamma (gamma = 1) while images in tev.exe and paper are corrected by gamma, which is 2.2. Should I set gamma in args when training? Or ignore it and just do gamma correction when visualization?

    opened by Woolseyyy 1
  • Environment Issue

    Environment Issue

    Appreciate for your great work! I am trying to run the repo on 2080Ti/3090/A30 and meet an error "CUBLAS_STATUS_EXECUTION_FAILED when calling `cublasSgemm...". In case that someone else meet the same problem, here is the record of my solution. According to google, one of the possible solution is to upgrade cuda10 to cuda11. Upgrade the cuda_toolkit in anaconda from 10.2 to 11.* should solve the problem. However, due to the strict version description in .yml a bug of anaconda, the upgrade cannot be conducted automatically by anaconda. Just manually install cuda11, pytorch and other dependence ( install each one when meet "No module named xxx" ...) from scratch.

    opened by Woolseyyy 1
  • gamma settings for png file

    gamma settings for png file

    Hi Kai,

    Thanks for releasing code for this awesome work! We are trying to apply physg to nerf images which are basically png files instead of exr files. I wonder in such a case, how do we set the gamma? Could we simply set it as 2.2 for png/jpg images that are in sRGB space?

    Thank you!

    Best, Wenzheng

    opened by wenzhengchen 1
  • RuntimeError: result type Long can't be cast to the desired output type Bool

    RuntimeError: result type Long can't be cast to the desired output type Bool

    Hello,

    I am trying your example and i have the following error : PhySG-master\code\model\ray_tracing.py", line 265, in rootfind while work_mask.any() & i < self.n_rootfind_steps: RuntimeError: result type Long can't be cast to the desired output type Bool

    Can you help?

    Best regards

    opened by dedelecoder 1
  • Avoid diffuse albedo to be dark

    Avoid diffuse albedo to be dark

    Hi guys! I also meet the problem that diffuse albedo become dark when training with the custom data. Here is my experience about when this could happen:

    1. the rgb image or environment light is not light enough
    2. the initial specular albedo is big

    And here is my way to avoid this situation: initialze specular albedo as a tiny value, for example, 0.1. Hope this can help!

    opened by Woolseyyy 0
  • Gap of PSNR computing between eval.py and the paper

    Gap of PSNR computing between eval.py and the paper

    The rendering results look good but the mean PSNR, which is computed by evaluation/eval.py, is different with the result report in the paper. Specially, I evalled the result of kitty and used same lighting as training. The mean PSNR is about 22 while the PSNR in the paper is 36.45.

    And here is the reason:

    1. eval.py computes PSNR of images in linear space instead of sRGB space, i.e, dose not apply "I_out = I_in ^ (1/2.2)" described in Tab.3. Although Line 204 runs tonemap_img, the gamma is 1.0.
    2. calculate_psnr in eval.py Line 396 only calculates MSE on masked area instead of the whole picture. mse = np.mean((img1 - img2)**2) * (img2.shape[0] * img2.shape[1]) / mask.sum() at Line 400 should be modified as mse = np.mean((img1 - img2)**2)
    opened by Woolseyyy 0
  • Pose estimation is failing

    Pose estimation is failing

    Hi,

    I am trying to use your method on our data, but it looks like the pose estimation module drawn from nerfplusplus's does not seem to retrieve the poses and point-cloud correctly (though point cloud is not relevant to this method). I assume the issue is because the input frames being specular. It makes it hard for COLAMP to estimate the pose.

    How did you circumvent this problem?

    [attaching some frames]

    test_00100 test_00115

    @Kai-46

    opened by dhawal1939 0
  • Incorrect normal and mesh on the back of bear dataset

    Incorrect normal and mesh on the back of bear dataset

    Hi, I was running experiments on the bear dataset, and I realized on the back of the bear there is a large section of incorrectly swelling section of mesh, as well as an overhanding section of volume on top of the bear. I wonder whether this is expect? This is not shown in the supplementary material, is there some additional config that's different from the one that we use for Kitty in order to better train the dataset of bear?

    opened by HollyDQWang 0
  • Synthetic dataset mask, normal and depth

    Synthetic dataset mask, normal and depth

    Hi,

    Would you like to share how you generate mask, normal map and depth map for your synthetic dataset? Just as reference. Did you also used background removal tools? Thanks!

    opened by HollyDQWang 1
  • How to convert these outputs for use in the rendering engine like blender or UE?

    How to convert these outputs for use in the rendering engine like blender or UE?

    Hello zhangkai, thanks for your amazing work!

    Thanks for releasing code for this awesome work so I get the output mesh(.obj/.ply), normal(.png) from one perspective, can you provide some suggestions for convert these files to assets in blender or UE?

    opened by EricStuart 1
  • Not good result on DTU dataset

    Not good result on DTU dataset

    I use you code on DTU dataset, however, the generated meshes are different from ground truth meshes. Would I need to change the default config or change the parameters in training?

    opened by FuchengSu 2
  • why i can't get glossy results when training using blender images?

    why i can't get glossy results when training using blender images?

    hi @Kai-46 , thank you for your excellent job!! However I encountered a problem when trying to training using my images. Acturally, I rendered images using blender renderer, and keep the training set the same format as yours kitty. The training process seems okay except it didn't get glossy results throughout the training process. Do you have any ideas why would this happen? Something like there's difference between mitsuba/blender or rendered-images need post-processing?

    Really hope to get your reply, thx in advance!

    opened by Jemmagu 7
Owner
Kai Zhang
PhD candidate at Cornell.
Kai Zhang
This is code to fit per-pixel environment map with spherical Gaussian lobes, using LBFGS optimization

Spherical Gaussian Optimization This is code to fit per-pixel environment map with spherical Gaussian lobes, using LBFGS optimization. This code has b

null 41 Dec 14, 2022
《Deep Single Portrait Image Relighting》(ICCV 2019)

Ratio Image Based Rendering for Deep Single-Image Portrait Relighting [Project Page] This is part of the Deep Portrait Relighting project. If you find

null 62 Dec 21, 2022
《Towards High Fidelity Face Relighting with Realistic Shadows》(CVPR 2021)

Towards High Fidelity Face-Relighting with Realistic Shadows Andrew Hou, Ze Zhang, Michel Sarkis, Ning Bi, Yiying Tong, Xiaoming Liu. In CVPR, 2021. T

null 114 Dec 10, 2022
This is the implementation of the paper "Self-supervised Outdoor Scene Relighting"

Self-supervised Outdoor Scene Relighting This is the implementation of the paper "Self-supervised Outdoor Scene Relighting". The model is implemented

Ye Yu 24 Dec 17, 2022
A spherical CNN for weather forecasting

DeepSphere-Weather - Deep Learning on the sphere for weather/climate applications. The code in this repository provides a scalable and flexible framew

DeepSphere 47 Dec 25, 2022
Spherical CNNs

Spherical CNNs Equivariant CNNs for the sphere and SO(3) implemented in PyTorch Overview This library contains a PyTorch implementation of the rotatio

Jonas Köhler 893 Dec 28, 2022
Spherical Confidence Learning for Face Recognition, accepted to CVPR2021.

Sphere Confidence Face (SCF) This repository contains the PyTorch implementation of Sphere Confidence Face (SCF) proposed in the CVPR2021 paper: Shen

Maths 70 Dec 9, 2022
Code, Data and Demo for Paper: Controllable Generation from Pre-trained Language Models via Inverse Prompting

InversePrompting Paper: Controllable Generation from Pre-trained Language Models via Inverse Prompting Code: The code is provided in the "chinese_ip"

THUDM 101 Dec 16, 2022
Predicting path with preference based on user demonstration using Maximum Entropy Deep Inverse Reinforcement Learning in a continuous environment

Preference-Planning-Deep-IRL Introduction Check my portfolio post Dependencies Gym stable-baselines3 PyTorch Usage Take Demonstration python3 record.

Tianyu Li 9 Oct 26, 2022
Python inverse kinematics for your robot model based on Pinocchio.

Python inverse kinematics for your robot model based on Pinocchio.

Stéphane Caron 50 Dec 22, 2022
Code for the paper "JANUS: Parallel Tempered Genetic Algorithm Guided by Deep Neural Networks for Inverse Molecular Design"

JANUS: Parallel Tempered Genetic Algorithm Guided by Deep Neural Networks for Inverse Molecular Design This repository contains code for the paper: JA

Aspuru-Guzik group repo 55 Nov 29, 2022
This is the official code release for the paper Shape and Material Capture at Home

This is the official code release for the paper Shape and Material Capture at Home. The code enables you to reconstruct a 3D mesh and Cook-Torrance BRDF from one or more images captured with a flashlight or camera with flash.

null 89 Dec 10, 2022
Original code for "Zero-Shot Domain Adaptation with a Physics Prior"

Zero-Shot Domain Adaptation with a Physics Prior [arXiv] [sup. material] - ICCV 2021 Oral paper, by Attila Lengyel, Sourav Garg, Michael Milford and J

Attila Lengyel 40 Dec 21, 2022
Pytorch implementation of forward and inverse Haar Wavelets 2D

Pytorch implementation of forward and inverse Haar Wavelets 2D

Sergei Belousov 9 Oct 30, 2022
Mitsuba 2: A Retargetable Forward and Inverse Renderer

Mitsuba Renderer 2 Documentation Mitsuba 2 is a research-oriented rendering system written in portable C++17. It consists of a small set of core libra

Mitsuba Physically Based Renderer 2k Jan 7, 2023
An Inverse Kinematics library aiming performance and modularity

IKPy Demo Live demos of what IKPy can do (click on the image below to see the video): Also, a presentation of IKPy: Presentation. Features With IKPy,

Pierre Manceron 481 Jan 2, 2023
The official implementation of the research paper "DAG Amendment for Inverse Control of Parametric Shapes"

DAG Amendment for Inverse Control of Parametric Shapes This repository is the official Blender implementation of the paper "DAG Amendment for Inverse

Elie Michel 157 Dec 26, 2022
SNIPS: Solving Noisy Inverse Problems Stochastically

SNIPS: Solving Noisy Inverse Problems Stochastically This repo contains the official implementation for the paper SNIPS: Solving Noisy Inverse Problem

Bahjat Kawar 35 Nov 9, 2022
Implementation of the GVP-Transformer, which was used in the paper "Learning inverse folding from millions of predicted structures" for de novo protein design alongside Alphafold2

GVP Transformer (wip) Implementation of the GVP-Transformer, which was used in the paper Learning inverse folding from millions of predicted structure

Phil Wang 19 May 6, 2022