Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion lvdm/models/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def init_test(self,):
self.decodes = []
self.save_decode_samples = 2048

def init_from_ckpt(self, path, ignore_keys=list()):
def init_from_ckpt(self, path, ignore_keys=None):
if ignore_keys is None:
ignore_keys = []
sd = torch.load(path, map_location="cpu")
try:
self._cur_epoch = sd['epoch']
Expand Down
12 changes: 8 additions & 4 deletions lvdm/models/ddpm3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self,
beta_schedule="linear",
loss_type="l2",
ckpt_path=None,
ignore_keys=[],
ignore_keys=None,
load_only_unet=False,
monitor=None,
use_ema=True,
Expand All @@ -67,6 +67,8 @@ def __init__(self,
logvar_init=0.
):
super().__init__()
if ignore_keys is None:
ignore_keys = []
assert parameterization in ["eps", "x0"], 'currently only supporting "eps" and "x0"'
self.parameterization = parameterization
mainlogger.info(f"{self.__class__.__name__}: Running in {self.parameterization}-prediction mode")
Expand Down Expand Up @@ -156,13 +158,13 @@ def register_schedule(self, given_betas=None, beta_schedule="linear", timesteps=
lvlb_weights = self.betas ** 2 / (
2 * self.posterior_variance * to_torch(alphas) * (1 - self.alphas_cumprod))
elif self.parameterization == "x0":
lvlb_weights = 0.5 * np.sqrt(torch.Tensor(alphas_cumprod)) / (2. * 1 - torch.Tensor(alphas_cumprod))
lvlb_weights = 0.5 * np.sqrt(torch.Tensor(alphas_cumprod)) / (2. * (1 - torch.Tensor(alphas_cumprod)))
else:
raise NotImplementedError("mu not supported")
# TODO how to choose this term
lvlb_weights[0] = lvlb_weights[1]
self.register_buffer('lvlb_weights', lvlb_weights, persistent=False)
assert not torch.isnan(self.lvlb_weights).all()
assert not torch.isnan(self.lvlb_weights).any()

@contextmanager
def ema_scope(self, context=None):
Expand All @@ -179,7 +181,9 @@ def ema_scope(self, context=None):
if context is not None:
mainlogger.info(f"{context}: Restored training weights")

def init_from_ckpt(self, path, ignore_keys=list(), only_model=False):
def init_from_ckpt(self, path, ignore_keys=None, only_model=False):
if ignore_keys is None:
ignore_keys = []
sd = torch.load(path, map_location="cpu")
if "state_dict" in list(sd.keys()):
sd = sd["state_dict"]
Expand Down