"""CPU/GPU smoke example. Synthetic inputs only; not an accuracy evaluation.""" import argparse import json from pathlib import Path import torch from bimanual_vae import load_pair, pack from hand_vae import aa_to_matrix def main(): parser = argparse.ArgumentParser() parser.add_argument("--device", default="cpu") args = parser.parse_args() torch.manual_seed(0) vae, _ = load_pair(str(Path(__file__).resolve().parent / "joint_mix40.pt"), args.device) # Synthetic full MANO local axis angles, left hand first, right hand second. local_aa = torch.zeros(2, 2, 15, 3, device=args.device, requires_grad=True) root_aa = torch.zeros(2, 2, 3, device=args.device, requires_grad=True) wrist = torch.tensor([[[0., 0., .5], [.2, 0., .5]], [[0., 0., .6], [.2, .02, .6]]], device=args.device, requires_grad=True) local_rot, root_rot = aa_to_matrix(local_aa), aa_to_matrix(root_aa) energy = vae.energy(local_rot, root_rot, wrist) loss = 0.1 * energy.mean() loss.backward() for x in (local_aa, root_aa, wrist): assert x.grad is not None and torch.isfinite(x.grad).all() assert torch.isfinite(energy).all() assert all(not p.requires_grad and p.grad is None for p in vae.parameters()) with torch.no_grad(): rot, pos = pack(local_rot, root_rot, wrist) rot_rec, pos_rec, mu, logvar = vae(rot, pos) assert rot_rec.shape == (2, 31, 3, 3) assert pos_rec.shape == (2, 3) assert mu.shape == logvar.shape == (2, 40) print(json.dumps({"device": args.device, "torch": torch.__version__, "synthetic_inputs": True, "energy": energy.detach().cpu().tolist(), "rotation_shape": list(rot_rec.shape), "position_shape": list(pos_rec.shape), "latent_shape": list(mu.shape), "finite_input_gradients": True, "frozen_vae": True}, indent=2)) if __name__ == "__main__": main()