如何在spyder中看到对象张量?

时间:2019-01-03 18:45:47

标签: object ide spyder pytorch

我很难看到间谍内部的物体。当我运行此代码段时,在变量资源管理器中,我只能看到所附的无花果,但是,我需要查看概率和其他对象张量,并且还需要访问概率的值?任何评论将不胜感激。

import torch
from U_Net_demo import device
from dataset import test_loader
import matplotlib.pyplot as plt
from torchvision.utils import make_grid
import torch.nn as nn
import numpy

criterion = nn.NLLLoss()


def test():

model_load = torch.load('model.pth')

#test model
model_load.eval()
total = 0
test_loss = 0
correct = 0
count = 0
#iterate through test dataset
for ii, data in enumerate(test_loader):

            t_image, mask = data
            t_image, mask = t_image.to(device), mask.to(device)
            with torch.no_grad():

                outputs = model_load(t_image)
                #print(outputs.shape) # torch.Size([1, 2, 240, 320])
                test_loss += criterion(outputs, mask).item() / len(test_loader)

                probs = torch.exp(outputs) 

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

                total += mask.nelement()
                correct += predicted.eq(mask.data).sum().item()
                accuracy = 100 * correct / total

                count +=1                
                print(count, "Test Loss: {:.3f}".format(test_loss), "Test Accuracy: %d %%" % (accuracy))


if __name__=='__main__':
    test = test()

varaible explorer

1 个答案:

答案 0 :(得分:0)

此处为Spyder维护者)自2019年1月起,Spyder的Variable Explorer中不支持Pytorch张量。