Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DiffTalk #20

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1f64c99
huanran: initial talking face api handling
huanranchen Jan 23, 2024
2805380
huanran: compatible changes
huanranchen Jan 23, 2024
21beb46
huanran: final commit
huanranchen Jan 23, 2024
e798a33
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
f2c1f3f
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
b5aa2f8
Add files via upload
FelixApril Jan 26, 2024
fb1447a
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
858f570
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
7e2ac54
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
9b42c69
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
3250ca1
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
a614114
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
59af553
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
bece7ef
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
86cc960
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
bbf9d1c
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
d7254b1
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
2ff0229
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
5f590e3
DiffTalkReadMe.MD
FelixApril Jan 26, 2024
ce4399f
huanran: add demos
huanranchen Jan 27, 2024
93a79b1
huanran: add demos
huanranchen Jan 27, 2024
677d9ab
huanran: add demos
huanranchen Jan 27, 2024
5a311d6
huanran: add demos
huanranchen Jan 27, 2024
158a45b
DiffTalkReadMe.MD
FelixApril Jan 29, 2024
1882504
DiffTalkReadMe.MD
FelixApril Jan 29, 2024
2400f5c
Create DiffTalkReadMe中文版.MD
FelixApril Jan 29, 2024
e73a912
DiffTalkReadMe中文版.MD
FelixApril Jan 29, 2024
22bfdef
DiffTalkReadMe中文版.MD
FelixApril Jan 29, 2024
cf182f5
Delete talkingface/model/image_driven_talkingface/DiffTalk/DiffTalkRe…
huanranchen Jan 29, 2024
a9df6bf
Create README.MD
huanranchen Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ log_tensorboard
results
temp
__pycache__
./idea/
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions .idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

162 changes: 162 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/talkingface-toolkit.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions checkpoints/DiffTalk/checkpoint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Obviously its impossible to push the checkpoint to github.

Please download the checkpoint from here: https://cloud.tsinghua.edu.cn/f/7eb11fc208144ed0ad20/?dl=1

Please do not modify the checkpoint name. Keep it as "model.ckpt".

52 changes: 52 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from talkingface.model.image_driven_talkingface.DiffTalk import get_difftalk_inference
import os
from talkingface.model.image_driven_talkingface.DiffTalk.ldm.models.diffusion.ddim_ldm_ref_inpaint import DDIMSampler
import torch
from einops import rearrange
from PIL import Image
import numpy as np

model = get_difftalk_inference()

save_dir = "./video/"
ddim_steps = 50
batch = None # load your data here
batchsize = 1
ddim_eta = 0 # Langevin
print(model)
sampler = DDIMSampler(model)
samples = []
samples_inpainting = []
xrec_img = []
z, c_audio, c_lip, c_ldm, c_mask, x, xrec, xc_audio, xc_lip = model.get_input(batch, 'image',
return_first_stage_outputs=True,
force_c_encode=True,
return_original_cond=True,
bs=batchsize)
shape = (z.shape[1], z.shape[2], z.shape[3])
N = x.shape[0]
c = {'audio': c_audio, 'lip': c_lip, 'ldm': c_ldm, 'mask_image': c_mask}

b, h, w = z.shape[0], z.shape[2], z.shape[3]
landmarks = batch["landmarks_all"]
landmarks = landmarks / 4
mask = batch["inference_mask"].to(model.device)
mask = mask[:, None, ...]
with model.ema_scope():
samples_ddim, _ = sampler.sample(ddim_steps, N, shape, c, x0=z[:N], verbose=False, eta=ddim_eta, mask=mask)

x_samples_ddim = model.decode_first_stage(samples_ddim)
x_samples_ddim = torch.clamp((x_samples_ddim + 1.0) / 2.0,
min=0.0, max=1.0)
samples_inpainting.append(x_samples_ddim)

# save images
samples_inpainting = torch.stack(samples_inpainting, 0)
samples_inpainting = rearrange(samples_inpainting, 'n b c h w -> (n b) c h w')
save_path = os.path.join(save_dir, '105_a105_mask_face')
if not os.path.exists(save_path):
os.mkdir(save_path)
for j in range(samples_inpainting.shape[0]):
samples_inpainting_img = 255. * rearrange(samples_inpainting[j], 'c h w -> h w c').cpu().numpy()
img = Image.fromarray(samples_inpainting_img.astype(np.uint8))
img.save(os.path.join(save_path, '{:04d}_{:04d}.jpg'.format(0, j)))
Loading