Exemplo n.º 1
0
 def __init__(self, model, criterion,
              replicate_in_memory=True):
     self.model = model
     self.criterion = criterion
     self.metrics = dict()
     self.add_metric('loss', lambda: Loss())
     self.replicate_in_memory = replicate_in_memory
Exemplo n.º 2
0
def test_loss():
    loss_calculator = Loss(average=True)
    loss = list()
    loss_calculator.reset()
    for _ in range(10):
        epoch_loss = np.random.uniform(0, 1)
        loss.append(epoch_loss)
        loss_calculator.update(epoch_loss)

    assert np.around(np.array(loss).mean(),
                     decimals=4) == np.around(loss_calculator.value,
                                              decimals=4)

    loss_calculator = Loss(average=False)
    loss = list()
    loss_calculator.reset()
    for _ in range(10):
        epoch_loss = np.random.uniform(0, 1)
        loss.append(epoch_loss)
        loss_calculator.update(epoch_loss)

    assert np.allclose(np.array(loss), loss_calculator.value)
Exemplo n.º 3
0
 def __init__(self, model, criterion):
     self.model = model
     self.criterion = criterion
     self.metrics = dict()
     self.add_metric('loss', lambda: Loss())