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

Implement new renderers and utilitary methods #64

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LeMilenov
Copy link

Implementation of the following renderers

  • Mitsuba 3 another differentiable renderer
  • Vertex based

Mitusba is a well documented ray tracing differentiable renderer that supports :

Vertex based is a deterministic method that gives fast results and can help debug complex architectures

Mitsuba gives up to 5x faster results than Redner and captures more small geometric details.

@LeMilenov LeMilenov marked this pull request as ready for review September 1, 2023 17:36
@skyler14
Copy link

Hey @LeMilenov I was trying out your pull request and noticed it has a hardcoded mesh obj and some other files it asks for in mitsuba_default? What exactly are we supposed to put in that folder and any instructions for preparing that folder?

@LeMilenov
Copy link
Author

@skyler14 For now, Mitsuba 3 uses scenes to render and we needs a mesh and textures to initialize and create an overhead. Those values (mesh data, textures, etc.) are overwritten at runtime. I just kept it hardcoded for now because I haven't had the time to generate those values through code directly.
How it works right now is like this :

  • Mitsuba_default is a folder that contains a mesh.obj file and textures.png files.
  • When creating the scene you just refer to those files.
  • mitsuba will create an overhead based on this scene
  • these values will be overwritten at runtime.
    image
    the mitsuba_default folder can be any folder you want, you just need to point to temporary textures
    Not needing a default mesh and default textures and instead generating a tensor filled with 0 or generating a mesh only at runtime without an initialization is a WIP issue.
    Does this answer your question ?

@skyler14
Copy link

skyler14 commented Sep 16, 2023

Mostly @LeMilenov . Can these just be empty files with the right name or they need to
have some correct dimensions, formatting, sizes, etc. If so can you attach
your hard-coded folder or some other valid example so I can give this code
a spin?

I tried feeding it some dummy obj I had floating around and this was the error I got. Also are there environment/python/cuda version changes to your code given that you set out to make this RTX compatible (which would imply running things in cuda 11):

