Skip to content

Commit

Permalink
Amass visualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kaseris committed Jan 17, 2024
1 parent e109b5b commit 078127f
Showing 1 changed file with 116 additions and 47 deletions.
163 changes: 116 additions & 47 deletions notebooks/amass_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib notebook\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -26,18 +38,9 @@
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_680365/1067486171.py:4: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.\n",
" subject_gender = bdata['gender'].tostring().decode('utf-8')\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"amass_npz_fname = osp.join(support_dir, 'github_data/dmpl_sample.npz')\n",
"bdata = np.load(amass_npz_fname)\n",
Expand All @@ -57,20 +60,9 @@
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The available keys from the read file are: ['poses', 'gender', 'mocap_framerate', 'betas', 'marker_data', 'dmpls', 'marker_labels', 'trans']\n",
"betas: (16,)\n",
"dmpls: (235, 8)\n",
"The subject gender is: female\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(f'The available keys from the read file are: {list(bdata.keys())}')\n",
"print(f'betas: {bdata[\"betas\"].shape}')\n",
Expand All @@ -80,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -111,24 +103,9 @@
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Body parameter vector shapes: \n",
"root_orient: torch.Size([235, 3]) \n",
"pose_body: torch.Size([235, 63]) \n",
"pose_hand: torch.Size([235, 90]) \n",
"trans: torch.Size([235, 3]) \n",
"betas: torch.Size([235, 16]) \n",
"dmpls: torch.Size([235, 8])\n",
"time_length = 235\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"time_length = len(bdata['trans'])\n",
"body_parms = {\n",
Expand All @@ -148,7 +125,99 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"import trimesh\n",
"from body_visualizer.tools.vis_tools import colors\n",
"from body_visualizer.mesh.mesh_viewer import MeshViewer\n",
"from body_visualizer.mesh.sphere import points_to_spheres\n",
"from body_visualizer.tools.vis_tools import show_image\n",
"\n",
"imw, imh=1600, 1600\n",
"mv = MeshViewer(width=imw, height=imh, use_offscreen=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"body_pose_beta = bm(**{k:v for k,v in body_parms.items() if k in ['pose_body', 'betas']})\n",
"\n",
"def vis_body_pose_beta(fId = 0):\n",
" body_mesh = trimesh.Trimesh(vertices=c2c(body_pose_beta.v[fId]), faces=faces, vertex_colors=np.tile(colors['grey'], (6890, 1)))\n",
" mv.set_static_meshes([body_mesh])\n",
" body_image = mv.render(render_wireframe=False)\n",
" show_image(body_image)\n",
"\n",
"vis_body_pose_beta(fId=0)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the model has a more realistic hand posture"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"body_pose_hand = bm(**{k:v for k,v in body_parms.items() if k in ['pose_body', 'betas', 'pose_hand']})\n",
"\n",
"def vis_body_pose_hand(fId = 0):\n",
" body_mesh = trimesh.Trimesh(vertices=c2c(body_pose_hand.v[fId]), faces=faces, vertex_colors=np.tile(colors['grey'], (6890, 1)))\n",
" mv.set_static_meshes([body_mesh])\n",
" body_image = mv.render(render_wireframe=False)\n",
" show_image(body_image)\n",
"\n",
"vis_body_pose_hand(fId=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualize the body joints"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def vis_body_joints(fId = 0):\n",
" joints = c2c(body_pose_hand.Jtr[fId])\n",
" joints_mesh = points_to_spheres(joints, point_color = colors['red'], radius=0.005)\n",
"\n",
" mv.set_static_meshes([joints_mesh])\n",
" body_image = mv.render(render_wireframe=False)\n",
" show_image(body_image)\n",
"\n",
"vis_body_joints(fId=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"body_dmpls = bm(**{k:v for k,v in body_parms.items() if k in ['pose_body', 'betas', 'pose_hand', 'dmpls']})\n",
"\n",
"def vis_body_dmpls(fId = 0):\n",
" body_mesh = trimesh.Trimesh(vertices=c2c(body_dmpls.v[fId]), faces=faces, vertex_colors=np.tile(colors['grey'], (6890, 1)))\n",
" mv.set_static_meshes([body_mesh])\n",
" body_image = mv.render(render_wireframe=False)\n",
" show_image(body_image)\n",
"\n",
"vis_body_dmpls(fId=0)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 078127f

Please sign in to comment.