Created
September 26, 2022 08:00
-
-
Save gerwang/901658f9d238f4e1400fb8326d4b2a5a to your computer and use it in GitHub Desktop.
Caculate chamfer distance on the DiLiGent-MV dataset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"id": "c72e321c-6dcc-484f-bbb5-66e07dcf7eb7", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from pytorch3d.io import load_ply\n", | |
"from pytorch3d.structures import Meshes\n", | |
"from pytorch3d.loss import chamfer_distance" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "883ec12a-03f1-4559-abe9-61b2fe18aff9", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pred_path = '/path/to/DiLiGenT-MV/estMesh/bearPNG_Mesh_PAMI16Park.ply'\n", | |
"gt_path = '/path/to/DiLiGenT-MV/mvpmsData/bearPNG/mesh_Gt.ply'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "48261e85-b315-42bf-82de-7fcf989f4819", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pred_verts, pred_faces = load_ply(pred_path)\n", | |
"gt_verts, gt_faces = load_ply(gt_path)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"id": "3d1b528b-642c-4966-bf56-6ed6d4fdf472", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pred_mesh = Meshes(verts=[pred_verts], faces=[pred_faces])\n", | |
"gt_mesh = Meshes(verts=[gt_verts], faces=[gt_faces])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"id": "ee6d76f3-5766-467c-a5f9-5c968ee7a407", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"torch.Size([1, 1155220, 3])" | |
] | |
}, | |
"execution_count": 22, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pred_mesh.verts_padded().shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"id": "d891155e-c514-43b9-94f9-90e76026ccda", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"device(type='cpu')" | |
] | |
}, | |
"execution_count": 23, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"pred_mesh.verts_padded().device" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"id": "93c7e174-c61d-4622-92aa-8c28b23c35d4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(tensor(2.5251, device='cuda:0'), None)" | |
] | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"chamfer_distance(pred_mesh.verts_padded().cuda(), gt_mesh.verts_padded().cuda())" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment