MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _validate

Method _validate

monai/optimizers/lr_finder.py:431–446  ·  view source on GitHub ↗
(self, val_iter: ValDataLoaderIter, non_blocking_transfer: bool = True)

Source from the content-addressed store, hash-verified

429 return total_loss
430
431 def _validate(self, val_iter: ValDataLoaderIter, non_blocking_transfer: bool = True) -> float:
432 # Set model to evaluation mode and disable gradient computation
433 running_loss = 0
434 with eval_mode(self.model):
435 for inputs, labels in val_iter:
436 # Copy data to the correct device
437 inputs, labels = copy_to_device(
438 [inputs, labels], device=self.device, non_blocking=non_blocking_transfer
439 )
440
441 # Forward pass and loss computation
442 outputs = self.model(inputs)
443 loss = self.criterion(outputs, labels)
444 running_loss += loss.item() * len(labels)
445
446 return running_loss / len(val_iter.dataset)
447
448 def get_lrs_and_losses(self, skip_start: int = 0, skip_end: int = 0) -> tuple[list, list]:
449 """Get learning rates and their corresponding losses

Callers 1

range_testMethod · 0.95

Calls 3

eval_modeFunction · 0.90
copy_to_deviceFunction · 0.90
modelMethod · 0.80

Tested by

no test coverage detected