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 3D face #30

Open
icegaomu opened this issue Jul 12, 2022 · 7 comments
Open

How to save 3D face #30

icegaomu opened this issue Jul 12, 2022 · 7 comments

Comments

@icegaomu
Copy link

Thank you for finsh this great job!
I have some questions about how to get 3D mesh and texture in your code?
I want to same then individual as obj or plt format and get 3D normal ,I don’t see those code but your paper show those 3D shapes .
I look forward to hearing from you.thanks again!

@philgras
Copy link
Owner

Hi,

in nha_optimizer.py, there is a method for rendering the shaded mesh

@torch.no_grad()
    def predict_shaded_mesh(self, batch, tex_color=np.array((188, 204, 245)) / 255, light_colors=(0.4, 0.6, 0.3)):
        K = batch["cam_intrinsic"]
        RT = batch["cam_extrinsic"]
        H, W = batch["rgb"].shape[-2:]

        flame_params_offsets = self._create_flame_param_batch(batch)
        offsets_verts, _ = self._forward_flame(flame_params_offsets)

        vertex_colors = torch.ones_like(offsets_verts) * torch.tensor(tex_color, device=self.device).float().view(1, 3)
        # define meshes and textures
        tex = TexturesVertex(vertex_colors)
        mesh = Meshes(
            verts=offsets_verts,
            faces=self._flame.faces[None].expand(len(offsets_verts), -1, -1),
            textures=tex,
        )

        return render_shaded_mesh(mesh, K, RT, (H, W), self.device, light_colors)

You can use this as a starting point. The mesh object can be used to compute per-vertex normals or can be saved to .obj or other formats using pytorch.io.*

Hope this helps!

@philgras philgras mentioned this issue Jul 15, 2022
@icegaomu
Copy link
Author

Thank you for the answer,but I want to save the whole RGB image or called UV maps ,but there is a little complex to save the object with texture, because i only find the render_rgba program. And it's for the novel view images generation, is there have a more easy way to save the texture ? Thanks again!

@icegaomu
Copy link
Author

def predict_shaded_mesh(self, batch, tex_color=np.array((188, 204, 245)) / 255, light_colors=(0.4, 0.6, 0.3))
And this program give a const tex_color ,but now i can't save the whole texture (not from one view) can you give me some advice?

@qiuyuzhao
Copy link

Hi,

in nha_optimizer.py, there is a method for rendering the shaded mesh

@torch.no_grad()
    def predict_shaded_mesh(self, batch, tex_color=np.array((188, 204, 245)) / 255, light_colors=(0.4, 0.6, 0.3)):
        K = batch["cam_intrinsic"]
        RT = batch["cam_extrinsic"]
        H, W = batch["rgb"].shape[-2:]

        flame_params_offsets = self._create_flame_param_batch(batch)
        offsets_verts, _ = self._forward_flame(flame_params_offsets)

        vertex_colors = torch.ones_like(offsets_verts) * torch.tensor(tex_color, device=self.device).float().view(1, 3)
        # define meshes and textures
        tex = TexturesVertex(vertex_colors)
        mesh = Meshes(
            verts=offsets_verts,
            faces=self._flame.faces[None].expand(len(offsets_verts), -1, -1),
            textures=tex,
        )

        return render_shaded_mesh(mesh, K, RT, (H, W), self.device, light_colors)

You can use this as a starting point. The object can be used to compute per-vertex normals or can be saved to .obj or other formats using pytorch.io.*mesh

Hope this helps!

This seems to only save before rendering,how to get the rendered?

@icegaomu
Copy link
Author

I try to save the texture uv map first by change the render_rgba program ,but it also get some problem because of there are not certain parameter about pix_to_face,and it's vertex weight . @qiuyuzhao this is my email [email protected] we can have a communicate or if you have some correct change or save the rendered obj successful please tell me ! thanks a lot

@yangqing-yq
Copy link

I try to save the texture uv map first by change the render_rgba program ,but it also get some problem because of there are not certain parameter about pix_to_face,and it's vertex weight . @qiuyuzhao this is my email [email protected] we can have a communicate or if you have some correct change or save the rendered obj successful please tell me ! thanks a lot

hey bro, any solution here?

@icegaomu
Copy link
Author

I‘m sorry not.but i don't try the way sampling in the whole 3d space.maybe this method is work,and the whole time to genarate a face is too long,so i will not fellow this work.

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

4 participants