Rotate transformation doesn't get parsed by `load_mitsuba()`
abhinavvs opened this issue · 17 comments
I see that the rotate
transformation present in Mitsuba doesn't get parsed automatically by the load_mitsuba()
function. Is it possible to add this functionality?
Thanks!
Added in 0.4.17. I didn't test it at all so let me know if it doesn't work. As usual contributions are welcome.
Crap I didn't actually commit. One moment.
I am getting an error when I use the load_mitsuba
function. Is the commit done? The pip installation still fetches only 0.4.17. Maybe that's the issue?
As usual, it would be helpful if you can share the error message.
Sorry about that. Here is the error message:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-3-2a213e4e55a7> in <module>
18 print('begin scene construction')
19
---> 20 scene = pyredner.load_mitsuba('hallway_redner/hallway_redner.xml')
21 # scene.shapes[0] = rotate(scene.shapes[0], torch.tensor([0.0, 0.0, 180.0], device = pyredner.get_device()) )
22
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in load_mitsuba(filename, device)
461 cwd = os.getcwd()
462 os.chdir(os.path.dirname(filename))
--> 463 ret = parse_scene(root, device)
464 os.chdir(cwd)
465 return ret
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_scene(node, device)
413 shape_group_dict[child.attrib['id']] = parse_shape(child_s, material_dict, None)[0]
414 elif child.tag == 'shape':
--> 415 shape, light = parse_shape(child, material_dict, len(shapes), shape_group_dict if child.attrib['type'] == 'instance' else None)
416 shapes.append(shape)
417 if light is not None:
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_shape(node, material_dict, shape_id, device, shape_group_dict)
235 if node.attrib['type'] == 'obj':
236 # Load in CPU for rebuild_topology
--> 237 _, mesh_list, _ = pyredner.load_obj(filename, obj_group = False, device = torch.device('cpu'))
238 vertices = mesh_list[0][1].vertices
239 indices = mesh_list[0][1].indices
~/anaconda3/lib/python3.7/site-packages/pyredner/load_obj.py in load_obj(filename, obj_group, flip_tex_coords, use_common_indices, return_objects, device)
186 diffuse_reflectance = pyredner.imread(m.map_Kd)
187 if pyredner.get_use_gpu():
--> 188 diffuse_reflectance = diffuse_reflectance.cuda(device = device)
189 if m.map_Ks is None:
190 specular_reflectance = torch.tensor(m.Ks,
RuntimeError: Invalid device, must be cuda device
The previous error got fixed, but now I am getting a different error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-2a213e4e55a7> in <module>
18 print('begin scene construction')
19
---> 20 scene = pyredner.load_mitsuba('hallway_redner/hallway_redner.xml')
21 # scene.shapes[0] = rotate(scene.shapes[0], torch.tensor([0.0, 0.0, 180.0], device = pyredner.get_device()) )
22
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in load_mitsuba(filename, device)
485 cwd = os.getcwd()
486 os.chdir(os.path.dirname(filename))
--> 487 ret = parse_scene(root, device)
488 os.chdir(cwd)
489 return ret
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_scene(node, device)
437 shape_group_dict[child.attrib['id']] = parse_shape(child_s, material_dict, None)[0]
438 elif child.tag == 'shape':
--> 439 shape, light = parse_shape(child, material_dict, len(shapes), shape_group_dict if child.attrib['type'] == 'instance' else None)
440 shapes.append(shape)
441 if light is not None:
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_shape(node, material_dict, shape_id, device, shape_group_dict)
240 filename = child.attrib['value']
241 elif child.attrib['name'] == 'toWorld':
--> 242 to_world = parse_transform(child)
243 elif child.attrib['name'] == 'shapeIndex':
244 serialized_shape_id = int(child.attrib['value'])
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_transform(node)
38 y = child.attrib['y'] if 'y' in child.attrib else 0.0
39 z = child.attrib['z'] if 'z' in child.attrib else 0.0
---> 40 angle = transform.radians(child.attrib['angle'])
41 axis = np.array([x, y, z])
42 axis = axis / np.norm(axis)
~/anaconda3/lib/python3.7/site-packages/pyredner/transform.py in radians(deg)
4
5 def radians(deg):
----> 6 return (math.pi / 180.0) * deg
7
8 def normalize(v):
TypeError: can't multiply sequence by non-int of type 'float'
I can see that the latest version is 0.4.20 on the Github page, but pip is still fetching me only 0.4.18.
Be patient. Release a version usually take 30 minutes to 1 hour.
Hi @BachiLi - I am still unable to get version 0.4.20. Pip is still fetching only 0.4.18
Should be there now.
Thanks, I was able to get 0.4.20, but got this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-2a213e4e55a7> in <module>
18 print('begin scene construction')
19
---> 20 scene = pyredner.load_mitsuba('hallway_redner/hallway_redner.xml')
21 # scene.shapes[0] = rotate(scene.shapes[0], torch.tensor([0.0, 0.0, 180.0], device = pyredner.get_device()) )
22
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in load_mitsuba(filename, device)
485 cwd = os.getcwd()
486 os.chdir(os.path.dirname(filename))
--> 487 ret = parse_scene(root, device)
488 os.chdir(cwd)
489 return ret
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_scene(node, device)
437 shape_group_dict[child.attrib['id']] = parse_shape(child_s, material_dict, None)[0]
438 elif child.tag == 'shape':
--> 439 shape, light = parse_shape(child, material_dict, len(shapes), shape_group_dict if child.attrib['type'] == 'instance' else None)
440 shapes.append(shape)
441 if light is not None:
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_shape(node, material_dict, shape_id, device, shape_group_dict)
240 filename = child.attrib['value']
241 elif child.attrib['name'] == 'toWorld':
--> 242 to_world = parse_transform(child)
243 elif child.attrib['name'] == 'shapeIndex':
244 serialized_shape_id = int(child.attrib['value'])
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_transform(node)
40 angle = transform.radians(float(child.attrib['angle']))
41 axis = np.array([x, y, z])
---> 42 axis = axis / np.norm(axis)
43 cos_theta = cos(angle)
44 sin_theta = sin(angle)
~/anaconda3/lib/python3.7/site-packages/numpy/__init__.py in __getattr__(attr)
218 else:
219 raise AttributeError("module {!r} has no attribute "
--> 220 "{!r}".format(__name__, attr))
221
222 def __dir__():
AttributeError: module 'numpy' has no attribute 'norm'
I think np.norm()
should be replaced by np.linalg.norm()
.
Fixed in 0.4.21. As you can see fixing this yourself and send a PR is probably more efficient than I doing it ; )
Thanks a lot for working on adding this functionality. Unfortunately, there are still some minor bugs in the code:
~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py in parse_transform(node)
41 axis = np.array([x, y, z])
42 axis = axis / np.linalg.norm(axis)
---> 43 cos_theta = cos(angle)
44 sin_theta = sin(angle)
45 mat = torch.zeros(4, 4)
NameError: name 'cos' is not defined
I am open to trying to fix as much of this myself as possible and then send a PR.
Just a quick clarification of how I should do it - I installed redner
using pip. How should I make changes?
Should I directly edit the ~/anaconda3/lib/python3.7/site-packages/pyredner/load_mitsuba.py
or clone the git folder, make changes there and run python setup.py install
to see if the changes are installed correctly? Which method is easier for doing the PR?
Once again, thanks a lot for helping me out with this! I really appreciate this.
Hi @BachiLi - 0.4.22 still hasn't come on pip, but I checked the source code and it is almost correct...you just need to add import math
to pyredner/load_mitsuba.py
:-D
I did that on my local copy and everything works well after that edit..!
I figured it would be easy to tell you that here instead of doing a PR (after bugging you to teach me how to do a PR). Sorry for all the trouble, and thanks a lot for patiently working with me on adding this functionality! :-)
The shapes that are parsed are now getting stored as torch tensors on the cpu (even if there is gpu device is available). Any chance this is a quick fix?
Should be fixed in 0.4.24.
Thanks a lot! Everything works fine now!! :)