Exemplo n.º 1
0
def system_check():
    import traceback

    try:
        import torch
        from olympus.models import Model
        from olympus.optimizers import Optimizer

        batch = torch.randn((32, 3, 64, 64)).cuda()
        model = Model('resnet18', input_size=(3, 64, 64),
                      output_size=(10, )).cuda()

        model.init()

        optimizer = Optimizer('sgd', params=model.parameters())

        optimizer.init(**optimizer.defaults)

        optimizer.zero_grad()
        loss = model(batch).sum()

        optimizer.backward(loss)
        optimizer.step()

        return True
    except:
        error(traceback.format_exc())
        return False
Exemplo n.º 2
0
    ProgressView(speed, max_epochs=epochs,
                 max_steps=len(loader.train())).every(epoch=1, batch=1))

model = model.to(device=device)
loss = 0

event_handler.start_train()

for e in range(epochs):
    losses = []
    event_handler.new_epoch(e + 1)

    for step, ((batch, ), target) in enumerate(loader.train()):
        event_handler.new_batch(step)

        optimizer.zero_grad()
        predict = model(batch.to(device=device))

        loss = F.cross_entropy(predict, target.to(device=device))
        losses.append(loss.detach())

        optimizer.backward(loss)
        optimizer.step()

        event_handler.end_batch(step)

    losses = [l.item() for l in losses]
    loss = sum(losses) / len(losses)
    event_handler.end_epoch(e + 1)

event_handler.end_train()