Skip to content

Type weirdness in ResNet9 submission code #6

@Guan-t7

Description

@Guan-t7

hw4/tests/hw4/test_conv.py

Lines 471 to 483 in 1ef8c3b

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions