MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / main

Function main

motion_rep/convert_hmr_to_motion.py:104–159  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102
103
104def main():
105 parser = argparse.ArgumentParser(description='Convert HMR output to motion representation')
106 parser.add_argument('--input', '-i', type=str, required=True,
107 help='Path to input HMR .pt file')
108 parser.add_argument('--output', '-o', type=str, required=True,
109 help='Path to output .pt file')
110 parser.add_argument('--smplx_model_path', type=str,
111 default='./data/body_models/smplx',
112 help='Path to SMPLX model directory')
113 parser.add_argument('--device', type=str, default='cuda:0',
114 help='Compute device')
115 args = parser.parse_args()
116
117 # Check input exists
118 input_path = Path(args.input)
119 if not input_path.exists():
120 raise FileNotFoundError(f"Input file not found: {input_path}")
121
122 # Create output directory if needed
123 output_path = Path(args.output)
124 output_path.parent.mkdir(parents=True, exist_ok=True)
125
126 print(f"Loading HMR data from: {input_path}")
127 hmr_data = torch.load(input_path, map_location='cpu', weights_only=False)
128
129 # Validate required keys
130 required_keys = ['global_orient', 'body_pose', 'transl']
131 missing_keys = [k for k in required_keys if k not in hmr_data]
132 if missing_keys:
133 raise KeyError(f"Missing required keys in HMR data: {missing_keys}")
134
135 print(f"Input sequence length: {hmr_data['global_orient'].shape[0]} frames")
136
137 # Check optional camera params
138 if 'focal_length' in hmr_data and 'width' in hmr_data and 'height' in hmr_data:
139 print(f"Camera: focal={hmr_data['focal_length'][0]}, size={hmr_data['width'][0]}x{hmr_data['height'][0]}")
140 else:
141 print("Camera params not provided, using identity intrinsic (reprojection not available)")
142
143 # Load SMPLX model
144 seq_len = hmr_data['global_orient'].shape[0]
145 print(f"Loading SMPLX model from: {args.smplx_model_path}")
146 smplx_model = load_smplx_model(args.smplx_model_path, seq_len, args.device)
147
148 # Convert
149 print("Converting to motion representation...")
150 output = convert_hmr_to_motion(
151 hmr_data, smplx_model,
152 device=args.device
153 )
154
155 print(f"Output motion shape: {output['motion'].shape}")
156 print(f"Saving to: {output_path}")
157 torch.save(output, output_path)
158
159 print("Done!")
160
161

Callers 1

Calls 2

load_smplx_modelFunction · 0.85
convert_hmr_to_motionFunction · 0.85

Tested by

no test coverage detected