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

Method _validation_step

sat/sgm/models/autoencoder.py:302–338  ·  view source on GitHub ↗
(self, batch: dict, batch_idx: int, postfix: str = "")

Source from the content-addressed store, hash-verified

300 return log_dict
301
302 def _validation_step(self, batch: dict, batch_idx: int, postfix: str = "") -> Dict:
303 x = self.get_input(batch)
304
305 z, xrec, regularization_log = self(x)
306 if hasattr(self.loss, "forward_keys"):
307 extra_info = {
308 "z": z,
309 "optimizer_idx": 0,
310 "global_step": self.global_step,
311 "last_layer": self.get_last_layer(),
312 "split": "val" + postfix,
313 "regularization_log": regularization_log,
314 "autoencoder": self,
315 }
316 extra_info = {k: extra_info[k] for k in self.loss.forward_keys}
317 else:
318 extra_info = dict()
319 out_loss = self.loss(x, xrec, **extra_info)
320 if isinstance(out_loss, tuple):
321 aeloss, log_dict_ae = out_loss
322 else:
323 # simple loss function
324 aeloss = out_loss
325 log_dict_ae = {f"val{postfix}/loss/rec": aeloss.detach()}
326 full_log_dict = log_dict_ae
327
328 if "optimizer_idx" in extra_info:
329 extra_info["optimizer_idx"] = 1
330 discloss, log_dict_disc = self.loss(x, xrec, **extra_info)
331 full_log_dict.update(log_dict_disc)
332 self.log(
333 f"val{postfix}/loss/rec",
334 log_dict_ae[f"val{postfix}/loss/rec"],
335 sync_dist=True,
336 )
337 self.log_dict(full_log_dict, sync_dist=True)
338 return full_log_dict
339
340 def get_param_groups(
341 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