Traceback (most recent call last):
  File "C:\Users\Skyler\Documents\NextFace-1\optimizer.py", line 612, in <module>
    optimizer.run(inputDir,
  File "C:\Users\Skyler\Documents\NextFace-1\optimizer.py", line 555, in run
    self.runStep2()
  File "C:\Users\Skyler\Documents\NextFace-1\optimizer.py", line 317, in runStep2
    loss.backward()
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\torch\_tensor.py", line 487, in backward
    torch.autograd.backward(
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\torch\autograd\__init__.py", line 200, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\torch\autograd\function.py", line 274, in apply
    return user_fn(self, *args)
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\torch\autograd\function.py", line 522, in wrapper
    outputs = fn(ctx, *args)
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\drjit\router.py", line 5814, in backward
    _dr.traverse(ctx.res_drjit, _dr.ADMode.Backward)
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\drjit\router.py", line 4351, in traverse
    dtype.traverse_(mode, flags)
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\mitsuba\python\util.py", line 404, in backward
    self.integrator.render_backward(self.scene, self.params, self.grad_out(),
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\mitsuba/python\ad\integrators\common.py", line 227, in render_backward
    ray, weight, pos, det = self.sample_rays(scene, sensor,
  File "C:\Users\Skyler\anaconda3\envs\NextFace\lib\site-packages\mitsuba/python\ad\integrators\common.py", line 363, in sample_rays
    raise Exception(
Exception: ADIntegrator detected the potential for image-space motion due to differentiable shape or camera pose parameters. This is, however, incompatible with the box reconstruction filter that is currently used. Please specify a smooth reconstruction filter in your scene description (e.g. 'gaussian', which is actually the default)
drjit-autodiff: variable leak detected (168 variables remain in use)!
 - variable a87 (2 references)
 - variable a101 (4 references)
 - variable a123 (2 references)
 - variable a34 (7 references)
 - variable a44 (4 references)
 - variable a67 (4 references)
 - variable a143 (5 references)
 - variable a109 (3 references)
 - variable a3 (1 references)
 - variable a83 (4 references)
 - (skipping the rest)
drjit-autodiff: edge leak detected (304 edges remain in use)!

@LeMilenov
Copy link
Author

@skyler14 in my testing I have worked with 256x256 images (textures, maps, input image, output image) and 512x512. Usually in the config file there is a maxRes number, modify it to the resolution you want and then feed an input image of this size and textures of that size.
for example, if you want to use an input image of 256x256 just change the maxRes to this number and feed it 256x256 textures. In the mitsuba scene, you can just directly write where those files are but if you want to exactly use the same setup as I did here is my folder :
https://drive.google.com/drive/folders/1BzWe_thaJbSXyuk3ep5Z7IkERmteQWQh?usp=drive_link
For the mesh.obj I used a previous morphable model mesh output so maybe thats why you are receiving this error. Here is the mesh I am using (it is usually overwritten at runtime).

For my setup :
GTX1070
python 3.9.16
cuda 11.8
pytorch 2.0.1
mitsuba 3.3.0
drjit 0.4.2
I have also tried this setup with RTX4070. Try with these files and tell me if you have more issues.

@abecadel
Copy link

abecadel commented Sep 17, 2023

Hi
I'm trying to run it on example files and getting this error:
image

Here's how I'm runing it:
image

@LeMilenov
Copy link
Author

hello @abecadel,
the issue seems to be coming from your mitsuba scene description, could you share it ? Your error message is mentioning to have a gaussian filter it should look like something like this :
image

https://mitsuba.readthedocs.io/en/stable/src/generated/plugins_films.html
But the gaussian filter should already be the default. I would need more information on your scene parameters to help reproduce the error.

@skyler14
Copy link

skyler14 commented Sep 17, 2023 via email

@abecadel
Copy link

abecadel commented Sep 17, 2023

@LeMilenov Mitsuba scene is the same as in mitsuba renderer, I haven't done any changes to it, just using your branch ;)
Also I believe the exceptio is talking about Reconstruction filter and not film filter https://mitsuba.readthedocs.io/en/latest/src/generated/plugins_rfilters.html

@LeMilenov
Copy link
Author

@abecadel I have tried the same code and I have no problems. Can you send me the version of your dependencies ?

@LeMilenov
Copy link
Author

@abecadel @skyler14 here is my setup :
#64 (comment)

Windows 11 Pro
GTX1070 driver 537.13
cuda 11.8.r11.8

Package Version


absl-py 1.4.0
asttokens 2.0.5
attrs 23.1.0
backcall 0.2.0
certifi 2022.12.7
cffi 1.15.1
charset-normalizer 2.1.1
cholespy 0.1.6
click 8.0.4
cloudpickle 2.2.1
colorama 0.4.6
comm 0.1.2
contourpy 1.0.5
cozmo 1.4.10
cozmoclad 3.4.0
cycler 0.11.0
cytoolz 0.12.0
dask 2023.4.1
dataclasses 0.6
debugpy 1.5.1
decorator 5.1.1
distro 1.8.0
drjit 0.4.2
executing 0.8.3
face-alignment 1.2.0
filelock 3.9.0
flatbuffers 23.5.26
fonttools 4.25.0
fsspec 2023.4.0
future 0.18.3
h5py 3.7.0
idna 3.4
imagecodecs 2021.8.26
imageio 2.26.0
importlib-metadata 6.0.0
importlib-resources 5.2.0
ipykernel 6.19.2
ipython 8.12.0
jedi 0.18.1
Jinja2 3.1.2
jupyter_client 8.1.0
jupyter_core 5.3.0
kiwisolver 1.4.4
lazy_loader 0.1
lightning-utilities 0.9.0
locket 1.0.0
MarkupSafe 2.1.2
matplotlib 3.7.1
matplotlib-inline 0.1.6
mediapipe 0.8.3.1
mitsuba 3.3.0
mpmath 1.2.1
munkres 1.1.4
nest-asyncio 1.5.6
networkx 3.0
numpy 1.24.1
opencv-contrib-python 4.8.0.76
opencv-python 4.7.0.72
packaging 23.0
parso 0.8.3
partd 1.2.0
pickleshare 0.7.5
Pillow 9.4.0
pip 23.0.1
platformdirs 2.5.2
ply 3.11
polyscope 1.3.3
prompt-toolkit 3.0.36
protobuf 3.20.3
psutil 5.9.0
pure-eval 0.2.2
pycparser 2.21
Pygments 2.15.1
pyparsing 3.0.9
PyQt5 5.15.7
PyQt5-sip 12.11.0
python-dateutil 2.8.2
PyWavelets 1.4.1
pywin32 305.1
PyYAML 6.0
pyzmq 25.0.2
redner 0.4.28
requests 2.28.1
scikit-image 0.20.0
scipy 1.8.1
setuptools 67.8.0
sip 6.6.2
six 1.16.0
sounddevice 0.4.6
stack-data 0.2.0
sympy 1.11.1
tifffile 2021.7.2
toml 0.10.2
tomli 2.0.1
toolz 0.12.0
torch 2.0.1+cu118
torchaudio 2.0.2+cu118
torchmetrics 1.0.3
torchvision 0.15.2+cu118
tornado 6.2
tqdm 4.65.0
traitlets 5.7.1
trimesh 3.22.5
typing_extensions 4.5.0
urllib3 1.26.13
wcwidth 0.2.5
wheel 0.38.4
zipp 3.11.0

@abecadel
Copy link

abecadel commented Sep 18, 2023

Here's a google colab notebook I'm running it on
NextFace_Mitsuba.zip

@LeMilenov
Copy link
Author

Here's a google colab notebook I'm running it on NextFace_Mitsuba.zip

I see in your debugs that you are using a different version of mediapipe and a different version of mitsuba and of drjit. You also seem to be using python 3.10 and linux.

Can you try with the same versions as I did so that it can help me pinpoint the issue ?
also what graphics card and what does your architecture looks like ?

@skyler14
Copy link

skyler14 commented Sep 18, 2023 via email

@LeMilenov
Copy link
Author

@skyler14 in my testing I have worked with 256x256 images (textures, maps, input image, output image) and 512x512. Usually in the config file there is a maxRes number, modify it to the resolution you want and then feed an input image of this size and textures of that size. for example, if you want to use an input image of 256x256 just change the maxRes to this number and feed it 256x256 textures. In the mitsuba scene, you can just directly write where those files are but if you want to exactly use the same setup as I did here is my folder : https://drive.google.com/drive/folders/1BzWe_thaJbSXyuk3ep5Z7IkERmteQWQh?usp=drive_link For the mesh.obj I used a previous morphable model mesh output so maybe thats why you are receiving this error. Here is the mesh I am using (it is usually overwritten at runtime).

For my setup : GTX1070 python 3.9.16 cuda 11.8 pytorch 2.0.1 mitsuba 3.3.0 drjit 0.4.2 I have also tried this setup with RTX4070. Try with these files and tell me if you have more issues.
@skyler14 I am using python 3.9.16

@skyler14
Copy link

skyler14 commented Sep 18, 2023

Thanks, I remade the environment using your guidance, I'm getting through alot of the process and writing files but still getting those exceptions, have to kill the entire terminal. Before I think redner-gpu doesn't show a valid version when I try to pip install with 3.9 so I used the image here (since were not using redner directly I just did this to make sure it wouldnt throw errors while running mitsuba). BachiLi/redner#169 (comment)

Note: I used the emily example and adjusted things to 256 in the config as you mentioned

Here's the error:

 python optimizer.py --input c:\Users\Skyler\Downloads\emily.png --output c:\Users\Skyler\Videos\training\
loading optim config from:  ./optimConfig.ini
Loading Basel Face Model 2017 from ./baselMorphableModel/morphableModel-2017.pickle...
loading mesh normals...
loading uv parametrization...        
loading landmarks association file...
creating sampler...
C:\Users\Skyler\anaconda3\envs\faceNext\lib\site-packages\scipy\__init__.py:155: UserWarning: A NumPy version >=1.18.5 and <1.25.0 is required for this version of SciPy (detected version 1.26.0
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
C:\Users\Skyler\anaconda3\envs\faceNext\lib\site-packages\torch\functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:3484.)    
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
loading image from path: c:\Users\Skyler\Downloads\emily.png
detecting landmarks using: fan
C:\Users\Skyler\Documents\NF\landmarksfan.py:35: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at C:\cb\pytorch_1000000000000\work\torch\csrc\utils\tensor_new.cpp:248.)
  return torch.tensor(landmarks, device = self.device)
init camera pose...
running with mitsuba
1/3 => Optimizing head pose and expressions using landmarks...
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████| 2000/2000 [00:13<00:00, 143.06it/s]
2/3 => Optimizing shape, statistical albedos, expression, head pose and scene light...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 401/401 [00:51<00:00,  7.82it/s]
3/3 => finetuning albedos, shape, expression, head pose and scene light...
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 101/101 [00:13<00:00,  7.46it/s]
took 1.33 minutes to optimize
saving to: ' c:\Users\Skyler\Videos\training\/emily.png/ '. hold on... 
c:\Users\Skyler\Videos\training\/emily.png///envMap_0.png = torch.Size([64, 64, 3])1
c:\Users\Skyler\Videos\training\/emily.png//diffuse_0.png = torch.Size([512, 512, 4])1
c:\Users\Skyler\Videos\training\/emily.png//specular_0.png = torch.Size([512, 512, 4])1
c:\Users\Skyler\Videos\training\/emily.png//roughness_0.png = torch.Size([512, 512, 4])1
c:\Users\Skyler\Videos\training\/emily.png//illumination_0.png = torch.Size([512, 512, 4])1
c:\Users\Skyler\Videos\training\/emily.png//finalReconstruction_0.png = torch.Size([512, 512, 4])1
c:\Users\Skyler\Videos\training\/emily.png///overlay_0.png = torch.Size([512, 512, 3])1
c:\Users\Skyler\Videos\training\/emily.png///render_0.png = torch.Size([512, 3584, 4])1
c:\Users\Skyler\Videos\training\/emily.png//diffuseMap_0.png = torch.Size([512, 512, 3])1
c:\Users\Skyler\Videos\training\/emily.png//specularMap_0.png = torch.Size([512, 512, 3])1
c:\Users\Skyler\Videos\training\/emily.png//roughnessMap_0.png = torch.Size([512, 512, 3])1
drjit-autodiff: variable leak detected (9 variables remain in use)!
 - variable a1528310 (1 references)
 - variable a1528304 (1 references)
 - variable a1528312 (1 references)
 - variable a1528303 (1 references)
 - variable a1528307 (1 references)
 - variable a1528309 (1 references)
 - variable a1528308 (1 references)
 - variable a1528311 (1 references)
 - variable a1528305 (1 references)
drjit-autodiff: edge leak detected (6 edges remain in use)!

Here's my installation (Win 10, 3090):

conda create -y --name faceNext python=3.9.16
conda activate faceNext
conda install -y pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
pip install 'c:\Users\Skyler\Downloads\cuda redner-0.4.28-cp39-cp39-win_amd64\redner-0.4.28-cp39-cp39-win_amd64.whl'
pip install opencv-python==4.7.0.72
conda install -y -c 1adrianb face_alignment=1.2.0
conda install -y -c anaconda h5py
pip install mediapipe
pip install mitsuba==3.3.0 drjit==0.4.2

@beltegeuse
Copy link

Leaking in Mitsuba 3 is quite common. This particular error is when Python finishes; it needs to destroy the different allocated objects. The objects are destroyed in an undefined order, which makes it difficult to manage smart pointers (internally used in DrJit implementation). More information: mitsuba-renderer/drjit#87

However, the log that you posted shows that you successfully optimized the shape.

@skyler14
Copy link

Leaking in Mitsuba 3 is quite common. This particular error is when Python finishes; it needs to destroy the different allocated objects. The objects are destroyed in an undefined order, which makes it difficult to manage smart pointers (internally used in DrJit implementation). More information: mitsuba-renderer/drjit#87

However, the log that you posted shows that you successfully optimized the shape.

so is there a particular module(s) that would be easy enough to manually del to make sure this error doesn't pop up. I wanted to run this script many times on a batch of stuff and the process failing to close and holding memory is PITA.

@beltegeuse
Copy link

It will not fill up your memory. All the allocated objects are deleted after your script finishes. It is just the order of the delete operations that trigger this "error". Please look at my previous attached issue to learn more.

@skyler14
Copy link

It will not fill up your memory. All the allocated objects are deleted after your script finishes. It is just the order of the delete operations that trigger this "error". Please look at my previous attached issue to learn more.

A bigger issue is the program never closes. That terminal session just hangs after the exception, its a bit hard to tell if any allocation remains, and the program freezes on that exception message so I literally have to kill the terminal session and start a new one again.

@skyler14
Copy link

skyler14 commented Sep 21, 2023

@LeMilenov when running in mediapipe mode I noticed this error, not sure if your render code doesnt account for when mediapipe does detecting I think some coordinate systems are normalized [0,1]

3/3 => finetuning albedos, shape, expression, head pose and scene light...
#...
# it was ok before this at like 70% 85%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎                                        | 86/101 [00:11<00:02,  7.45it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 86%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████                                      
| 87/101 [00:11<00:01,  7.47it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 87%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋                                   
| 88/101 [00:11<00:01,  7.52it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 88%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍                                
| 89/101 [00:11<00:01,  7.45it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 89%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏                             
| 90/101 [00:12<00:01,  7.30it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 90%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊                           
| 91/101 [00:12<00:01,  7.22it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 91%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌                        
| 92/101 [00:12<00:01,  6.81it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 95%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍             
| 96/101 [00:12<00:00,  7.59it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 96%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏          
| 97/101 [00:13<00:00,  7.63it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 98%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌     
| 99/101 [00:13<00:00,  7.34it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 99%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎  
| 100/101 [00:13<00:00,  7.38it/s]2023-09-20 23:14:34 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
| 101/101 [00:14<00:00,  7.19it/s]
took 2.07 minutes to optimize

@LeMilenov
Copy link
Author

LeMilenov commented Sep 21, 2023

@LeMilenov when running in mediapipe mode I noticed this error, not sure if your render code doesnt account for when mediapipe does detecting I think some coordinate systems are normalized [0,1]

3/3 => finetuning albedos, shape, expression, head pose and scene light...
#...
# it was ok before this at like 70% 85%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎                                        | 86/101 [00:11<00:02,  7.45it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 86%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████                                      
| 87/101 [00:11<00:01,  7.47it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 87%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋                                   
| 88/101 [00:11<00:01,  7.52it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 88%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍                                
| 89/101 [00:11<00:01,  7.45it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 89%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏                             
| 90/101 [00:12<00:01,  7.30it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 90%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▊                           
| 91/101 [00:12<00:01,  7.22it/s]2023-09-20 23:14:32 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 91%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌                        
| 92/101 [00:12<00:01,  6.81it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 95%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍             
| 96/101 [00:12<00:00,  7.59it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 96%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏          
| 97/101 [00:13<00:00,  7.63it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 98%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌     
| 99/101 [00:13<00:00,  7.34it/s]2023-09-20 23:14:33 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
 99%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎  
| 100/101 [00:13<00:00,  7.38it/s]2023-09-20 23:14:34 WARN  main  [BitmapTexture] BitmapTexture: texture named "" contains pixels that exceed the [0, 1] range!
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
| 101/101 [00:14<00:00,  7.19it/s]
took 2.07 minutes to optimize

I did not have this issue when I tested mediapipe on the latest version but, I did have this issue in the past. This issue is pretty straightforward, the texture is exceeding the range. There should be a clamp between 0,1 before rendering. Its just a warning it happens sometimes on specific use cases where the optimisation converges towards extreme colors.

@skyler14
Copy link

Got it @LeMilenov ,
Few questions given how in depth your understanding of this code is:

When you start rendering is it relying the contents of the the _map images to perform its projection onto the face or just the coefficient terms, when you load the output pickles it seems to preserve all of these so I assume they all are used to generate the final rendered face inverse. I am going to test out some mesh refinements.

>>> s=loadDictionaryFromPickle(r"c:\Users\Skyler\Videos\training\xnviewmp_uW4vEiJh4w.png\checkpoints\stage3_output.pickle") 
>>> {k:np.shape(v) for (k,v) in s.items()} 
{'vShapeCoeff': (1, 199), 'vAlbedoCoeff': (1, 145), 'vExpCoeff': (1, 100), 'vRotation': (1, 3), 'vTranslation': (1, 3), 'vFocals': (1,), 'vShCoeffs': (1, 81, 3), 'screenWidth': (), 'screenHeight': (), 'sharedIdentity': (), 'vEnhancedDiffuse': (1, 512, 512, 3), 'vEnhancedSpecular': (1, 512, 512, 3), 'vEnhancedRoughness': (1, 512, 512, 1)}

I'm curious if you could explain a bit more about which of these

Relating to the exception I mentioned:
I still have the problem where the script throws the exception and doesnt close/hangs up terminal.

Looking at the local variables right before ending execution below. Any ideas which objects have the drjit related modules I should see about manually deleting to maybe prevent this error

locals().keys()
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', '__file__', '__cached__', 'Image', 'ImageFolder', 'overlayImage', 'saveImage', 'GaussianSmoothing', 'smoothImage', 'estimateCameraPosition', 'TextureLoss', 'Pipeline', 'Config', 'np', 'torch', 'cv2', 'os', 'saveObj', 'saveLandmarksVerticesProjections', 'mkdir_p', 'loadDictionaryFromPickle', 'writeDictionaryToPickle', 'debugRender', 'debugIteration', 'debugTensor', 'screenshotMesh', 'argparse', 'pickle', 'tqdm', 'sys', 'code', 'Optimizer', 'tempfile', 'parser', 'params', 'inputDir', 'sharedIdentity', 'outputDir', 'configFile', 'checkpoint', 'doStep1', 'doStep2', 'doStep3', 'config', 'LandmarksDetectorMediapipe', 'optimizer'])

@LeMilenov
Copy link
Author

Got it @LeMilenov , Few questions given how in depth your understanding of this code is:

When you start rendering is it relying the contents of the the _map images to perform its projection onto the face or just the coefficient terms, when you load the output pickles it seems to preserve all of these so I assume they all are used to generate the final rendered face inverse. I am going to test out some mesh refinements.

>>> s=loadDictionaryFromPickle(r"c:\Users\Skyler\Videos\training\xnviewmp_uW4vEiJh4w.png\checkpoints\stage3_output.pickle") 
>>> {k:np.shape(v) for (k,v) in s.items()} 
{'vShapeCoeff': (1, 199), 'vAlbedoCoeff': (1, 145), 'vExpCoeff': (1, 100), 'vRotation': (1, 3), 'vTranslation': (1, 3), 'vFocals': (1,), 'vShCoeffs': (1, 81, 3), 'screenWidth': (), 'screenHeight': (), 'sharedIdentity': (), 'vEnhancedDiffuse': (1, 512, 512, 3), 'vEnhancedSpecular': (1, 512, 512, 3), 'vEnhancedRoughness': (1, 512, 512, 1)}

I'm curious if you could explain a bit more about which of these

Relating to the exception I mentioned: I still have the problem where the script throws the exception and doesnt close/hangs up terminal.

Looking at the local variables right before ending execution below. Any ideas which objects have the drjit related modules I should see about manually deleting to maybe prevent this error

locals().keys()
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', '__file__', '__cached__', 'Image', 'ImageFolder', 'overlayImage', 'saveImage', 'GaussianSmoothing', 'smoothImage', 'estimateCameraPosition', 'TextureLoss', 'Pipeline', 'Config', 'np', 'torch', 'cv2', 'os', 'saveObj', 'saveLandmarksVerticesProjections', 'mkdir_p', 'loadDictionaryFromPickle', 'writeDictionaryToPickle', 'debugRender', 'debugIteration', 'debugTensor', 'screenshotMesh', 'argparse', 'pickle', 'tqdm', 'sys', 'code', 'Optimizer', 'tempfile', 'parser', 'params', 'inputDir', 'sharedIdentity', 'outputDir', 'configFile', 'checkpoint', 'doStep1', 'doStep2', 'doStep3', 'config', 'LandmarksDetectorMediapipe', 'optimizer'])

@skyler14 here is how it works :
When you start the app, we take the inputs (textures) and convert them to tensors. We generate default coefficients tensors. As the optimisation continues, we optimise these coefficients and use them to render our images and to help us do a loss and compute a gradient.
To render, we take the coefficients -> convert them to albedos -> convert them to textures or envMaps for redner and mitsuba (for vertex based we do not do this step).
When the optimisation is done, we convert the coefficients to textures and save them in our _map textures for reference purposes.
We give textures to mitsuba to help it create the needed overhead for our optimisation process.
Recap : We only use the coefficients and the _map textures are an output of those coefficients at the end of the optimisation process. if you want more information look at the step1 step2 step3 methods in optimizer to see how it works, the code isnt that long :)

@skyler14
Copy link

skyler14 commented Sep 22, 2023

We give textures to mitsuba to help it create the needed overhead for our optimisation process.

We only use the coefficients and the _map textures are an output of those coefficients

So since mitsuba/redner use the finalized textures instead of the coefficients directly if we perform any further stages of improvement on the texture then we can improve our final render correct? But we can't perform a processing stage on the intermediate textures each iteration since that's just an output (and isn't directly fed back in/used to calculate loss). But post-processing is on the table if I understand correctly.

And another small question:
is illumination relative to the face or a base coordinate system, I was thinking about trying to fit to a video just by adjusting the translation/rotation to make it quick, but was wondering if the lighting conditions (if I'm aiming to just be approximate and environment conditions are static) can not be updated with good results?

@LeMilenov
Copy link
Author

We give textures to mitsuba to help it create the needed overhead for our optimisation process.

We only use the coefficients and the _map textures are an output of those coefficients

So since mitsuba/redner use the finalized textures instead of the coefficients directly if we perform any further stages of improvement on the texture then we can improve our final render correct? But we can't perform a processing stage on the intermediate textures each iteration since that's just an output (and isn't directly fed back in/used to calculate loss). But post-processing is on the table if I understand correctly.

And another small question: is illumination relative to the face or a base coordinate system, I was thinking about trying to fit to a video just by adjusting the translation/rotation to make it quick, but was wondering if the lighting conditions (if I'm aiming to just be approximate and environment conditions are static) can not be updated with good results?

@skyler14 we use spherical harmonics coefficients for the illumination. and yes since the textures are an output you can do post -processing or since the repos is open-source you can do your own post-processing and just re-use the textures inside the implementation.

@skyler14
Copy link

skyler14 commented Oct 5, 2023

We give textures to mitsuba to help it create the needed overhead for our optimisation process.

We only use the coefficients and the _map textures are an output of those coefficients

So since mitsuba/redner use the finalized textures instead of the coefficients directly if we perform any further stages of improvement on the texture then we can improve our final render correct? But we can't perform a processing stage on the intermediate textures each iteration since that's just an output (and isn't directly fed back in/used to calculate loss). But post-processing is on the table if I understand correctly.
And another small question: is illumination relative to the face or a base coordinate system, I was thinking about trying to fit to a video just by adjusting the translation/rotation to make it quick, but was wondering if the lighting conditions (if I'm aiming to just be approximate and environment conditions are static) can not be updated with good results?

@skyler14 we use spherical harmonics coefficients for the illumination. and yes since the textures are an output you can do post -processing or since the repos is open-source you can do your own post-processing and just re-use the textures inside the implementation.

great, if I do upsample the final texture what changes need to be made to the vertexes to support the upsampling? (or is the texture atlas placed onto the vertexes by relative location so you just need to preserve the aspect ratio)

@Loammm
Copy link

Loammm commented Dec 7, 2023

@LeMilenov
Hello, I tried running your branch and I am facing an attribute error:

AttributeError: jit_init_thread_state(): the CUDA backend hasn't been initialized. Make sure to call jit_init(JitBackend::CUDA) to properly initialize this backend.

My package list:

Package Version


absl-py 1.4.0
asttokens 2.4.1
attrs 23.1.0
backcall 0.2.0
certifi 2022.12.7
cffi 1.15.1
charset-normalizer 2.1.1
cholespy 0.1.6
click 8.0.4
cloudpickle 2.2.1
cmake 3.25.0
colorama 0.4.6
comm 0.1.2
contourpy 1.0.5
cozmo 1.4.10
cozmoclad 3.4.0
cycler 0.11.0
cytoolz 0.12.0
dask 2023.4.1
dataclasses 0.6
debugpy 1.5.1
decorator 5.1.1
distro 1.8.0
drjit 0.4.2
exceptiongroup 1.2.0
executing 2.0.1
face-alignment 1.2.0
filelock 3.9.0
flatbuffers 23.5.26
fonttools 4.25.0
fsspec 2023.4.0
future 0.18.3
h5py 3.7.0
idna 3.4
imagecodecs 2021.8.26
imageio 2.26.0
importlib-metadata 6.0.0
importlib-resources 5.2.0
ipykernel 6.19.2
ipython 8.12.0
jedi 0.18.1
Jinja2 3.1.2
jupyter_client 8.1.0
jupyter_core 5.3.0
kiwisolver 1.4.4
lazy_loader 0.1
lightning-utilities 0.9.0
lit 15.0.7
locket 1.0.0
MarkupSafe 2.1.2
matplotlib 3.7.1
matplotlib-inline 0.1.6
mediapipe 0.8.6.2
mitsuba 3.3.0
mpmath 1.2.1
munkres 1.1.4
nest-asyncio 1.5.6
networkx 3.0
numpy 1.24.1
opencv-contrib-python 4.8.0.76
opencv-python 4.7.0.72
packaging 23.0
parso 0.8.3
partd 1.2.0
pexpect 4.9.0
pickleshare 0.7.5
Pillow 9.4.0
pip 23.0.1
platformdirs 2.5.2
ply 3.11
polyscope 1.3.3
prompt-toolkit 3.0.36
protobuf 3.20.3
psutil 5.9.0
ptyprocess 0.7.0
pure-eval 0.2.2
pycparser 2.21
Pygments 2.15.1
pyparsing 3.0.9
PyQt5 5.15.7
PyQt5-Qt5 5.15.2
PyQt5-sip 12.11.0
python-dateutil 2.8.2
PyWavelets 1.4.1
PyYAML 6.0
pyzmq 25.0.2
redner 0.4.28
requests 2.28.1
scikit-image 0.20.0
scipy 1.8.1
setuptools 67.8.0
sip 6.6.2
six 1.16.0
sounddevice 0.4.6
stack-data 0.2.0
sympy 1.11.1
tifffile 2021.7.2
toml 0.10.2
toolz 0.12.0
torch 2.0.1+cu118
torchaudio 2.0.2+cu118
torchmetrics 1.0.3
torchvision 0.15.2+cu118
tornado 6.2
tqdm 4.65.0
traitlets 5.7.1
trimesh 3.22.5
triton 2.0.0
typing_extensions 4.5.0
urllib3 1.26.13
wcwidth 0.2.5
wheel 0.38.4
zipp 3.11.0

Any help would be appreciated please =)

@LeMilenov
Copy link
Author

@Loammm what have you tried running ? what action were you trying to do ? I am asking because usually in the python files or jupyter notebooks, we initialise Cuda and other things.

@skyler14
Copy link

skyler14 commented Dec 9, 2023

Two questions:

If I want to align the face with another image of the same face what should I be doing. Iirc the version using the other renderer sort of supported this out the gate by allowing you to train with multiple pictures at once. What's missing here in order to either reintroduce that feature or at least allow us to do then fit the single image geometry back onto another picture of the same person?

And second, the reconstructed face on an image (vs when we load up the .obj file in an application it) looks so much better and the obj looks horrible. What exactly is going to to make that image reconstruction look so much better, is that the mitsuba render a point cloud or something similar?

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

Successfully merging this pull request may close these issues.

5 participants