Instructions to use urikxx/EchoMimic with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use urikxx/EchoMimic with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("urikxx/EchoMimic", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Download src/utils/step_func.py from urikxx/EchoMimic: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/urikxx/EchoMimic/resolve/main/src/utils/step_func.py
- Command line
-
hf download hf://urikxx/EchoMimic/src/utils/step_func.py
-
curl -L -o step_func.py https://huggingface.co/urikxx/EchoMimic/resolve/main/src/utils/step_func.py
1.59 kB
| import torch | |
| import numpy as np | |
| def get_alpha(alphas_cumprod, timestep): | |
| timestep_lt_zero_mask = torch.lt(timestep, 0).to(alphas_cumprod.dtype) | |
| normal_alpha = alphas_cumprod[torch.clip(timestep, 0)] | |
| one_alpha = torch.ones_like(normal_alpha).to(normal_alpha.dtype).to(normal_alpha.dtype) | |
| return normal_alpha * (1 - timestep_lt_zero_mask) + one_alpha * timestep_lt_zero_mask | |
| def psuedo_velocity_wrt_noisy_and_timestep(noisy_images, noisy_images_pre, alphas_cumprod, timestep, timestep_prev): | |
| alpha_prod_t = get_alpha(alphas_cumprod, timestep).view(-1, 1, 1, 1, 1).detach() | |
| beta_prod_t = 1 - alpha_prod_t | |
| alpha_prod_t_prev = get_alpha(alphas_cumprod, timestep_prev).view(-1, 1, 1, 1, 1).detach() | |
| beta_prod_t_prev = 1 - alpha_prod_t_prev | |
| a_s = (alpha_prod_t_prev ** (0.5)).to(noisy_images.dtype) | |
| a_t = (alpha_prod_t ** (0.5)).to(noisy_images.dtype) | |
| b_s = (beta_prod_t_prev ** (0.5)).to(noisy_images.dtype) | |
| b_t = (beta_prod_t ** (0.5)).to(noisy_images.dtype) | |
| psuedo_velocity = (noisy_images_pre - ( | |
| a_s * a_t + b_s * b_t | |
| ) * noisy_images) / ( | |
| b_s * a_t - a_s * b_t | |
| ) | |
| return psuedo_velocity | |
| def origin_by_velocity_and_sample(velocity, noisy_images, alphas_cumprod, timestep): | |
| alpha_prod_t = get_alpha(alphas_cumprod, timestep).view(-1, 1, 1, 1, 1).detach() | |
| beta_prod_t = 1 - alpha_prod_t | |
| a_t = (alpha_prod_t ** (0.5)).to(noisy_images.dtype) | |
| b_t = (beta_prod_t ** (0.5)).to(noisy_images.dtype) | |
| pred_original_sample = a_t * noisy_images - b_t * velocity | |
| return pred_original_sample | |