athn-nik / teach

Official PyTorch implementation of the paper "TEACH: Temporal Action Compositions for 3D Humans"
https://teach.is.tue.mpg.de
Other
383 stars 40 forks source link

How to export smpl model with the joints, trans, beta and etc. info? #14

Closed Stomachache007 closed 1 year ago

Stomachache007 commented 1 year ago

I would like to export the smpl model with joints, trans and beta information. Any idea how I get it?

athn-nik commented 1 year ago

From the interact_teach script or in general? The idea is if you wan to export the motions generated from the inference code? Actually I save it here. In case you want the rotations you can add a line here and save the rots and transl variables forward_seq -- which are the rotations and translation in SMPL format. The betas are not really used so you can set them to zeros. The joint positions are the ones one line below .joints and can also be returned from forward_seq if you pass the argument return_type=joints instead of vertices.

Stomachache007 commented 1 year ago

From the interact_teach script or in general? The idea is if you wan to export the motions generated from the inference code? Actually I save it here. In case you want the rotations you can add a line here and save the rots and transl variables forward_seq -- which are the rotations and translation in SMPL format. The betas are not really used so you can set them to zeros. The joint positions are the ones one line below .joints and can also be returned from forward_seq if you pass the argument return_type=joints instead of vertices.

Hi athn-nik, thanks for your reply. What I want is motions which can be exported into blender(https://gitlab.tuebingen.mpg.de/jtesch/smplx_blender_addon/-/blob/master/__init__.py) as animation. It needs smplx joints 55 3 and transl 1 3 info.

I tried

        from teach.transforms.smpl import RotTransDatastruct
        final_datastruct = self.Datastruct(rots_=RotTransDatastruct(rots=rots, trans=transl))
        print("joints ",final_datastruct.joints.shape)
        print("vertices ", final_datastruct.vertices.shape)
        if return_type == "vertices":
            return final_datastruct.vertices
        elif return_type == "joints":
            return final_datastruct.joints
        else:
            raise NotImplementedError

and find the output joints and vertices have exactly the same shape:

joints torch.Size([270, 6890, 3]) vertices torch.Size([270, 6890, 3])

I assume joints size should me much smaller than vertices 6890. So may I ask how to get the joints with 55*3?

thanks.

athn-nik commented 1 year ago

So to do this you must take the rots and trans and pad the with zeros [for the extra joints] up to 55 and then it should work. Note that the joint you refer to I think are the SMPL rotations and not the joint positions referred as joints in the code. So you take the rots pad them with zeros to fit your purpose and the translation does the job you want to(transl.) put an extra line above the return type to save them and use them in blender

athn-nik commented 1 year ago

Let me know, how this goes so I can close this.

Stomachache007 commented 1 year ago

Hi athn-nik,

  1. I print transl by
        print("transl ", transl.shape)

    before here. got

    transl  torch.Size([180, 3])

I assume this is the transl needed for blender animation. please correct me if you think I am wrong.

  1. Besides this transl, to convert smpl data to a blender animation, the real poses(which I guess is joints information) is also needed, not the rots + trans + pad, it should be real poses. Transfer smpl to animation is desecribed here and the 55 joints name are here

To get the joints I tried two things 2.a and 2.b:

find this smpl_output is batch_size 73 3, this is the final smplh joints info right? Can I transfer it into a smplx? Because I only saw blender support smplx.

joints shape torch.Size([180, 6890, 3])

joints [[-0.26980534 0.01313967 1.5121334 ] [-0.26402193 0.01042563 1.4962435 ] [-0.26557612 -0.00282052 1.5022819 ] ...

vertices shape torch.Size([180, 6890, 3])

vertices [[-0.26980534 0.01313967 1.5121334 ] [-0.26402193 0.01042563 1.4962435 ] [-0.26557612 -0.00282052 1.5022819 ] ...

motion shape torch.Size([180, 6890, 3])

while the vertices and joints look exactly the same. I think these are not the joints. may be a bug here.

So may I ask how I can get the smplx joints info?

ps:As I saw you only implement smplh, do I need to implement something for smplx?

thanks.

athn-nik commented 1 year ago

Let me try to explain. The joints vertices point 3 seems like my bug but it is irrelevant for what you want to do. The poses you need are the SMPL poses which are the joint rotations not the joint positions. The 55 joints are kind of irrelevant and are the joint positions you need the rotations.

As I said in the previous comment you can get the rotations in here. Just add a line to save them like pickle or np save . The variables you need are rots and transl from that line which are the rotations and translation.

I am using SMPL right now and SMPL is enough for my training data because AMASS has almost zero face and hand expressions (the rest of the joints beyond of the first 22). So save those joints and translation. Those are the real poses you refer to. Next because there is no motion for the rest you can just set them to zero to make the target shape that the plugin accepts compatible with the the shape of the motion.

Stomachache007 commented 1 year ago

thanks athn-nik, Let me try later(it may takes sometime, a bit busy now). And update feedback with you.

zhuangzhuang000 commented 1 year ago

thanks athn-nik, Let me try later(it may takes sometime, a bit busy now). And update feedback with you.

Hello, have you got the position of the joints? Could you share the method with me? Thank you!

athn-nik commented 1 year ago

If you set the model.rots2joints.jointstype = mmm it will return the joints.

zhuangzhuang000 commented 1 year ago

If you set the model.rots2joints.jointstype = mmm it will return the joints.

Hello! Thank you for your reply, but I still have some questions. Where should I return the result?

I tried to set the 'model.transforms.rots2joints.jointstype = "mmm"' in 【interact_teach.py】, and I also tried to change the 'return_type='joints'' in 【interact_teach.py】, but the results I got are all the same shape (motion shape torch.Size([60, 6890, 3])), it is the same as the last questioner.

What I want is the position of joints, I think the shape shold be [frame, number of joints, 3], where did I make a mistake? Could you help me?

athn-nik commented 1 year ago

Have you tried changing the line model.transforms.rots2joints='vertices' to the interact_teach.py?

zhuangzhuang000 commented 1 year ago

Have you tried changing the line model.transforms.rots2joints='vertices' to the interact_teach.py?

Thank you! I set the 'model.transforms.rots2joints.jointstype = "mmm" and 'return_type='joints'' , it works!

athn-nik commented 1 year ago

You 're welcome, I will change the code to make it more obvious

yufu-liu commented 1 year ago

Hi, guys! Thanks for these detailed steps to get rotation and translation/position.

After getting all the information, I wonder that is there any difference between generated translation and orignal translation in AMASS? Because I plotted the mesh with translation and rotation instead of plotting with vertices like the code, my mesh has a drift problem.