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

fix continue train iter count error #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
trainer = Pix2PixTrainer(opt)

# create tool for counting iterations
iter_counter = IterationCounter(opt, len(dataloader))
iter_counter = IterationCounter(opt, len(dataloader) * opt.batchSize)

# create tool for visualization
visualizer = Visualizer(opt)

clear_iter = False
for epoch in iter_counter.training_epochs():
iter_counter.record_epoch_start(epoch)
for i, data_i in enumerate(dataloader, start=iter_counter.epoch_iter):
iter_counter.record_epoch_start(epoch, clear_iter)
clear_iter = True

start_batch_idx = iter_counter.epoch_iter // opt.batchSize
for i, data_i in enumerate(dataloader):
if i < start_batch_idx:
continue

iter_counter.record_one_iteration()

# Training
Expand Down
5 changes: 3 additions & 2 deletions util/iter_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ def __init__(self, opt, dataset_size):
def training_epochs(self):
return range(self.first_epoch, self.total_epochs + 1)

def record_epoch_start(self, epoch):
def record_epoch_start(self, epoch, clear_iter=True):
self.epoch_start_time = time.time()
self.epoch_iter = 0
if clear_iter:
self.epoch_iter = 0
self.last_iter_time = time.time()
self.current_epoch = epoch

Expand Down