Native Windows video motion capture with ExMR, FlowHMR and GVHMR, contact correction, humanoid retargeting, and FBX/VMD export.
Python
# -*- coding: utf-8 -*-
# Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is
# holder of all proprietary rights on this computer program.
# You can only use this computer program if you have closed
# a license agreement with MPG or you get the right to use the computer
# program from someone who is authorized to grant you that right.
# Any use of the computer program without a valid license is prohibited and
# liable to prosecution.
# Copyright©2019 Max-Planck-Gesellschaft zur Förderung
# der Wissenschaften e.V. (MPG). acting on behalf of its Max Planck Institute
# for Intelligent Systems. All rights reserved.
# Contact: [email protected]
from __future__ import absolute_import
from __future__ import print_function
from __future__ import division
import numpy as np
import torch
import torch.nn as nn
from typing import NewType, Union, Optional
from dataclasses import dataclass, asdict, fields
import numpy as np
import torch
Tensor = NewType('Tensor', torch.Tensor)
Array = NewType('Array', np.ndarray)
COCO17_IN_BODY25 = [0,16,15,18,17,5,2,6,3,7,4,12,9,13,10,14,11]
def coco17tobody25(points2d):
kpts = np.zeros((points2d.shape[0], 25, 3))
kpts[:, COCO17_IN_BODY25, :2] = points2d[:, :, :2]
kpts[:, COCO17_IN_BODY25, 2:3] = points2d[:, :, 2:3]
kpts[:, 8, :2] = kpts[:, [9, 12], :2].mean(axis=1)
kpts[:, 8, 2] = kpts[:, [9, 12], 2].min(axis=1)
kpts[:, 1, :2] = kpts[:, [2, 5], :2].mean(axis=1)
kpts[:, 1, 2] = kpts[:, [2, 5], 2].min(axis=1)
return kpts
def coco23tobody25(points2d):
kpts = coco17tobody25(points2d[:, :17, :])
kpts[:, [19, 20, 21, 22, 23, 24], :] = points2d[:, 17:23, :]
return kpts
def coco133tobody25(points2d):
kpts = coco23tobody25(points2d[:, :23, :])
return kpts
smpl_to_openpose = [24, 12, 17, 19, 21, 16, 18, 20, 0, 2, 5, 8, 1, 4,
7, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
smplx_to_openpose = [55, 12, 17, 19, 21, 16, 18, 20, 0, 2, 5, 8, 1, 4,
7, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65]
smplx_lr_hand_inds = [20, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
21, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54]
smplx42tohand42 = [
40, 10, 11, 12, 1, 13, 14, 15, 2, 16, 17, 18, 4, 19, 20, 21, 3, 22, 23, 24, 0,
41, 25, 26, 27, 6, 28, 29, 30, 7, 31, 32, 33, 9, 34, 35, 36, 8, 37, 38, 39, 5
]
# smpl_extra_ids = {
SMPLH_FOOT_SOLE_VERTEX_IDS = [3216, 3226, 3387, 6617, 6624, 6787]
# LBigToe, LSmallToe, LHeel, RBigToe, RSmallToe, RHeel
smplx_ids = {
'nose': 9120,
'reye': 9929,
'leye': 9448,
'rear': 616,
'lear': 6,
'rthumb': 8079,
'rindex': 7669,
'rmiddle': 7794,
'rring': 7905,
'rpinky': 8022,
'lthumb': 5361,
'lindex': 4933,
'lmiddle': 5058,
'lring': 5169,
'lpinky': 5286,
'LBigToe': 5770,
'LSmallToe': 5780,
'LHeel': 8846,
'RBigToe': 8463,
'RSmallToe': 8474,
'RHeel': 8635}
smplx42_lr_hand_ids = {'l_thumb4': 0, 'l_index4': 1, 'l_middle4': 2, 'l_ring4': 3, 'l_pinky4': 4,
'r_thumb4': 5, 'r_index4': 6, 'r_middle4': 7, 'r_ring4': 8, 'r_pinky4': 9,
'l_index1': 10, 'l_index2': 11, 'l_index3': 12, 'l_middle1': 13, 'l_middle2': 14, 'l_middle3': 15,
'l_pinky1': 16, 'l_pinky2': 17, 'l_pinky3': 18, 'l_ring1': 19, 'l_ring2': 20, 'l_ring3': 21,
'l_thumb1': 22, 'l_thumb2': 23, 'l_thumb3': 24, 'r_index1': 25, 'r_index2': 26, 'r_index3': 27,
'r_middle1': 28, 'r_middle2': 29, 'r_middle3': 30, 'r_pinky1': 31, 'r_pinky2': 32, 'r_pinky3': 33,
'r_ring1': 34, 'r_ring2': 35, 'r_ring3': 36, 'r_thumb1': 37, 'r_thumb2': 38, 'r_thumb3': 39,
'l_wrist': 40, 'r_wrist': 41}
hand42 = {'r_thumb4': 0, 'r_thumb3': 1, 'r_thumb2': 2, 'r_thumb1': 3,
'r_index4': 4, 'r_index3': 5, 'r_index2': 6, 'r_index1': 7,
'r_middle4': 8, 'r_middle3': 9, 'r_middle2': 10, 'r_middle1': 11,
'r_ring4': 12, 'r_ring3': 13, 'r_ring2': 14, 'r_ring1': 15,
'r_pinky4': 16, 'r_pinky3': 17, 'r_pinky2': 18, 'r_pinky1': 19, 'r_wrist': 20,
'l_thumb4': 21, 'l_thumb3': 22, 'l_thumb2': 23, 'l_thumb1': 24,
'l_index4': 25, 'l_index3': 26, 'l_index2': 27, 'l_index1': 28,
'l_middle4': 29, 'l_middle3': 30, 'l_middle2': 31, 'l_middle1': 32,
'l_ring4': 33, 'l_ring3': 34, 'l_ring2': 35, 'l_ring1': 36,
'l_pinky4': 37, 'l_pinky3': 38, 'l_pinky2': 39, 'l_pinky1': 40, 'l_wrist': 41}
mano_smplx_lhand_vertex_ids = torch.tensor([
4597, 4598, 4595, 4596, 4602, 4599, 4600, 4601, 4604, 4603, 4606,
4607, 4605, 4610, 4608, 4609, 4611, 4612, 4613, 4614, 4615, 4616,
4617, 4618, 4621, 4622, 4619, 4620, 4625, 4626, 4623, 4624, 4629,
4630, 4627, 4628, 4634, 4631, 4632, 4633, 4637, 4635, 4636, 4638,
4640, 4639, 4643, 4644, 4641, 4642, 4647, 4648, 4645, 4646, 4649,
4650, 4653, 4654, 4651, 4652, 4656, 4655, 4659, 4660, 4657, 4658,
4663, 4664, 4661, 4662, 4667, 4668, 4665, 4666, 4671, 4672, 4669,
4670, 4673, 4674, 4677, 4678, 4675, 4676, 4679, 4680, 4682, 4681,
4683, 4684, 4685, 4687, 4686, 4688, 4689, 4690, 4693, 4694, 4691,
4692, 4697, 4698, 4695, 4696, 4699, 4700, 4702, 4701, 4703, 4706,
4707, 4704, 4705, 4708, 4709, 4710, 4711, 4713, 4712, 4714, 4715,
4720, 4723, 4729, 4730, 4727, 4728, 4733, 4731, 4732, 4734, 4735,
4736, 4739, 4740, 4737, 4738, 4743, 4744, 4741, 4742, 4745, 4746,
4749, 4747, 4748, 4751, 4752, 4750, 4755, 4756, 4753, 4754, 4757,
4758, 4760, 4759, 4763, 4764, 4765, 4768, 4769, 4766, 4767, 4772,
4773, 4770, 4771, 4776, 4777, 4774, 4775, 4778, 4779, 4782, 4783,
4780, 4781, 4784, 4785, 4786, 4787, 4788, 4789, 4790, 4792, 4793,
4791, 4794, 4795, 4796, 4797, 4798, 4799, 4800, 4801, 4804, 4805,
4802, 4803, 4806, 4808, 4807, 4810, 4811, 4809, 4812, 4813, 4814,
4815, 4816, 4817, 4819, 4818, 4820, 4822, 4824, 4825, 4826, 4827,
4828, 4831, 4832, 4829, 4830, 4833, 4834, 4835, 4836, 4837, 4838,
4839, 4840, 4841, 4842, 4843, 4845, 4846, 4847, 4849, 4850, 4852,
4851, 4854, 4853, 4859, 4860, 4861, 4862, 4863, 4866, 4867, 4864,
4865, 4868, 4869, 4871, 4870, 4872, 4873, 4874, 4875, 4877, 4876,
4878, 4879, 4880, 4881, 4882, 4883, 4884, 4885, 4886, 4887, 4888,
4889, 4890, 4891, 4892, 4893, 4895, 4894, 4896, 4897, 4898, 4899,
4902, 4901, 4903, 4904, 4907, 4905, 4906, 4908, 4909, 4910, 4911,
4912, 4913, 4914, 4915, 4916, 4917, 4918, 4921, 4922, 4919, 4920,
4924, 4923, 4925, 4926, 4929, 4927, 4928, 4930, 4931, 4934, 4935,
4932, 4933, 4936, 4937, 4938, 4939, 4941, 4940, 4942, 4944, 4943,
4945, 4946, 4947, 4948, 4949, 4950, 4951, 4952, 4954, 4953, 4955,
4956, 4957, 4958, 4959, 4960, 4961, 4962, 4964, 4963, 4965, 4966,
4967, 4970, 4968, 4969, 4973, 4974, 4971, 4972, 4977, 4978, 4975,
4976, 4980, 4979, 4983, 4984, 4981, 4982, 4985, 4986, 4988, 4987,
4991, 4992, 4989, 4990, 4993, 4994, 4995, 4998, 4999, 4996, 4997,
5000, 5001, 5002, 5004, 5003, 5007, 5008, 5005, 5006, 5009, 5010,
5011, 5012, 5013, 5014, 5015, 5016, 5018, 5017, 5019, 5020, 5021,
5022, 5023, 5024, 5025, 5026, 5027, 5028, 5029, 5030, 5033, 5034,
5031, 5032, 5036, 5035, 5037, 5038, 5041, 5039, 5040, 5042, 5044,
5043, 5045, 5046, 5047, 5048, 5049, 5051, 5050, 5052, 5054, 5053,
5055, 5056, 5057, 5058, 5059, 5060, 5061, 5062, 5063, 5064, 5066,
5065, 5067, 5068, 5069, 5070, 5071, 5072, 5073, 5074, 5076, 5075,
5077, 5078, 5079, 5082, 5080, 5081, 5085, 5086, 5083, 5084, 5089,
5090, 5087, 5088, 5092, 5091, 5095, 5096, 5093, 5094, 5098, 5097,
5101, 5102, 5099, 5100, 5104, 5103, 5105, 5108, 5109, 5106, 5107,
5110, 5111, 5112, 5114, 5113, 5117, 5118, 5115, 5116, 5119, 5120,
5121, 5122, 5123, 5124, 5125, 5126, 5127, 5129, 5128, 5130, 5131,
5132, 5133, 5134, 5135, 5136, 5137, 5138, 5139, 5140, 5141, 5144,
5145, 5142, 5143, 5147, 5146, 5148, 5149, 5152, 5150, 5151, 5153,
5155, 5154, 5156, 5157, 5158, 5159, 5160, 5162, 5161, 5163, 5165,
5164, 5166, 5167, 5168, 5169, 5170, 5171, 5172, 5173, 5174, 5175,
5177, 5176, 5178, 5179, 5180, 5181, 5182, 5183, 5184, 5185, 5187,
5186, 5188, 5189, 5190, 5193, 5191, 5192, 5194, 5197, 5198, 5195,
5196, 5201, 5202, 5199, 5200, 5204, 5203, 5207, 5208, 5205, 5206,
5211, 5212, 5209, 5210, 5214, 5213, 5217, 5218, 5215, 5216, 5221,
5222, 5219, 5220, 5223, 5226, 5227, 5224, 5225, 5228, 5229, 5230,
5232, 5231, 5235, 5236, 5233, 5234, 5237, 5238, 5239, 5240, 5241,
5242, 5243, 5244, 5246, 5245, 5247, 5248, 5249, 5250, 5251, 5252,
5253, 5254, 5255, 5256, 5257, 5258, 5261, 5262, 5259, 5260, 5264,
5263, 5265, 5266, 5269, 5267, 5268, 5270, 5272, 5271, 5273, 5274,
5275, 5276, 5277, 5279, 5278, 5280, 5282, 5281, 5283, 5284, 5285,
5286, 5287, 5288, 5289, 5290, 5291, 5292, 5294, 5293, 5295, 5296,
5297, 5298, 5299, 5300, 5301, 5302, 5304, 5303, 5305, 5306, 5307,
5310, 5308, 5309, 5311, 5313, 5312, 5314, 5315, 5316, 5317, 5318,
5319, 5320, 5321, 5322, 5323, 5324, 5325, 5326, 5327, 5328, 5329,
5330, 5331, 5334, 5335, 5332, 5333, 5337, 5336, 5339, 5338, 5340,
5341, 5342, 5344, 5343, 5345, 5346, 5347, 5348, 5351, 5352, 5354,
5353, 5355, 5357, 5356, 5358, 5359, 5360, 5361, 5362, 5363, 5365,
5364, 5366, 5367, 5369, 5368, 5370, 5371, 5372, 5373, 5374, 5375,
5376, 5377, 5379, 5378, 5380, 5381, 5382, 5385, 5383, 5384, 5386,
5387, 5388, 5389, 5390, 5391, 5392, 5393, 5394]).long()
mano_smplx_rhand_vertex_ids = torch.tensor([
7333, 7334, 7331, 7332, 7338, 7335, 7336, 7337, 7340, 7339, 7342,
7343, 7341, 7346, 7344, 7345, 7347, 7348, 7349, 7350, 7351, 7352,
7353, 7354, 7357, 7358, 7355, 7356, 7361, 7362, 7359, 7360, 7365,
7366, 7363, 7364, 7370, 7367, 7368, 7369, 7373, 7371, 7372, 7374,
7376, 7375, 7379, 7380, 7377, 7378, 7383, 7384, 7381, 7382, 7385,
7386, 7389, 7390, 7387, 7388, 7392, 7391, 7395, 7396, 7393, 7394,
7399, 7400, 7397, 7398, 7403, 7404, 7401, 7402, 7407, 7408, 7405,
7406, 7409, 7410, 7413, 7414, 7411, 7412, 7415, 7416, 7418, 7417,
7419, 7420, 7421, 7423, 7422, 7424, 7425, 7426, 7429, 7430, 7427,
7428, 7433, 7434, 7431, 7432, 7435, 7436, 7438, 7437, 7439, 7442,
7443, 7440, 7441, 7444, 7445, 7446, 7447, 7449, 7448, 7450, 7451,
7456, 7459, 7465, 7466, 7463, 7464, 7469, 7467, 7468, 7470, 7471,
7472, 7475, 7476, 7473, 7474, 7479, 7480, 7477, 7478, 7481, 7482,
7485, 7483, 7484, 7487, 7488, 7486, 7491, 7492, 7489, 7490, 7493,
7494, 7496, 7495, 7499, 7500, 7501, 7504, 7505, 7502, 7503, 7508,
7509, 7506, 7507, 7512, 7513, 7510, 7511, 7514, 7515, 7518, 7519,
7516, 7517, 7520, 7521, 7522, 7523, 7524, 7525, 7526, 7528, 7529,
7527, 7530, 7531, 7532, 7533, 7534, 7535, 7536, 7537, 7540, 7541,
7538, 7539, 7542, 7544, 7543, 7546, 7547, 7545, 7548, 7549, 7550,
7551, 7552, 7553, 7555, 7554, 7556, 7558, 7560, 7561, 7562, 7563,
7564, 7567, 7568, 7565, 7566, 7569, 7570, 7571, 7572, 7573, 7574,
7575, 7576, 7577, 7578, 7579, 7581, 7582, 7583, 7585, 7586, 7588,
7587, 7590, 7589, 7595, 7596, 7597, 7598, 7599, 7602, 7603, 7600,
7601, 7604, 7605, 7607, 7606, 7608, 7609, 7610, 7611, 7613, 7612,
7614, 7615, 7616, 7617, 7618, 7619, 7620, 7621, 7622, 7623, 7624,
7625, 7626, 7627, 7628, 7629, 7631, 7630, 7632, 7633, 7634, 7635,
7638, 7637, 7639, 7640, 7643, 7641, 7642, 7644, 7645, 7646, 7647,
7648, 7649, 7650, 7651, 7652, 7653, 7654, 7657, 7658, 7655, 7656,
7660, 7659, 7661, 7662, 7665, 7663, 7664, 7666, 7667, 7670, 7671,
7668, 7669, 7672, 7673, 7674, 7675, 7677, 7676, 7678, 7680, 7679,
7681, 7682, 7683, 7684, 7685, 7686, 7687, 7688, 7690, 7689, 7691,
7692, 7693, 7694, 7695, 7696, 7697, 7698, 7700, 7699, 7701, 7702,
7703, 7706, 7704, 7705, 7709, 7710, 7707, 7708, 7713, 7714, 7711,
7712, 7716, 7715, 7719, 7720, 7717, 7718, 7721, 7722, 7724, 7723,
7727, 7728, 7725, 7726, 7729, 7730, 7731, 7734, 7735, 7732, 7733,
7736, 7737, 7738, 7740, 7739, 7743, 7744, 7741, 7742, 7745, 7746,
7747, 7748, 7749, 7750, 7751, 7752, 7754, 7753, 7755, 7756, 7757,
7758, 7759, 7760, 7761, 7762, 7763, 7764, 7765, 7766, 7769, 7770,
7767, 7768, 7772, 7771, 7773, 7774, 7777, 7775, 7776, 7778, 7780,
7779, 7781, 7782, 7783, 7784, 7785, 7787, 7786, 7788, 7790, 7789,
7791, 7792, 7793, 7794, 7795, 7796, 7797, 7798, 7799, 7800, 7802,
7801, 7803, 7804, 7805, 7806, 7807, 7808, 7809, 7810, 7812, 7811,
7813, 7814, 7815, 7818, 7816, 7817, 7821, 7822, 7819, 7820, 7825,
7826, 7823, 7824, 7828, 7827, 7831, 7832, 7829, 7830, 7834, 7833,
7837, 7838, 7835, 7836, 7840, 7839, 7841, 7844, 7845, 7842, 7843,
7846, 7847, 7848, 7850, 7849, 7853, 7854, 7851, 7852, 7855, 7856,
7857, 7858, 7859, 7860, 7861, 7862, 7863, 7865, 7864, 7866, 7867,
7868, 7869, 7870, 7871, 7872, 7873, 7874, 7875, 7876, 7877, 7880,
7881, 7878, 7879, 7883, 7882, 7884, 7885, 7888, 7886, 7887, 7889,
7891, 7890, 7892, 7893, 7894, 7895, 7896, 7898, 7897, 7899, 7901,
7900, 7902, 7903, 7904, 7905, 7906, 7907, 7908, 7909, 7910, 7911,
7913, 7912, 7914, 7915, 7916, 7917, 7918, 7919, 7920, 7921, 7923,
7922, 7924, 7925, 7926, 7929, 7927, 7928, 7930, 7933, 7934, 7931,
7932, 7937, 7938, 7935, 7936, 7940, 7939, 7943, 7944, 7941, 7942,
7947, 7948, 7945, 7946, 7950, 7949, 7953, 7954, 7951, 7952, 7957,
7958, 7955, 7956, 7959, 7962, 7963, 7960, 7961, 7964, 7965, 7966,
7968, 7967, 7971, 7972, 7969, 7970, 7973, 7974, 7975, 7976, 7977,
7978, 7979, 7980, 7982, 7981, 7983, 7984, 7985, 7986, 7987, 7988,
7989, 7990, 7991, 7992, 7993, 7994, 7997, 7998, 7995, 7996, 8000,
7999, 8001, 8002, 8005, 8003, 8004, 8006, 8008, 8007, 8009, 8010,
8011, 8012, 8013, 8015, 8014, 8016, 8018, 8017, 8019, 8020, 8021,
8022, 8023, 8024, 8025, 8026, 8027, 8028, 8030, 8029, 8031, 8032,
8033, 8034, 8035, 8036, 8037, 8038, 8040, 8039, 8041, 8042, 8043,
8046, 8044, 8045, 8047, 8049, 8048, 8050, 8051, 8052, 8053, 8054,
8055, 8056, 8057, 8058, 8059, 8060, 8061, 8062, 8063, 8064, 8065,
8066, 8067, 8070, 8071, 8068, 8069, 8073, 8072, 8075, 8074, 8076,
8077, 8078, 8080, 8079, 8081, 8082, 8083, 8084, 8085, 8086, 8088,
8087, 8089, 8091, 8090, 8092, 8093, 8094, 8095, 8096, 8097, 8099,
8098, 8100, 8101, 8103, 8102, 8104, 8105, 8106, 8107, 8108, 8109,
8110, 8111, 8113, 8112, 8114, 8115, 8116, 8119, 8117, 8118, 8120,
8121, 8122, 8123, 8124, 8125, 8126, 8127, 8128]).long()
mano_smplh_lhand_vertex_ids = torch.tensor([
1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992,
1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028,
2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040,
2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049, 2050, 2051, 2052,
2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064,
2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2076,
2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088,
2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100,
2101, 2107, 2111, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121,
2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2131, 2132, 2133,
2134, 2135, 2136, 2137, 2138, 2139, 2140, 2141, 2142, 2143, 2144, 2145,
2146, 2149, 2150, 2151, 2152, 2153, 2154, 2155, 2156, 2157, 2158, 2159,
2160, 2161, 2162, 2163, 2164, 2165, 2166, 2167, 2168, 2169, 2170, 2171,
2172, 2173, 2174, 2175, 2176, 2177, 2178, 2179, 2180, 2181, 2182, 2183,
2184, 2185, 2186, 2187, 2188, 2189, 2190, 2191, 2192, 2193, 2194, 2195,
2196, 2197, 2198, 2199, 2200, 2201, 2202, 2203, 2204, 2205, 2207, 2209,
2210, 2211, 2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221,
2222, 2223, 2224, 2225, 2226, 2227, 2228, 2229, 2231, 2232, 2233, 2234,
2236, 2237, 2238, 2239, 2240, 2245, 2246, 2247, 2248, 2249, 2250, 2251,
2252, 2253, 2254, 2255, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263,
2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271, 2272, 2273, 2274, 2275,
2276, 2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2285, 2287, 2288,
2289, 2290, 2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299, 2300,
2301, 2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312,
2313, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324,
2325, 2326, 2327, 2328, 2329, 2330, 2331, 2332, 2333, 2334, 2335, 2336,
2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344, 2345, 2346, 2347, 2348,
2349, 2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360,
2361, 2362, 2363, 2364, 2365, 2366, 2367, 2368, 2369, 2370, 2371, 2372,
2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2384,
2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396,
2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2407, 2408,
2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420,
2421, 2422, 2423, 2424, 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2432,
2433, 2434, 2435, 2436, 2437, 2438, 2439, 2440, 2441, 2442, 2443, 2444,
2445, 2446, 2447, 2448, 2449, 2450, 2451, 2452, 2453, 2454, 2455, 2456,
2457, 2458, 2459, 2460, 2461, 2462, 2463, 2464, 2465, 2466, 2467, 2468,
2469, 2470, 2471, 2472, 2473, 2474, 2475, 2476, 2477, 2478, 2479, 2480,
2481, 2482, 2483, 2484, 2485, 2486, 2487, 2488, 2489, 2490, 2491, 2492,
2493, 2494, 2495, 2496, 2497, 2498, 2499, 2500, 2501, 2502, 2503, 2504,
2505, 2506, 2507, 2508, 2509, 2510, 2511, 2512, 2513, 2514, 2515, 2516,
2517, 2518, 2519, 2520, 2521, 2522, 2523, 2524, 2525, 2526, 2527, 2528,
2529, 2530, 2531, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540,
2541, 2542, 2543, 2544, 2545, 2546, 2547, 2548, 2549, 2550, 2551, 2552,
2553, 2554, 2555, 2556, 2557, 2558, 2559, 2560, 2561, 2562, 2563, 2564,
2565, 2566, 2567, 2568, 2569, 2570, 2571, 2572, 2573, 2574, 2575, 2576,
2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, 2587, 2588,
2589, 2590, 2591, 2592, 2593, 2594, 2595, 2596, 2597, 2598, 2599, 2600,
2601, 2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612,
2613, 2614, 2615, 2616, 2617, 2618, 2619, 2620, 2621, 2622, 2623, 2624,
2625, 2626, 2627, 2628, 2629, 2630, 2631, 2632, 2633, 2634, 2635, 2636,
2637, 2638, 2639, 2640, 2641, 2642, 2643, 2644, 2645, 2646, 2647, 2648,
2649, 2650, 2651, 2652, 2653, 2654, 2655, 2656, 2657, 2658, 2659, 2660,
2661, 2662, 2663, 2664, 2665, 2666, 2667, 2668, 2669, 2670, 2671, 2672,
2673, 2674, 2675, 2676, 2677, 2678, 2679, 2680, 2681, 2682, 2683, 2684,
2685, 2686, 2687, 2688, 2689, 2690, 2691, 2692, 2693, 2694, 2695, 2696,
2697, 2698, 2699, 2700, 2701, 2702, 2703, 2704, 2705, 2706, 2707, 2708,
2709, 2710, 2711, 2712, 2713, 2714, 2715, 2716, 2717, 2718, 2719, 2720,
2721, 2722, 2723, 2724, 2725, 2726, 2727, 2728, 2729, 2730, 2731, 2732,
2733, 2734, 2735, 2736, 2737, 2738, 2739, 2740, 2741, 2742, 2743, 2744,
2745, 2746, 2747, 2748, 2749, 2750, 2751, 2752, 2753, 2754, 2755, 2756,
2757, 2758, 2759, 2760, 2761, 2762, 2763, 2764, 2765, 2766, 2767, 2768,
2769, 2770, 2771, 2772, 2773, 2774, 2775, 2776, 2777, 2778])
mano_smplh_rhand_vertex_ids = torch.tensor([
5442, 5443, 5444, 5445, 5446, 5447, 5448, 5449, 5450, 5451, 5452, 5453,
5454, 5455, 5456, 5457, 5458, 5459, 5460, 5461, 5462, 5463, 5464, 5465,
5466, 5467, 5468, 5469, 5470, 5471, 5472, 5473, 5474, 5475, 5476, 5477,
5478, 5479, 5480, 5481, 5482, 5483, 5484, 5485, 5486, 5487, 5488, 5489,
5490, 5491, 5492, 5493, 5494, 5495, 5496, 5497, 5498, 5499, 5500, 5501,
5502, 5503, 5504, 5505, 5506, 5507, 5508, 5509, 5510, 5511, 5512, 5513,
5514, 5515, 5516, 5517, 5518, 5519, 5520, 5521, 5522, 5523, 5524, 5525,
5526, 5527, 5528, 5529, 5530, 5531, 5532, 5533, 5534, 5535, 5536, 5537,
5538, 5539, 5540, 5541, 5542, 5543, 5544, 5545, 5546, 5547, 5548, 5549,
5550, 5551, 5552, 5553, 5554, 5555, 5556, 5557, 5558, 5559, 5560, 5561,
5562, 5569, 5571, 5574, 5575, 5576, 5577, 5578, 5579, 5580, 5581, 5582,
5583, 5584, 5585, 5586, 5587, 5588, 5589, 5590, 5591, 5592, 5593, 5594,
5595, 5596, 5597, 5598, 5599, 5600, 5601, 5602, 5603, 5604, 5605, 5606,
5607, 5610, 5611, 5612, 5613, 5614, 5615, 5616, 5617, 5618, 5619, 5620,
5621, 5622, 5623, 5624, 5625, 5626, 5627, 5628, 5629, 5630, 5631, 5632,
5633, 5634, 5635, 5636, 5637, 5638, 5639, 5640, 5641, 5642, 5643, 5644,
5645, 5646, 5647, 5648, 5649, 5650, 5651, 5652, 5653, 5654, 5655, 5656,
5657, 5658, 5659, 5660, 5661, 5662, 5663, 5664, 5665, 5666, 5667, 5670,
5671, 5672, 5673, 5674, 5675, 5676, 5677, 5678, 5679, 5680, 5681, 5682,
5683, 5684, 5685, 5686, 5687, 5688, 5689, 5690, 5692, 5693, 5694, 5695,
5697, 5698, 5699, 5700, 5701, 5706, 5707, 5708, 5709, 5710, 5711, 5712,
5713, 5714, 5715, 5716, 5717, 5718, 5719, 5720, 5721, 5722, 5723, 5724,
5725, 5726, 5727, 5728, 5729, 5730, 5731, 5732, 5733, 5734, 5735, 5736,
5737, 5738, 5739, 5740, 5741, 5742, 5743, 5744, 5745, 5746, 5748, 5749,
5750, 5751, 5752, 5753, 5754, 5755, 5756, 5757, 5758, 5759, 5760, 5761,
5762, 5763, 5764, 5765, 5766, 5767, 5768, 5769, 5770, 5771, 5772, 5773,
5774, 5775, 5776, 5777, 5778, 5779, 5780, 5781, 5782, 5783, 5784, 5785,
5786, 5787, 5788, 5789, 5790, 5791, 5792, 5793, 5794, 5795, 5796, 5797,
5798, 5799, 5800, 5801, 5802, 5803, 5804, 5805, 5806, 5807, 5808, 5809,
5810, 5811, 5812, 5813, 5814, 5815, 5816, 5817, 5818, 5819, 5820, 5821,
5822, 5823, 5824, 5825, 5826, 5827, 5828, 5829, 5830, 5831, 5832, 5833,
5834, 5835, 5836, 5837, 5838, 5839, 5840, 5841, 5842, 5843, 5844, 5845,
5846, 5847, 5848, 5849, 5850, 5851, 5852, 5853, 5854, 5855, 5856, 5857,
5858, 5859, 5860, 5861, 5862, 5863, 5864, 5865, 5866, 5867, 5868, 5869,
5870, 5871, 5872, 5873, 5874, 5875, 5876, 5877, 5878, 5879, 5880, 5881,
5882, 5883, 5884, 5885, 5886, 5887, 5888, 5889, 5890, 5891, 5892, 5893,
5894, 5895, 5896, 5897, 5898, 5899, 5900, 5901, 5902, 5903, 5904, 5905,
5906, 5907, 5908, 5909, 5910, 5911, 5912, 5913, 5914, 5915, 5916, 5917,
5918, 5919, 5920, 5921, 5922, 5923, 5924, 5925, 5926, 5927, 5928, 5929,
5930, 5931, 5932, 5933, 5934, 5935, 5936, 5937, 5938, 5939, 5940, 5941,
5942, 5943, 5944, 5945, 5946, 5947, 5948, 5949, 5950, 5951, 5952, 5953,
5954, 5955, 5956, 5957, 5958, 5959, 5960, 5961, 5962, 5963, 5964, 5965,
5966, 5967, 5968, 5969, 5970, 5971, 5972, 5973, 5974, 5975, 5976, 5977,
5978, 5979, 5980, 5981, 5982, 5983, 5984, 5985, 5986, 5987, 5988, 5989,
5990, 5991, 5992, 5993, 5994, 5995, 5996, 5997, 5998, 5999, 6000, 6001,
6002, 6003, 6004, 6005, 6006, 6007, 6008, 6009, 6010, 6011, 6012, 6013,
6014, 6015, 6016, 6017, 6018, 6019, 6020, 6021, 6022, 6023, 6024, 6025,
6026, 6027, 6028, 6029, 6030, 6031, 6032, 6033, 6034, 6035, 6036, 6037,
6038, 6039, 6040, 6041, 6042, 6043, 6044, 6045, 6046, 6047, 6048, 6049,
6050, 6051, 6052, 6053, 6054, 6055, 6056, 6057, 6058, 6059, 6060, 6061,
6062, 6063, 6064, 6065, 6066, 6067, 6068, 6069, 6070, 6071, 6072, 6073,
6074, 6075, 6076, 6077, 6078, 6079, 6080, 6081, 6082, 6083, 6084, 6085,
6086, 6087, 6088, 6089, 6090, 6091, 6092, 6093, 6094, 6095, 6096, 6097,
6098, 6099, 6100, 6101, 6102, 6103, 6104, 6105, 6106, 6107, 6108, 6109,
6110, 6111, 6112, 6113, 6114, 6115, 6116, 6117, 6118, 6119, 6120, 6121,
6122, 6123, 6124, 6125, 6126, 6127, 6128, 6129, 6130, 6131, 6132, 6133,
6134, 6135, 6136, 6137, 6138, 6139, 6140, 6141, 6142, 6143, 6144, 6145,
6146, 6147, 6148, 6149, 6150, 6151, 6152, 6153, 6154, 6155, 6156, 6157,
6158, 6159, 6160, 6161, 6162, 6163, 6164, 6165, 6166, 6167, 6168, 6169,
6170, 6171, 6172, 6173, 6174, 6175, 6176, 6177, 6178, 6179, 6180, 6181,
6182, 6183, 6184, 6185, 6186, 6187, 6188, 6189, 6190, 6191, 6192, 6193,
6194, 6195, 6196, 6197, 6198, 6199, 6200, 6201, 6202, 6203, 6204, 6205,
6206, 6207, 6208, 6209, 6210, 6211, 6212, 6213, 6214, 6215, 6216, 6217,
6218, 6219, 6220, 6221, 6222, 6223, 6224, 6225, 6226, 6227, 6228, 6229,
6230, 6231, 6232, 6233, 6234, 6235, 6236, 6237, 6238, 6239])
def split2face_feet_hand_parts(ffh_joints):
# ['nose', 'reye', 'leye', 'rear', 'lear']
face_joints = ffh_joints[:, :5]
# ['LBigToe', 'LSmallToe', 'LHeel', 'RBigToe', 'RSmallToe', 'RHeel']
feet_joints = ffh_joints[:, 5:5+6]
# 42 hand joints in InterHand2.6M's order
hand_joints = ffh_joints[:, 11:][:, smplx42tohand42]
return face_joints, feet_joints, hand_joints
def to_tensor(
array: Union[Array, Tensor], dtype=torch.float32
) -> Tensor:
if torch.is_tensor(array):
return array
else:
return torch.tensor(array, dtype=dtype)
class VertexJointSelector(nn.Module):
def __init__(self, vertex_ids=None, **kwargs):
super(VertexJointSelector, self).__init__()
face_keyp_idxs = np.array([
vertex_ids['nose'],
vertex_ids['reye'],
vertex_ids['leye'],
vertex_ids['rear'],
vertex_ids['lear']], dtype=np.int64)
feet_keyp_idxs = np.array([vertex_ids['LBigToe'],
vertex_ids['LSmallToe'],
vertex_ids['LHeel'],
vertex_ids['RBigToe'],
vertex_ids['RSmallToe'],
vertex_ids['RHeel']], dtype=np.int32)
self.tip_names = ['thumb', 'index', 'middle', 'ring', 'pinky']
tips_idxs = []
for hand_id in ['l', 'r']:
for tip_name in self.tip_names:
tips_idxs.append(vertex_ids[hand_id + tip_name])
extra_joints_idxs = np.concatenate([face_keyp_idxs, feet_keyp_idxs, tips_idxs])
self.register_buffer('extra_joints_idxs',
to_tensor(extra_joints_idxs, dtype=torch.long))
def forward(self, vertices):
extra_joints = torch.index_select(vertices, 1, self.extra_joints_idxs.to(torch.long))
return extra_joints