Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add last epoch argument #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions train_ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
parser.add_argument('--pretrained_ssd', help='Pre-trained base model')
parser.add_argument('--resume', default=None, type=str,
help='Checkpoint state_dict file to resume training from')
parser.add_argument('--last-epoch', default=-1, type=int, help='Epoch to start from, when resuming the model.')


# Scheduler
parser.add_argument('--scheduler', default="multi-step", type=str,
Expand Down Expand Up @@ -240,8 +242,7 @@ def test(loader, net, criterion, device):
logging.info("Build network.")
net = create_net(num_classes)
min_loss = -10000.0
last_epoch = -1


base_net_lr = args.base_net_lr if args.base_net_lr is not None else args.lr
extra_layers_lr = args.extra_layers_lr if args.extra_layers_lr is not None else args.lr
if args.freeze_base_net:
Expand Down Expand Up @@ -302,18 +303,18 @@ def test(loader, net, criterion, device):
if args.scheduler == 'multi-step':
logging.info("Uses MultiStepLR scheduler.")
milestones = [int(v.strip()) for v in args.milestones.split(",")]
scheduler = MultiStepLR(optimizer, milestones=milestones,
gamma=0.1, last_epoch=last_epoch)
scheduler = MultiStepLR(optimizer, milestones=milestones, gamma=0.1)

elif args.scheduler == 'cosine':
logging.info("Uses CosineAnnealingLR scheduler.")
scheduler = CosineAnnealingLR(optimizer, args.t_max, last_epoch=last_epoch)
scheduler = CosineAnnealingLR(optimizer, args.t_max)
else:
logging.fatal(f"Unsupported Scheduler: {args.scheduler}.")
parser.print_help(sys.stderr)
sys.exit(1)

logging.info(f"Start training from epoch {last_epoch + 1}.")
for epoch in range(last_epoch + 1, args.num_epochs):
logging.info(f"Start training from epoch {args.last_epoch + 1}.")
for epoch in range(args.last_epoch + 1, args.num_epochs):
scheduler.step()
train(train_loader, net, criterion, optimizer,
device=DEVICE, debug_steps=args.debug_steps, epoch=epoch)
Expand Down