def run_tailornet(): gender = 'female' garment_class = 'pant' thetas, betas, gammas = get_single_frame_inputs(garment_class, gender) # # uncomment the line below to run inference on sequence data # thetas, betas, gammas = get_sequence_inputs(garment_class, gender) # load model tn_runner = get_tn_runner(gender=gender, garment_class=garment_class) smpl = SMPL4Garment(gender=gender) # make out directory if doesn't exist if not os.path.isdir(OUT_PATH): os.mkdir(OUT_PATH) # run inference for i, (theta, beta, gamma) in enumerate(zip(thetas, betas, gammas)): print(i, len(thetas)) # normalize y-rotation to make it front facing theta_normalized = normalize_y_rotation(theta) with torch.no_grad(): pred_verts_d = tn_runner.forward( thetas=torch.from_numpy(theta_normalized[None, :].astype(np.float32)).cuda(), betas=torch.from_numpy(beta[None, :].astype(np.float32)).cuda(), gammas=torch.from_numpy(gamma[None, :].astype(np.float32)).cuda(), )[0].cpu().numpy() # get garment from predicted displacements body, pred_gar = smpl.run(beta=beta, theta=theta, garment_class=garment_class, garment_d=pred_verts_d) pred_gar = remove_interpenetration_fast(pred_gar, body) # save body and predicted garment body.write_ply(os.path.join(OUT_PATH, "body_{:04d}.ply".format(i))) pred_gar.write_ply(os.path.join(OUT_PATH, "pred_gar_{:04d}.ply".format(i)))
def run_tailornet(): gender = 'male' garment_class = 'short-pant' garment_class_pairs = { 'shirt': [], 't-shirt': [], 'pant': ['shirt', 't-shirt'], 'short-pant': ['shirt', 't-shirt'], 'skirt': ['shirt', 't-shirt'] } thetas, betas, gammas = get_single_frame_inputs(garment_class, gender) # # uncomment the line below to run inference on sequence data # thetas, betas, gammas = get_sequence_inputs(garment_class, gender) # load model tn_runner = get_tn_runner(gender=gender, garment_class=garment_class) # from trainer.base_trainer import get_best_runner # tn_runner = get_best_runner("/BS/cpatel/work/data/learn_anim/tn_baseline/{}_{}/".format(garment_class, gender)) smpl = SMPL4Garment(gender=gender) # make out directory if doesn't exist if not os.path.isdir(OUT_PATH): os.mkdir(OUT_PATH) # run inference for i, (theta, beta, gamma) in enumerate(zip(thetas, betas, gammas)): print(i, len(thetas)) # normalize y-rotation to make it front facing theta_normalized = normalize_y_rotation(theta) with torch.no_grad(): pred_verts_d = tn_runner.forward( thetas=torch.from_numpy(theta_normalized[None, :].astype( np.float32)).cuda(), betas=torch.from_numpy(beta[None, :].astype( np.float32)).cuda(), gammas=torch.from_numpy(gamma[None, :].astype( np.float32)).cuda(), )[0].cpu().numpy() # get garment from predicted displacements body, pred_gar = smpl.run(beta=beta, theta=theta, garment_class=garment_class, garment_d=pred_verts_d) pred_gar = remove_interpenetration_fast(pred_gar, body) hv, hf, mapping = get_hres(pred_gar.v, pred_gar.f) pred_gar_hres = Mesh(hv, hf) for garment_class_pair in garment_class_pairs[garment_class]: gar_pair_hres = Mesh(filename=os.path.join( OUT_PATH, "bcnet_model_{}_gar_hres_{}_{:04d}.obj".format( BCNET_MODEL_NUM, garment_class_pair, i))) # print(len(body.v), body.f.min(), body.f.max()) # print(len(pred_gar_hres.v), pred_gar_hres.f.min(), pred_gar_hres.f.max()) # print(np.vstack((body.v, pred_gar_hres.v)).shape, np.min(pred_gar_hres.f + len(body.v)), np.max(pred_gar_hres.f + len(body.v))) # gar_pair_hres = remove_interpenetration_fast(gar_pair_hres, pred_gar_hres) for _ in range(3): gar_pair_hres = remove_interpenetration_fast( gar_pair_hres, Mesh(np.vstack((body.v, pred_gar_hres.v)), np.vstack((body.f, pred_gar_hres.f + len(body.v))))) gar_pair_hres.write_obj( os.path.join( OUT_PATH, "bcnet_model_{}_gar_hres_{}_inter_{}_{:04d}.obj".format( BCNET_MODEL_NUM, garment_class_pair, garment_class, i))) # save body and predicted garment body.write_obj( os.path.join(OUT_PATH, "bcnet_model_{}.obj".format(BCNET_MODEL_NUM))) pred_gar.write_obj( os.path.join( OUT_PATH, "bcnet_model_{}_gar_{}_{:04d}.obj".format( BCNET_MODEL_NUM, garment_class, i))) pred_gar_hres.write_obj( os.path.join( OUT_PATH, "bcnet_model_{}_gar_hres_{}_{:04d}.obj".format( BCNET_MODEL_NUM, garment_class, i)))