如何在python中运行割炬时修复NotImplementedError

时间:2019-07-24 13:36:24

标签: python torch

请尝试在Windows10上使用python中的pytorch在pytorch中运行Logistic回归,但在尝试训练模型时,始终遇到此错误NotimplementedError。代码如下所示

iterations = 0
for epoch in range(num_epochs):
    for i,(images,labels) in enumerate(train_data):
        images = Variable(images.view(-1,28*28))
        labels = Variable(labels)

        optimizer.zero_grad()
        output = model(images)
        loss = criterion(output,labels)
        loss.backward()
        optimizer.step()
        iterations +=1

        if iterations % 500 == 0:
            #calculate acuracy
            correct = 0
            total = 0
            for images,labels in test_data:
                images = Variable(images.view(-1,28*28))
                output = model(images)

                _, predicted = torch.max(output.data, 1)

                total += labels.size(0)
                correct += (predicted == labels).sum()
            accuracy = 100 * correct/total

        print('Iteration {}, loss {}, accuracy {}'.format(iterations,loss.data,accuracy))

0 个答案:

没有答案