Skip to content

wrong acc, loss return in one_iter_of_cifar10_training #2

@tiendung

Description

@tiendung

return correct/(y.shape[0]*niter), total_loss/(y.shape[0]*niter)

    for batch in dataloader:
        opt.reset_grad()
        X, y = batch
        X,y = ndl.Tensor(X, device=device), ndl.Tensor(y, device=device)
        out = model(X)
        correct += np.sum(np.argmax(out.numpy(), axis=1) == y.numpy())
        loss = loss_fn(out, y)
        total_loss += loss.data.numpy() * y.shape[0]
        loss.backward()
        opt.step()
        if i >= niter:
            break
        i += 1
    return correct/(y.shape[0]*niter), total_loss/(y.shape[0]*niter)

correct/(y.shape[0]*niter), total_loss/(y.shape[0]*niter) only correct if the size of the last batch is equal to the others. It's maybe not true for all dataset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions