commitb608558b9eMerge:ad29b02dd205abAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 24 17:56:47 2024 +0300 Merge branch 'develop' of https://github.com/kijai/ComfyUI-LivePortraitKJ into develop commitad29b02bc1Author: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 24 17:56:46 2024 +0300 update workflows commitdd205ab4a4Author: Jukka Seppänen <40791699+kijai@users.noreply.github.com> Date: Wed Jul 24 17:54:47 2024 +0300 Update readme.md commitba0886a905Author: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 24 16:09:26 2024 +0300 fix running without insightface installed commit068ab2c280Author: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 24 03:57:59 2024 +0300 Add MediaPipe as alternative face detector commit6261f4e474Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 23 22:58:33 2024 +0300 cleanup, memory fixes commit46675b2016Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 23 21:13:15 2024 +0300 update workflows, cleanup commit806263dd25Author: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 22 20:39:43 2024 +0300 cleanup, fixes commitac89dc1e2fAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 22 19:19:46 2024 +0300 fix no face frame skip commit27d745b53eAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 22 17:52:34 2024 +0300 add other examples commit052762578cAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 22 17:45:49 2024 +0300 Update readme.md commite825c51c87Author: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 22 16:21:35 2024 +0300 separate composition to it's own node commit177b324fcdAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 22 01:02:56 2024 +0300 Update live_portrait_pipeline.py commit5c03bd8439Author: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 22 00:57:44 2024 +0300 MPS fallbacks commitef5ff7075fAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Sun Jul 21 20:35:33 2024 +0300 Update requirements.txt commit92fad03ee5Author: kijai <40791699+kijai@users.noreply.github.com> Date: Sun Jul 21 20:20:46 2024 +0300 restructure a bit for more caching commit4cefac79b8Author: kijai <40791699+kijai@users.noreply.github.com> Date: Sun Jul 21 19:42:22 2024 +0300 Add single_frame mode for webcam commit5e3c92d55cAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Sun Jul 21 19:20:52 2024 +0300 restructuring, video smoothing commitcc0501a2dbAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Sun Jul 21 13:21:26 2024 +0300 flag_relative_rotation_only commit3dc822fd2fAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Sat Jul 20 20:24:15 2024 +0300 to use GPU for pasteback commit697b9a78e6Author: kijai <40791699+kijai@users.noreply.github.com> Date: Sat Jul 20 17:39:44 2024 +0300 Restructure nodes, skip frames with no face detect commit2a7bd6116fAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 10 17:14:43 2024 +0300 Update nodes.py commita7d09f5d49Author: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 10 16:33:31 2024 +0300 example workflow commit8e85d5b96dAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 10 16:06:01 2024 +0300 some optimizations commit30989a9d37Author: kijai <40791699+kijai@users.noreply.github.com> Date: Wed Jul 10 01:17:10 2024 +0300 Update nodes.py commiteecf645603Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 23:02:47 2024 +0300 rotate option for cropper commit1b080706dfAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 22:46:51 2024 +0300 Update nodes.py commit336f3f7c23Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 22:19:56 2024 +0300 add cut method commitf27e1cca13Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 22:11:19 2024 +0300 remove nearest option commit86e91a6e9dAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 22:06:56 2024 +0300 better error for retargeting commit92529f7ca8Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 21:59:32 2024 +0300 cleanup commitc0959056aeAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 21:49:54 2024 +0300 eye/lip retargeting fixes commit2e40fe3820Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 21:23:10 2024 +0300 Update live_portrait_pipeline.py commit0a5e187637Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 21:15:17 2024 +0300 keep Cropper in memory commit4e19dbd6d1Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 20:19:53 2024 +0300 Do video cropping on the cropped node too commit9c190804a7Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 19:02:27 2024 +0300 big cleanup commitd9ca40e1d6Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 15:08:17 2024 +0300 logging commitb68cf8788cAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 14:35:51 2024 +0300 fix warning commite702b26895Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 14:31:22 2024 +0300 Update cropper.py commitc21705edb5Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 14:25:39 2024 +0300 Don't draw keypoints for every frame by default commita284bb52b2Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 14:04:56 2024 +0300 Bring back mismatch_method selection commit9884aac18aAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 14:00:43 2024 +0300 Fix eye/lip retargeting commitf8aada81dbAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 13:00:03 2024 +0300 face_index selection commit6735771664Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 11:51:38 2024 +0300 tqdm progress bars commit857ddbc6d7Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 02:54:27 2024 +0300 skip autocast if not needed for mps commita6edcda97dAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 01:37:05 2024 +0300 output masks commitca01d706d0Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 00:57:13 2024 +0300 custom mask support commit0dc9a8a695Merge:ee7d5b4ba6b3f5Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 00:13:07 2024 +0300 Merge branch 'add_video_source' into develop commitba6b3f5f68Author: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 23:09:56 2024 +0200 bring KJ edits commitee7d5b4241Author: kijai <40791699+kijai@users.noreply.github.com> Date: Tue Jul 9 00:08:10 2024 +0300 revert this for compatibility commit03df9f35cdMerge:ec6b5c88509d9aAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 8 23:55:22 2024 +0300 Merge branch 'add_video_source' into develop commitec6b5c8c85Merge:6f9dba7e724da1Author: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 8 23:52:58 2024 +0300 calc_combined_eye_ratio commit8509d9a551Author: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 22:52:48 2024 +0200 remove unused imports commite724da1161Author: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 21:38:27 2024 +0200 fix relative mode use R_d_0 instead of source commit68d0ddf72aAuthor: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 21:22:50 2024 +0200 remove reference frame attempt also use batches for driving when either retargetting is enabled commit6f9dba7777Author: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 8 20:50:44 2024 +0300 fixes commit811ca557fbAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 8 20:31:00 2024 +0300 more commit6d790bdcc3Merge:ef8b426eb5fddfAuthor: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 8 20:30:35 2024 +0300 Merge branch 'add_video_source' into develop commitef8b4263b4Author: kijai <40791699+kijai@users.noreply.github.com> Date: Mon Jul 8 20:21:45 2024 +0300 separating functions to nodes commiteb5fddf4deAuthor: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 19:10:53 2024 +0200 fix issues from merge commit9c7db3c59aMerge:bf3410c1f28e12Author: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 19:09:02 2024 +0200 Merge branch 'main' into add_video_source commitbf3410cd0dAuthor: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 19:04:42 2024 +0200 trying reference frame commit24c65627dbAuthor: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 19:03:28 2024 +0200 local updates before merging main commit72bb6910e9Author: Mel Massadian <mel@melmassadian.com> Date: Mon Jul 8 16:48:15 2024 +0200 initial too much diff due to formatting
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
# coding: utf-8
|
|
|
|
"""
|
|
utility functions and classes to handle feature extraction and model loading
|
|
"""
|
|
|
|
import os.path as osp
|
|
import cv2
|
|
import torch
|
|
from collections import OrderedDict
|
|
|
|
def squeeze_tensor_to_numpy(tensor):
|
|
out = tensor.data.squeeze(0).cpu().numpy()
|
|
return out
|
|
|
|
def dct2cuda(dct: dict, device_id: int):
|
|
for key in dct:
|
|
dct[key] = torch.tensor(dct[key]).to(device_id)
|
|
return dct
|
|
|
|
|
|
def concat_feat(kp_source: torch.Tensor, kp_driving: torch.Tensor) -> torch.Tensor:
|
|
"""
|
|
kp_source: (bs, k, 3)
|
|
kp_driving: (bs, k, 3)
|
|
Return: (bs, 2k*3)
|
|
"""
|
|
bs_src = kp_source.shape[0]
|
|
bs_dri = kp_driving.shape[0]
|
|
assert bs_src == bs_dri, 'batch size must be equal'
|
|
|
|
feat = torch.cat([kp_source.view(bs_src, -1), kp_driving.view(bs_dri, -1)], dim=1)
|
|
return feat
|
|
|
|
|
|
def remove_ddp_dumplicate_key(state_dict):
|
|
state_dict_new = OrderedDict()
|
|
for key in state_dict.keys():
|
|
state_dict_new[key.replace('module.', '')] = state_dict[key]
|
|
return state_dict_new
|
|
|
|
# get coefficients of Eqn. 7
|
|
def calculate_transformation(config, s_kp_info, t_0_kp_info, t_i_kp_info, R_s, R_t_0, R_t_i):
|
|
if config.relative:
|
|
new_rotation = (R_t_i @ R_t_0.permute(0, 2, 1)) @ R_s
|
|
new_expression = s_kp_info['exp'] + (t_i_kp_info['exp'] - t_0_kp_info['exp'])
|
|
else:
|
|
new_rotation = R_t_i
|
|
new_expression = t_i_kp_info['exp']
|
|
new_translation = s_kp_info['t'] + (t_i_kp_info['t'] - t_0_kp_info['t'])
|
|
new_translation[..., 2].fill_(0) # Keep the z-axis unchanged
|
|
new_scale = s_kp_info['scale'] * (t_i_kp_info['scale'] / t_0_kp_info['scale'])
|
|
return new_rotation, new_expression, new_translation, new_scale
|
|
|
|
|
|
def resize_to_limit(img, max_dim=1280, n=2):
|
|
h, w = img.shape[:2]
|
|
if max_dim > 0 and max(h, w) > max_dim:
|
|
if h > w:
|
|
new_h = max_dim
|
|
new_w = int(w * (max_dim / h))
|
|
else:
|
|
new_w = max_dim
|
|
new_h = int(h * (max_dim / w))
|
|
img = cv2.resize(img, (new_w, new_h))
|
|
n = max(n, 1)
|
|
new_h = img.shape[0] - (img.shape[0] % n)
|
|
new_w = img.shape[1] - (img.shape[1] % n)
|
|
if new_h == 0 or new_w == 0:
|
|
return img
|
|
if new_h != img.shape[0] or new_w != img.shape[1]:
|
|
img = img[:new_h, :new_w]
|
|
return img
|