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

Method get_steepest_gradient

monai/optimizers/lr_finder.py:468–485  ·  view source on GitHub ↗

Get learning rate which has steepest gradient and its corresponding loss Args: skip_start: number of batches to trim from the start. skip_end: number of batches to trim from the end. Returns: Learning rate which has steepest gradient and its corr

(self, skip_start: int = 0, skip_end: int = 0)

Source from the content-addressed store, hash-verified

466 return lrs, losses
467
468 def get_steepest_gradient(self, skip_start: int = 0, skip_end: int = 0) -> tuple[float, float] | tuple[None, None]:
469 """Get learning rate which has steepest gradient and its corresponding loss
470
471 Args:
472 skip_start: number of batches to trim from the start.
473 skip_end: number of batches to trim from the end.
474
475 Returns:
476 Learning rate which has steepest gradient and its corresponding loss
477 """
478 lrs, losses = self.get_lrs_and_losses(skip_start, skip_end)
479
480 try:
481 min_grad_idx = np.gradient(np.array(losses)).argmin()
482 return lrs[min_grad_idx], losses[min_grad_idx]
483 except ValueError:
484 print("Failed to compute the gradients, there might not be enough points.")
485 return None, None
486
487 def plot(
488 self,

Callers 2

plotMethod · 0.95
test_lr_finderMethod · 0.95

Calls 2

get_lrs_and_lossesMethod · 0.95
arrayMethod · 0.80

Tested by 1

test_lr_finderMethod · 0.76