daniilidis-group / neural_renderer

A PyTorch port of the Neural 3D Mesh Renderer
Other
1.12k stars 248 forks source link

How to save as .obj ? #49

Closed jay-thakur closed 5 years ago

jay-thakur commented 5 years ago

Hi,

I used this code to save as .obj-


import chainer
import numpy as np
import scipy.misc
import neural_renderer

renderer = neural_renderer.Renderer()

vertices, faces, textures = neural_renderer.load_obj( '/home/user/jay/straight.obj', load_texture=True, texture_size=16)

neural_renderer.save_obj('/home/user/jay/chainer_save.obj', vertices, faces, textures)

But getting error at this assert So changed this line to

self.register_buffer('vertices', vertices[:, :])
self.register_buffer('faces', faces[:, :])

But facing issue in renderer.py. So i changed the code with below line.

faces = torch.cat((faces, faces[:, list(reversed(range(faces.shape[-1])))]), dim=1).detach()

Then i was getting error in vertices_to_faces.py so i changed below vertices & faces assert to 2.

assert (vertices.ndimension() == 2)
assert (faces.ndimension() == 2)

But I am getting error at this line assert (vertices.shape[0] == faces.shape[0])because vertices.shape[0] = 34817 faces.shape[0] = 69630.

Where am i doing wrong ? Could you please help me to fix this.

nkolot commented 5 years ago

You need to add a dummy batch dimension, so vertices will be (1,34817,3) and faces (1,69630,3).