mitsuba-renderer / mitsuba2

Mitsuba 2: A Retargetable Forward and Inverse Renderer
Other
2.05k stars 267 forks source link

[🐛 bug report] - Does not catch variant changes from modules #380

Open ignamoro opened 3 years ago

ignamoro commented 3 years ago

[🐛 bug report]

Description

Hi everyone, I'm trying to change the variant from main (notebook jupyter), using mitsuba from other module, but I don't know how to specify a certain variant when importing it, so I try to use the method setVariant( 'variant' ) for this propose. the problem is that when I try to change it, it shows that it is using this new variable (through getVariant()), but then it is not used, and uses the module's default

System configuration

For bug report, please enter information regarding your system configuration<- [remove this]

Steps to reproduce

  1. Create a module in python, where import mitsuba with a variant (e.g. gpu*)
  2. From notebook jupyter change to a new variant using a module method (e.g. spectral*)
  3. Make a function of this variant (e.g render)

imagen

Speierers commented 3 years ago

Hi @naachoo0 ,

I am not sure to fully understand your problem here. Are you trying to switch between variants in your jupyter notebook using mitsuba.set_variant(...)? This should be possible, it is used quite a few times in the test suite.

Maybe you could share a little more of your code so I could take a look and see what's going on?

ignamoro commented 3 years ago

The problem is that switch between variants from a custom module (where is mitsuba declared and used) is giving me problems, throwing mistakes.

For example, I have the following code, stored in [User]/miniconda3/Lib/customLibrary/mitsuba.py: imagen

When I use from jupyter notebook the method _setVariant('[newvariant]') and then use getVariant(), this returns the variant that was inserted with setVariant, fine!. But the problem is that when I Try use like that new variant (e.g. rendering the scene like a scalar* variant using the code of the document), I get the error that I show in the previos post (cuda_var_register(): attempted to create a variable with size zero!).

Looks like internally, the switch was not made it and mitsuba is in the gpu* variable still.

Speierers commented 3 years ago

Could it be that some variables where created (e.g. scene, Float, ...) when the gpu variant was switched ON, and later on you are trying to use those same GPU variables with the scalar variant ON?

For instance, you will need to reload the scene after switching variant.

ignamoro commented 3 years ago

I don't think so, because the variants are switched at the beginning of the code. I attached my code used in jupyter (I've turned .py for better code understanding)

My jupyter notebook Code

imagen

Output

My default variant is 'gpu_autodiff_rgb'

Set variant to 'scalar_spectral'

Now I should be using the 'scalar_spectral' variant

Reading the ('x', 'y', 'z') of element 'vertex' from file 'C:/Users/nacho/miniconda3/Lib/tfg/examples/cloudpoints/bunny.ply' Using 'scalar_spectral' variant

2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\path.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\perspective.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\hdrfilm.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\gaussian.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\multijitter.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\directional.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\uniform.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\sphere.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\diffuse.dll" .. 2021-02-04 11:58:12 INFO main [PluginManager] Loading plugin "plugins\srgb.dll" .. 2021-02-04 11:58:12 INFO main [Scene] Building scene in OptiX .. 2021-02-04 11:58:12 INFO main [SamplingIntegrator] Start rendering...


RuntimeError Traceback (most recent call last)

in 1 if __name__ == "__main__": ----> 2 main() in main() 16 tcm.renderGPUmode(scene) 17 else: ---> 18 tcm.render(scene,extension='png') ~\miniconda3\lib\tfg\core\helper.py in wrap(*args, **kwargs) 7 def wrap(*args, **kwargs): 8 time1 = time.time() ----> 9 ret = f(*args, **kwargs) 10 time2 = time.time() 11 print('{:s} function took {:.16f} ms'.format(f.__name__, (time2-time1)*1000.0)) ~\miniconda3\lib\tfg\core\mitsuba.py in render(dictScene, **kwargs) 27 28 sensor = scene.sensors()[options['sensor']] ---> 29 scene.integrator().render(scene,sensor) 30 31 film = sensor.film() RuntimeError: cuda_var_register(): attempted to create a variable of size zero!
Speierers commented 3 years ago

And I suppose this doesn't happen if you do not set the scalar_spectral variant at the beginning? Why do you even need to do this in the first place?

ignamoro commented 3 years ago

Because I've thought about having mitsuba in a module to organize the code. The problem is when i have to specify which variant use from jupyter. Can you in python import a module by passing argument?