MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / _validation_step

Method _validation_step

sat/vae_modules/autoencoder.py:317–353  ·  view source on GitHub ↗
(self, batch: dict, batch_idx: int, postfix: str = "")

Source from the content-addressed store, hash-verified

315 return log_dict
316
317 def _validation_step(self, batch: dict, batch_idx: int, postfix: str = "") -> Dict:
318 x = self.get_input(batch)
319
320 z, xrec, regularization_log = self(x)
321 if hasattr(self.loss, "forward_keys"):
322 extra_info = {
323 "z": z,
324 "optimizer_idx": 0,
325 "global_step": self.global_step,
326 "last_layer": self.get_last_layer(),
327 "split": "val" + postfix,
328 "regularization_log": regularization_log,
329 "autoencoder": self,
330 }
331 extra_info = {k: extra_info[k] for k in self.loss.forward_keys}
332 else:
333 extra_info = dict()
334 out_loss = self.loss(x, xrec, **extra_info)
335 if isinstance(out_loss, tuple):
336 aeloss, log_dict_ae = out_loss
337 else:
338 # simple loss function
339 aeloss = out_loss
340 log_dict_ae = {f"val{postfix}/loss/rec": aeloss.detach()}
341 full_log_dict = log_dict_ae
342
343 if "optimizer_idx" in extra_info:
344 extra_info["optimizer_idx"] = 1
345 discloss, log_dict_disc = self.loss(x, xrec, **extra_info)
346 full_log_dict.update(log_dict_disc)
347 self.log(
348 f"val{postfix}/loss/rec",
349 log_dict_ae[f"val{postfix}/loss/rec"],
350 sync_dist=True,
351 )
352 self.log_dict(full_log_dict, sync_dist=True)
353 return full_log_dict
354
355 def get_param_groups(
356 self, parameter_names: List[List[str]], optimizer_args: List[dict]

Callers 1

validation_stepMethod · 0.95

Calls 4

get_inputMethod · 0.95
get_last_layerMethod · 0.95
logMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected