使用PyTorch运行单个预测时出现问题
我有一个使用PyTorch的训练有素的模型,现在我想简单地在一个示例上运行它使用PyTorch运行单个预测时出现问题,pytorch,torch,Pytorch,Torch,我有一个使用PyTorch的训练有素的模型,现在我想简单地在一个示例上运行它 >>> model nn.Sequential { [input -> (0) -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> output] (0): nn.SpatialConvolutionMap (1): nn.
>>> model
nn.Sequential {
[input -> (0) -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> output]
(0): nn.SpatialConvolutionMap
(1): nn.Tanh
(2): nn.SpatialMaxPooling(2x2, 2, 2)
(3): nn.SpatialConvolutionMap
(4): nn.Tanh
(5): nn.SpatialMaxPooling(2x2, 2, 2)
(6): nn.Reshape(6400)
(7): nn.Linear(6400 -> 128)
(8): nn.Tanh
(9): nn.Linear(128 -> 5)
(10): nn.LogSoftMax
}
然后,我从测试集中加载一个图像:
image = cv2.imread('image.png',cv2.IMREAD_GRAYSCALE)
transformation = transforms.Compose([transforms.ToTensor()])
image_tensor = transformation(image).float()
inp = Variable(image_tensor)
最后尝试运行网络
output = model(inp)
但是我得到了errorTypeError:“Sequential”对象是不可调用的似乎您的模型不是(pytorch
Sequential
),而是(一个遗留的lua torch模型)。尝试显式使用此模型
forward()
:
output = model.forward(inp[None, ...]) # don't forget to add "batch" dimension
谢谢,似乎是这样,但现在我得到了错误:oubleSpatialConvolutionMap_updateOutput收到了无效的参数组合-get(int,Tensor,Tensor,Tensor,Tensor,Tensor,int,int,int),但应为(int state,torch.DoubleTensor input,torch.DoubleTensor output,torch.DoubleTensor weight,torch.DoubleTensor bias,torch.DoubleTensor connTable,int nInputPlane,int nOutputPlane,int dW,int dH)@VahagnTumanyan尝试将旧模型转换为pytorch模型。这样做会更容易。