Spaces:
Runtime error
Runtime error
Download sgm/modules/diffusionmodules/loss_weighting.py from yslan/LN3Diff_I23D: direct link, hf CLI and curl.
- Browser
- Download file 855 Bytes
-
https://huggingface.co/spaces/yslan/LN3Diff_I23D/resolve/main/sgm/modules/diffusionmodules/loss_weighting.py
- Command line
-
hf download hf://spaces/yslan/LN3Diff_I23D/sgm/modules/diffusionmodules/loss_weighting.py
-
curl -L -o loss_weighting.py https://huggingface.co/spaces/yslan/LN3Diff_I23D/resolve/main/sgm/modules/diffusionmodules/loss_weighting.py
855 Bytes
| from abc import ABC, abstractmethod | |
| import torch | |
| class DiffusionLossWeighting(ABC): | |
| def __call__(self, sigma: torch.Tensor) -> torch.Tensor: | |
| pass | |
| class UnitWeighting(DiffusionLossWeighting): | |
| def __call__(self, sigma: torch.Tensor) -> torch.Tensor: | |
| return torch.ones_like(sigma, device=sigma.device) | |
| class EDMWeighting(DiffusionLossWeighting): | |
| def __init__(self, sigma_data: float = 0.5): | |
| self.sigma_data = sigma_data | |
| def __call__(self, sigma: torch.Tensor) -> torch.Tensor: | |
| return (sigma**2 + self.sigma_data**2) / (sigma * self.sigma_data) ** 2 | |
| class VWeighting(EDMWeighting): | |
| def __init__(self): | |
| super().__init__(sigma_data=1.0) | |
| class EpsWeighting(DiffusionLossWeighting): | |
| def __call__(self, sigma: torch.Tensor) -> torch.Tensor: | |
| return sigma**-2.0 | |