本文整理汇总了Python中utils.timer.Timer.remain方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.remain方法的具体用法?Python Timer.remain怎么用?Python Timer.remain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.timer.Timer
的用法示例。
在下文中一共展示了Timer.remain方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_model
# 需要导入模块: from utils.timer import Timer [as 别名]
# 或者: from utils.timer.Timer import remain [as 别名]
def train_model(self, max_iters):
"""Network training loop."""
last_snapshot_iter = -1
timer = Timer()
losstxt = os.path.join(self.output_dir, 'loss.txt')
f = open(losstxt, 'w')
while self.solver.iter < max_iters:
timer.tic()
self.solver.step(1)
timer.toc()
if self.solver.iter % (1 * self.solver_param.display) == 0:
print '---------------------------------------------------------'
print 'speed: {:.3f}s / iter'.format(timer.average_time)
print 'time remains: {}s'.format(timer.remain(self.solver.iter, max_iters))
print '---------------------------------------------------------'
if self.solver.iter % cfg.SNAPSHOT_ITERS == 0:
last_snapshot_iter = self.solver.iter
self.snapshot()
loss = self.solver.net.blobs['loss'].data[0]
f.write('{} {}\n'.format(self.solver.iter - 1, loss))
f.flush()
f.close()
if last_snapshot_iter != self.solver.iter:
self.snapshot()
示例2: train
# 需要导入模块: from utils.timer import Timer [as 别名]
# 或者: from utils.timer.Timer import remain [as 别名]
def train(self):
print("Solver train() start")
train_timer = Timer()
load_timer = Timer()
for step in range(1, self.max_iter + 1):
print("step:%d"%step)
time.sleep(5)
load_timer.tic()
images, labels = self.data.get()
load_timer.toc()
feed_dict = {self.net.images: images,
self.net.labels: labels}
if step % self.summary_iter == 0:
if step % (self.summary_iter * 10) == 0:
train_timer.tic()
summary_str, loss, _ = self.sess.run(
[self.summary_op, self.net.total_loss, self.train_op],
feed_dict=feed_dict)
train_timer.toc()
log_str = '''{} Epoch: {}, Step: {}, Learning rate: {},'''
''' Loss: {:5.3f}\nSpeed: {:.3f}s/iter,'''
'''' Load: {:.3f}s/iter, Remain: {}'''.format(
datetime.datetime.now().strftime('%m-%d %H:%M:%S'),
self.data.epoch,
int(step),
round(self.learning_rate.eval(session=self.sess), 6),
loss,
train_timer.average_time,
load_timer.average_time,
train_timer.remain(step, self.max_iter))
print(log_str)
else:
train_timer.tic()
summary_str, _ = self.sess.run(
[self.summary_op, self.train_op],
feed_dict=feed_dict)
train_timer.toc()
self.writer.add_summary(summary_str, step)
else:
train_timer.tic()
self.sess.run(self.train_op, feed_dict=feed_dict)
train_timer.toc()
if step % self.save_iter == 0:
print('{} Saving checkpoint file to: {}'.format(
datetime.datetime.now().strftime('%m-%d %H:%M:%S'),
self.output_dir))
self.saver.save(
self.sess, self.ckpt_file, global_step=self.global_step)
示例3: train
# 需要导入模块: from utils.timer import Timer [as 别名]
# 或者: from utils.timer.Timer import remain [as 别名]
def train(self):
isTest = False
train_timer = Timer()
load_timer = Timer()
for step in range(1, self.max_iter + 1):
print("{}:第{}轮训练".format(datetime.datetime.now().strftime('%m-%d %H:%M:%S'),step))
time.sleep(2)
load_timer.tic()
images, labels = self.data.get()
load_timer.toc()
feed_dict = {self.net.images: images,
self.net.labels: labels}
if step % self.summary_iter == 0:
if step % (self.summary_iter * 10) == 0:
train_timer.tic()
summary_str, loss, _ = self.sess.run(
[self.summary_op, self.net.total_loss, self.train_op],
feed_dict=feed_dict)
train_timer.toc()
print('{} Epoch: {}, Step: {}, Learning rate: {}, Loss: {:5.3f}\nSpeed: {:.3f}s/iter,Load: {:.3f}s / iter, Remain: {}'.format(
datetime.datetime.now().strftime('%m-%d %H:%M:%S'),
self.data.epoch,
int(step),
round(self.learning_rate.eval(session=self.sess), 6),
loss,
train_timer.average_time,
load_timer.average_time,
train_timer.remain(step, self.max_iter)))
else:
train_timer.tic()
summary_str, _ = self.sess.run(
[self.summary_op, self.train_op],
feed_dict=feed_dict)
train_timer.toc()
self.writer.add_summary(summary_str, step)
else:
train_timer.tic()
self.sess.run(self.train_op, feed_dict=feed_dict)
train_timer.toc()
time.sleep(1)
isTest = True
#if step % self.save_iter == 0:
if step == 1:#测试保存功能时使用此行
self.saveData(step)
break
print("假装已经训练完成")