Spaces:
Running on Zero
Running on Zero
Download diffusionGS/models/diffusion/__init__.py from CaiYuanhao/DiffusionGS-Object: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/CaiYuanhao/DiffusionGS-Object/resolve/main/diffusionGS/models/diffusion/__init__.py
- Command line
-
hf download hf://spaces/CaiYuanhao/DiffusionGS-Object/diffusionGS/models/diffusion/__init__.py
-
curl -L -o __init__.py https://huggingface.co/spaces/CaiYuanhao/DiffusionGS-Object/resolve/main/diffusionGS/models/diffusion/__init__.py
1.89 kB
| # Modified from OpenAI's diffusion repos | |
| # GLIDE: https://github.com/openai/glide-text2im/blob/main/glide_text2im/gaussian_diffusion.py | |
| # ADM: https://github.com/openai/guided-diffusion/blob/main/guided_diffusion | |
| # IDDPM: https://github.com/openai/improved-diffusion/blob/main/improved_diffusion/gaussian_diffusion.py | |
| from . import gaussian_diffusion as gd | |
| from .respace import SpacedDiffusion, space_timesteps | |
| ''' | |
| 输入一些参数,返回一个 SpacedDiffusion 对象 | |
| 这是一个比较泛化的类和框架, 里面调用的还是 gaussian_diffusion | |
| ''' | |
| def create_diffusion( | |
| timestep_respacing, | |
| noise_schedule="squaredcos_cap_v2", # consine 地安排 alpha 和 beta | |
| use_kl=False, | |
| sigma_small=False, | |
| predict_xstart=True, | |
| learn_sigma=False, | |
| rescale_learned_sigmas=False, | |
| diffusion_steps=1000 | |
| ): | |
| betas = gd.get_named_beta_schedule(noise_schedule, diffusion_steps) # schedule beta | |
| if use_kl: | |
| loss_type = gd.LossType.RESCALED_KL | |
| elif rescale_learned_sigmas: | |
| loss_type = gd.LossType.RESCALED_MSE | |
| else: | |
| loss_type = gd.LossType.MSE | |
| if timestep_respacing is None or timestep_respacing == "": # 控制调整 timestep 的策略 | |
| timestep_respacing = [diffusion_steps] | |
| return SpacedDiffusion( | |
| use_timesteps=space_timesteps(diffusion_steps, timestep_respacing), | |
| betas=betas, | |
| model_mean_type=( | |
| gd.ModelMeanType.EPSILON if not predict_xstart else gd.ModelMeanType.START_X | |
| ), | |
| model_var_type=( | |
| ( | |
| gd.ModelVarType.FIXED_LARGE | |
| if not sigma_small | |
| else gd.ModelVarType.FIXED_SMALL | |
| ) | |
| if not learn_sigma | |
| else gd.ModelVarType.LEARNED_RANGE | |
| ), | |
| loss_type=loss_type | |
| # rescale_timesteps=rescale_timesteps, | |
| ) | |