multimodalart HF staff commited on
Commit
bd169c9
1 Parent(s): add5fb2

Move tensors to gpu

Browse files
Files changed (1) hide show
  1. src/gradio_pipeline.py +7 -5
src/gradio_pipeline.py CHANGED
@@ -83,17 +83,19 @@ class GradioPipeline(LivePortraitPipeline):
83
  duration=5
84
  )
85
  else:
 
 
86
  # ∆_eyes,i = R_eyes(x_s; c_s,eyes, c_d,eyes,i)
87
  combined_eye_ratio_tensor = self.live_portrait_wrapper.calc_combined_eye_ratio([[input_eye_ratio]], self.source_lmk_user)
88
- eyes_delta = self.live_portrait_wrapper.retarget_eye(self.x_s_user, combined_eye_ratio_tensor)
89
  # ∆_lip,i = R_lip(x_s; c_s,lip, c_d,lip,i)
90
  combined_lip_ratio_tensor = self.live_portrait_wrapper.calc_combined_lip_ratio([[input_lip_ratio]], self.source_lmk_user)
91
- lip_delta = self.live_portrait_wrapper.retarget_lip(self.x_s_user, combined_lip_ratio_tensor)
92
- num_kp = self.x_s_user.shape[1]
93
  # default: use x_s
94
- x_d_new = self.x_s_user + eyes_delta.reshape(-1, num_kp, 3) + lip_delta.reshape(-1, num_kp, 3)
95
  # D(W(f_s; x_s, x′_d))
96
- out = self.live_portrait_wrapper.warp_decode(self.f_s_user, self.x_s_user, x_d_new)
97
  out = self.live_portrait_wrapper.parse_output(out['out'])[0]
98
  out_to_ori_blend = paste_back(out, self.crop_M_c2o, self.img_rgb, self.mask_ori)
99
  # gr.Info("Run successfully!", duration=2)
 
83
  duration=5
84
  )
85
  else:
86
+ x_s_user = self.x_s_user.to("cuda")
87
+ f_s_user = self.f_s_user.to("cuda")
88
  # ∆_eyes,i = R_eyes(x_s; c_s,eyes, c_d,eyes,i)
89
  combined_eye_ratio_tensor = self.live_portrait_wrapper.calc_combined_eye_ratio([[input_eye_ratio]], self.source_lmk_user)
90
+ eyes_delta = self.live_portrait_wrapper.retarget_eye(x_s_user, combined_eye_ratio_tensor)
91
  # ∆_lip,i = R_lip(x_s; c_s,lip, c_d,lip,i)
92
  combined_lip_ratio_tensor = self.live_portrait_wrapper.calc_combined_lip_ratio([[input_lip_ratio]], self.source_lmk_user)
93
+ lip_delta = self.live_portrait_wrapper.retarget_lip(x_s_user, combined_lip_ratio_tensor)
94
+ num_kp = x_s_user.shape[1]
95
  # default: use x_s
96
+ x_d_new = x_s_user + eyes_delta.reshape(-1, num_kp, 3) + lip_delta.reshape(-1, num_kp, 3)
97
  # D(W(f_s; x_s, x′_d))
98
+ out = self.live_portrait_wrapper.warp_decode(f_s_user, x_s_user, x_d_new)
99
  out = self.live_portrait_wrapper.parse_output(out['out'])[0]
100
  out_to_ori_blend = paste_back(out, self.crop_M_c2o, self.img_rgb, self.mask_ori)
101
  # gr.Info("Run successfully!", duration=2)