def test_cannot_add_same_name(self): queue = callbacks.CallbackQueue([callbacks.Monitor()]) queue.append(callbacks.Monitor()) assert len(queue) == 1 queue.extend([callbacks.Monitor()]) assert len(queue) == 1
def get_callbacks(data, trainer, path): return [ callbacks.Validate(data(mode='val'), trainer.validate), callbacks.Monitor(), callbacks.LRScheduler( ExponentialLR(trainer.optimizers[0], gamma=0.1)), mdb.Babysitter(), callbacks.Checkpoint(path) ]
def test_less_loss(self): data, model, trainer = get_obj() cbacks = [ callbacks.Validate(data(mode='val', sample_space=0.01), SupervisedTrainer.validate), callbacks.Monitor() ] trainer.train(data(sample_space=0.01), epochs=0.3, callbacks=cbacks) losses = trainer.callbacks[1].history['loss'] assert losses[0] > losses[1] val_losses = trainer.callbacks[1].history['val_loss'] assert val_losses[0] > val_losses[1]
def test_multiple_callbacks_error(self): queue = callbacks.CallbackQueue( [callbacks.Monitor() for _ in range(2)]) with pytest.raises(RuntimeError): queue.exists('monitor')
def test_exists(self): queue = callbacks.CallbackQueue([callbacks.Monitor()]) assert queue.exists('monitor') assert not queue.exists('einstein')