Pytorch如何用自己训练好的模型预测新的图片类型?

def predict(img_path):
    net = torch.load('model.pkl') 
    net = net.to(device)
    torch.no_grad()
    img = PIL.Image.open(img_path)
    img_ = transform(img).unsqueeze(0)
    img_ = img_.to(device)
    outputs = net(img_)
    _, predicted = torch.max(outputs,1)
    print(predicted)


# by mote-tao

 

你可能感兴趣的:(PyTorch)