From 22e323c5afce19543839a0f33fea462070f87a63 Mon Sep 17 00:00:00 2001 From: Aditya Anil Date: Sun, 10 Dec 2023 01:19:40 +0530 Subject: [PATCH] Typings added --- references/classification/train_pytorch.py | 3 ++- references/classification/train_tensorflow.py | 3 ++- references/classification/utils.py | 2 +- references/detection/train_pytorch.py | 3 ++- references/detection/train_tensorflow.py | 3 ++- references/detection/utils.py | 2 +- references/obj_detection/train_pytorch.py | 2 +- references/obj_detection/utils.py | 2 +- references/recognition/train_pytorch.py | 3 ++- references/recognition/train_pytorch_ddp.py | 3 ++- references/recognition/train_tensorflow.py | 3 ++- references/recognition/utils.py | 2 +- 12 files changed, 19 insertions(+), 12 deletions(-) diff --git a/references/classification/train_pytorch.py b/references/classification/train_pytorch.py index 9f06c8f0fc..51bfe7bc01 100644 --- a/references/classification/train_pytorch.py +++ b/references/classification/train_pytorch.py @@ -331,7 +331,7 @@ def main(args): min_loss = np.inf # Training loop if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) for epoch in range(args.epochs): fit_one_epoch(model, train_loader, batch_transforms, optimizer, scheduler) @@ -421,6 +421,7 @@ def parse_args(): parser.add_argument("--find-lr", action="store_true", help="Gridsearch the optimal LR") parser.add_argument("--early-stop", action="store_true", help="Enable early stopping") parser.add_argument("--early-stop-epochs", type=int, default=5, help="Patience for early stopping") + parser.add_argument("--early-stop-delta", type=float, default=0.01, help="Minimum Delta for early stopping") args = parser.parse_args() return args diff --git a/references/classification/train_tensorflow.py b/references/classification/train_tensorflow.py index c7dbc28637..8cae252a52 100644 --- a/references/classification/train_tensorflow.py +++ b/references/classification/train_tensorflow.py @@ -295,7 +295,7 @@ def main(args): # Training loop if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) for epoch in range(args.epochs): fit_one_epoch(model, train_loader, batch_transforms, optimizer, args.amp) @@ -395,6 +395,7 @@ def parse_args(): parser.add_argument("--find-lr", action="store_true", help="Gridsearch the optimal LR") parser.add_argument("--early-stop", action="store_true", help="Enable early stopping") parser.add_argument("--early-stop-epochs", type=int, default=5, help="Patience for early stopping") + parser.add_argument("--early-stop-delta", type=float, default=0.01, help="Minimum Delta for early stopping") args = parser.parse_args() return args diff --git a/references/classification/utils.py b/references/classification/utils.py index 8618a4de7e..a457132e59 100644 --- a/references/classification/utils.py +++ b/references/classification/utils.py @@ -81,7 +81,7 @@ def __init__(self, patience: int = 5, min_delta: float = 0.01): self.counter = 0 self.min_validation_loss = float("inf") - def early_stop(self, validation_loss: float): + def early_stop(self, validation_loss: float) -> bool: if validation_loss < self.min_validation_loss: self.min_validation_loss = validation_loss self.counter = 0 diff --git a/references/detection/train_pytorch.py b/references/detection/train_pytorch.py index 2631b14cfc..cbfa45c495 100644 --- a/references/detection/train_pytorch.py +++ b/references/detection/train_pytorch.py @@ -368,7 +368,7 @@ def main(args): # Create loss queue min_loss = np.inf if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) # Training loop for epoch in range(args.epochs): @@ -451,6 +451,7 @@ def parse_args(): parser.add_argument("--find-lr", action="store_true", help="Gridsearch the optimal LR") parser.add_argument("--early-stop", action="store_true", help="Enable early stopping") parser.add_argument("--early-stop-epochs", type=int, default=5, help="Patience for early stopping") + parser.add_argument("--early-stop-delta", type=float, default=0.01, help="Minimum Delta for early stopping") args = parser.parse_args() return args diff --git a/references/detection/train_tensorflow.py b/references/detection/train_tensorflow.py index a9e3a69d86..4ad405a43c 100644 --- a/references/detection/train_tensorflow.py +++ b/references/detection/train_tensorflow.py @@ -327,7 +327,7 @@ def main(args): min_loss = np.inf if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) # Training loop for epoch in range(args.epochs): @@ -419,6 +419,7 @@ def parse_args(): parser.add_argument("--find-lr", action="store_true", help="Gridsearch the optimal LR") parser.add_argument("--early-stop", action="store_true", help="Enable early stopping") parser.add_argument("--early-stop-epochs", type=int, default=5, help="Patience for early stopping") + parser.add_argument("--early-stop-delta", type=float, default=0.01, help="Minimum Delta for early stopping") args = parser.parse_args() return args diff --git a/references/detection/utils.py b/references/detection/utils.py index 8b357df05b..5b1c03d82f 100644 --- a/references/detection/utils.py +++ b/references/detection/utils.py @@ -100,7 +100,7 @@ def __init__(self, patience: int = 5, min_delta: float = 0.01): self.counter = 0 self.min_validation_loss = float("inf") - def early_stop(self, validation_loss: float): + def early_stop(self, validation_loss: float) -> bool: if validation_loss < self.min_validation_loss: self.min_validation_loss = validation_loss self.counter = 0 diff --git a/references/obj_detection/train_pytorch.py b/references/obj_detection/train_pytorch.py index b6f5e2ffc3..0e203b75e4 100644 --- a/references/obj_detection/train_pytorch.py +++ b/references/obj_detection/train_pytorch.py @@ -306,7 +306,7 @@ def main(args): max_score = 0.0 if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) for epoch in range(args.epochs): fit_one_epoch(model, train_loader, optimizer, scheduler, amp=args.amp) # Validation loop at the end of each epoch diff --git a/references/obj_detection/utils.py b/references/obj_detection/utils.py index 2f19547097..99a2072cdd 100644 --- a/references/obj_detection/utils.py +++ b/references/obj_detection/utils.py @@ -86,7 +86,7 @@ def __init__(self, patience: int = 5, min_delta: float = 0.01): self.counter = 0 self.min_validation_loss = float("inf") - def early_stop(self, validation_loss: float): + def early_stop(self, validation_loss: float) -> bool: if validation_loss < self.min_validation_loss: self.min_validation_loss = validation_loss self.counter = 0 diff --git a/references/recognition/train_pytorch.py b/references/recognition/train_pytorch.py index 691d58c37c..ffe1c1ee16 100644 --- a/references/recognition/train_pytorch.py +++ b/references/recognition/train_pytorch.py @@ -393,7 +393,7 @@ def main(args): min_loss = np.inf # Training loop if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) for epoch in range(args.epochs): fit_one_epoch(model, train_loader, batch_transforms, optimizer, scheduler, amp=args.amp) @@ -484,6 +484,7 @@ def parse_args(): parser.add_argument("--find-lr", action="store_true", help="Gridsearch the optimal LR") parser.add_argument("--early-stop", action="store_true", help="Enable early stopping") parser.add_argument("--early-stop-epochs", type=int, default=5, help="Patience for early stopping") + parser.add_argument("--early-stop-delta", type=float, default=0.01, help="Minimum Delta for early stopping") args = parser.parse_args() return args diff --git a/references/recognition/train_pytorch_ddp.py b/references/recognition/train_pytorch_ddp.py index 081e54d051..c6c0827d9f 100644 --- a/references/recognition/train_pytorch_ddp.py +++ b/references/recognition/train_pytorch_ddp.py @@ -322,7 +322,7 @@ def main(rank: int, world_size: int, args): # Create loss queue min_loss = np.inf if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) # Training loop for epoch in range(args.epochs): fit_one_epoch(model, device, train_loader, batch_transforms, optimizer, scheduler, amp=args.amp) @@ -421,6 +421,7 @@ def parse_args(): parser.add_argument("--amp", dest="amp", help="Use Automatic Mixed Precision", action="store_true") parser.add_argument("--early-stop", action="store_true", help="Enable early stopping") parser.add_argument("--early-stop-epochs", type=int, default=5, help="Patience for early stopping") + parser.add_argument("--early-stop-delta", type=float, default=0.01, help="Minimum Delta for early stopping") args = parser.parse_args() return args diff --git a/references/recognition/train_tensorflow.py b/references/recognition/train_tensorflow.py index bf0ec7c542..0f8c99f4b9 100644 --- a/references/recognition/train_tensorflow.py +++ b/references/recognition/train_tensorflow.py @@ -348,7 +348,7 @@ def main(args): min_loss = np.inf if args.early_stop: - early_stopper = EarlyStopper(patience=args.early_stop_epochs) + early_stopper = EarlyStopper(patience=args.early_stop_epochs, min_delta=args.early_stop_delta) # Training loop for epoch in range(args.epochs): fit_one_epoch(model, train_loader, batch_transforms, optimizer, args.amp) @@ -447,6 +447,7 @@ def parse_args(): parser.add_argument("--find-lr", action="store_true", help="Gridsearch the optimal LR") parser.add_argument("--early-stop", action="store_true", help="Enable early stopping") parser.add_argument("--early-stop-epochs", type=int, default=5, help="Patience for early stopping") + parser.add_argument("--early-stop-delta", type=float, default=0.01, help="Minimum Delta for early stopping") args = parser.parse_args() return args diff --git a/references/recognition/utils.py b/references/recognition/utils.py index 66804857a1..e3b54a2ad7 100644 --- a/references/recognition/utils.py +++ b/references/recognition/utils.py @@ -81,7 +81,7 @@ def __init__(self, patience: int = 5, min_delta: float = 0.01): self.counter = 0 self.min_validation_loss = float("inf") - def early_stop(self, validation_loss: float): + def early_stop(self, validation_loss: float) -> bool: if validation_loss < self.min_validation_loss: self.min_validation_loss = validation_loss self.counter = 0