import torch import numpy as np import utils.training_utils as utils class EDM(): """ Definition of most of the diffusion parameterization, following ( Karras et al., "Elucidating...", 2022) """ def __init__(self, args): """ Args: args (dictionary): hydra arguments sigma_data (float): """ self.args=args self.sigma_min = args.diff_params.sigma_min self.sigma_max =args.diff_params.sigma_max self.P_mean=args.diff_params.P_mean self.P_std=args.diff_params.P_std self.ro=args.diff_params.ro self.ro_train=args.diff_params.ro_train self.sigma_data=args.diff_params.sigma_data #depends on the training data!! precalculated variance of the dataset #parameters stochastic sampling self.Schurn=args.diff_params.Schurn self.Stmin=args.diff_params.Stmin self.Stmax=args.diff_params.Stmax self.Snoise=args.diff_params.Snoise #perceptual filter if self.args.diff_params.aweighting.use_aweighting: self.AW=utils.FIRFilter(filter_type="aw", fs=args.exp.sample_rate, ntaps=self.args.diff_params.aweighting.ntaps) def get_gamma(self, t): """ Get the parameter gamma that defines the stochasticity of the sampler Args t (Tensor): shape: (N_steps, ) Tensor of timesteps, from which we will compute gamma """ N=t.shape[0] gamma=torch.zeros(t.shape).to(t.device) #If desired, only apply stochasticity between a certain range of noises Stmin is 0 by default and Stmax is a huge number by default. (Unless these parameters are specified, this does nothing) indexes=torch.logical_and(t>self.Stmin , t