|
def one_iter_of_cifar10_training(dataloader, model, niter=1, loss_fn=ndl.nn.SoftmaxLoss(), opt=None, device=None): |
|
np.random.seed(4) |
|
model.train() |
|
correct, total_loss = 0, 0 |
|
i = 1 |
|
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] |
Is it intended that correct is a float scalar and total_loss is a np array? They're heterogenous but later fed into ndl.Tensor ctor, leading to Error.
hw4/tests/hw4/test_conv.py
Lines 471 to 483 in 1ef8c3b
Is it intended that
correctis a float scalar andtotal_lossis a np array? They're heterogenous but later fed into ndl.Tensor ctor, leading to Error.