MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / get_emo_feature

Function get_emo_feature

infer.py:349–378  ·  view source on GitHub ↗
(video_path, face_aligner, pd_fpg_motion, device=torch.device("cuda"))

Source from the content-addressed store, hash-verified

347 return 0
348
349def get_emo_feature(video_path, face_aligner, pd_fpg_motion, device=torch.device("cuda")):
350 pd_fpg_motion = pd_fpg_motion.to(device)
351 cap = cv2.VideoCapture(video_path)
352 fps = cap.get(cv2.CAP_PROP_FPS)
353 frame_list = []
354 ret, frame = cap.read()
355 while ret:
356 resized_frame = frame
357 frame_list.append(resized_frame.copy())
358 ret, frame = cap.read()
359 cap.release()
360 num_frames = len(frame_list)
361 num_frames = find_replacement(num_frames)
362 frame_list = frame_list[:num_frames]
363 landmark_list = det_landmarks(face_aligner, frame_list)[1]
364 emo_list = get_drive_expression_pd_fgc(pd_fpg_motion, frame_list, landmark_list, device)
365 emo_feat_list = []
366 head_emo_feat_list = []
367 for emo in emo_list:
368 headpose_emb = emo["headpose_emb"]
369 eye_embed = emo["eye_embed"]
370 emo_embed = emo["emo_embed"]
371 mouth_feat = emo["mouth_feat"]
372 emo_feat = torch.cat([eye_embed, emo_embed, mouth_feat], dim=1)
373 head_emo_feat = torch.cat([headpose_emb, emo_feat], dim=1)
374 emo_feat_list.append(emo_feat)
375 head_emo_feat_list.append(head_emo_feat)
376 emo_feat_all = torch.cat(emo_feat_list, dim=0)
377 head_emo_feat_all = torch.cat(head_emo_feat_list, dim=0)
378 return emo_feat_all, head_emo_feat_all, fps, num_frames
379
380with torch.no_grad():
381 image_start = clip_image = Image.open(validation_image_start).convert("RGB")

Callers 1

infer.pyFile · 0.70

Calls 3

det_landmarksFunction · 0.90
find_replacementFunction · 0.70

Tested by

no test coverage detected