Skip to content

Commit

Permalink
Typings added
Browse files Browse the repository at this point in the history
  • Loading branch information
SkaarFacee committed Dec 9, 2023
1 parent fff69d4 commit 22e323c
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion references/classification/train_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion references/classification/train_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion references/classification/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion references/detection/train_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion references/detection/train_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion references/detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion references/obj_detection/train_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion references/obj_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion references/recognition/train_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion references/recognition/train_pytorch_ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion references/recognition/train_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion references/recognition/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22e323c

Please sign in to comment.