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

How to save as .obj #20

Open
jay-thakur opened this issue Apr 12, 2019 · 8 comments
Open

How to save as .obj #20

jay-thakur opened this issue Apr 12, 2019 · 8 comments

Comments

@jay-thakur
Copy link

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 facing issue in renderer.py. So i changed below code like this.
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
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?

@minghaoPA
Copy link

I think the shape[0] is to make sure batch sizes are equal to each other. So you need to add an extra '0' dimension as batch size, like line25 and line26 in example3.py.

    vertices, faces = neural_renderer.load_obj(filename_obj)
    self.vertices = vertices[None, :, :]
    self.faces = faces[None, :, :]

Hopefully my understanding is helpful to your problem.

And if you have time, please also take a look at my question #21 , which is also related to save_obj.py.

@jay-thakur
Copy link
Author

I believe, if we add extra '0' as you suggested, then vertices & faces will be of 3 dimension. & in save_obj() we have assert statement for vertices & faces to 2. Please correct me if i am wrong.

I am expecting to save the .obj with its texture . Do you have working code for the same? Could you please share your example3.py ?

Thanks,
Jay

@minghaoPA
Copy link

Hi Jay. For your concern, please check out my code at question #21. I am sharing my piece of code there.

But anyway, I just slice out the first dimension and feed the rest into save_obj. And I am also a little confused about your question. The vertices_to_faces is not called either in load_obj.py or save_obj.py. So I don't encounter any problem related to dimension assertion. Maybe it's because you are using torch edition from another repo, not exactly the same code as this repo?

@minghaoPA
Copy link

For simplicity, here are the codes added before #draw object module in example3.py

    # save obj with textures
    #TODO: textures are not reasonable
    model.textures_1 = cf.concat((model.textures, model.textures.transpose((0, 1, 4, 3, 2, 5))), axis=1)
    neural_renderer.save_obj('result.obj', model.vertices[0], model.faces[0], cf.tanh(model.textures_1[0]).array)

@jay-thakur
Copy link
Author

Sorry, I am using another repo.

@Goldname100
Copy link

@jay-thakur Which repo are you using?

@kelly08385
Copy link

I have the same problem when saved the rendered object.
The error said

cupy.cuda.compiler.CompileException: /tmp/tmp72lc77x3/44a6062960e6de87983184b4a18c1a10_2.cubin.cu(20): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"

/tmp/tmp72lc77x3/44a6062960e6de87983184b4a18c1a10_2.cubin.cu(21): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"

/tmp/tmp72lc77x3/44a6062960e6de87983184b4a18c1a10_2.cubin.cu(75): error: expression must be a modifiable lvalue

I think it's chain, cupy or cuda versions problem.
I run in python3.8 and cuda10.2
What chain and cupy version should I select?
thanks

@caojiehui
Copy link

I have the same problem when saved the rendered object. The error said

cupy.cuda.compiler.CompileException: /tmp/tmp72lc77x3/44a6062960e6de87983184b4a18c1a10_2.cubin.cu(20): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"

/tmp/tmp72lc77x3/44a6062960e6de87983184b4a18c1a10_2.cubin.cu(21): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"

/tmp/tmp72lc77x3/44a6062960e6de87983184b4a18c1a10_2.cubin.cu(75): error: expression must be a modifiable lvalue

I think it's chain, cupy or cuda versions problem. I run in python3.8 and cuda10.2 What chain and cupy version should I select? thanks

Hello, I have encountered the same issue as you. How did you resolve this problem? Was it related to the version?

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

No branches or pull requests

5 participants