Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* callbacks with and without name
* initialized and uninitialized callbacks
* puts PrintLog(s) last
"""
print_logs = []
for item in self.get_default_callbacks() + (self.callbacks or []):
if isinstance(item, (tuple, list)):
name, cb = item
else:
cb = item
if isinstance(cb, type): # uninitialized:
name = cb.__name__
else:
name = cb.__class__.__name__
if isinstance(cb, PrintLog) or (cb == PrintLog):
print_logs.append((name, cb))
else:
yield name, cb
yield from print_logs
def _default_callbacks(self):
return [
('epoch_timer', EpochTimer()),
('train_loss', BatchScoring(
train_loss_score,
name='train_loss',
on_train=True,
target_extractor=noop,
)),
('valid_loss', BatchScoring(
valid_loss_score,
name='valid_loss',
target_extractor=noop,
)),
('print_log', PrintLog()),
]
def _default_callbacks(self):
return [
('epoch_timer', EpochTimer()),
('train_loss', BatchScoring(
train_loss_score,
name='train_loss',
on_train=True,
target_extractor=noop,
)),
('valid_loss', BatchScoring(
valid_loss_score,
name='valid_loss',
target_extractor=noop,
)),
('print_log', PrintLog()),
]
* puts PrintLog(s) last
"""
print_logs = []
for item in self.get_default_callbacks() + (self.callbacks or []):
if isinstance(item, (tuple, list)):
named_by_user = True
name, cb = item
else:
named_by_user = False
cb = item
if isinstance(cb, type): # uninitialized:
name = cb.__name__
else:
name = cb.__class__.__name__
if isinstance(cb, PrintLog) or (cb == PrintLog):
print_logs.append((name, cb, named_by_user))
else:
yield name, cb, named_by_user
yield from print_logs
train_loss_score,
name='train_loss',
on_train=True,
target_extractor=noop,
)),
('valid_loss', BatchScoring(
valid_loss_score,
name='valid_loss',
target_extractor=noop,
)),
('valid_acc', EpochScoring(
'accuracy',
name='valid_acc',
lower_is_better=False,
)),
('print_log', PrintLog()),
]