无法规范化PyTorch中的张量

无法规范化PyTorch中的张量,pytorch,Pytorch,我试图规范化我的网络输出的张量,但这样做会出错。代码如下: device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model_load_path = r'path\to\saved\model\file' model.load_state_dict(torch.load(model_load_path)) model.eval() output = model(input).to(device).view(

我试图规范化我的网络输出的张量,但这样做会出错。代码如下:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model_load_path = r'path\to\saved\model\file'
model.load_state_dict(torch.load(model_load_path))
model.eval()
output = model(input).to(device).view(-1, 1, 150, 150)
inv_normalize = transforms.Compose(
    [
        transforms.Normalize(mean=[-0.5/0.5], std=[1/0.5])
    ]
)
print(output.size())  # The size printed is torch.Size([1, 1, 150, 150])
output = inv_normalize(output)
我在以下行中遇到错误:

output = inv_normalize(output)
错误内容如下:

TypeError: tensor is not a torch image.
我的输出是单个图像,具有单个通道,高度和宽度=150


任何帮助都将不胜感激!谢谢

为了应用
变换。规范化
您必须将输入转换为张量。为此,您可以使用


这个张量必须由三个维度组成(通道、高度、宽度)。目前你有一个维度到多个维度。只需删除
视图中的额外维度
调用:

output = model(input).to(device).view(1, 150, 150)

为了应用
变换。规范化
必须将输入转换为张量。为此,您可以使用


这个张量必须由三个维度组成(通道、高度、宽度)。目前你有一个维度到多个维度。只需删除
视图中的额外维度
调用:

output = model(input).to(device).view(1, 150, 150)

我的输入已经是张量了。我还是尝试了一下,在transforms.ToTensor()中出现了以下错误:pic应该是PIL Image或ndarray。得到了
除了作为张量的要求外,
的输入将进行变换。规范化
必须由三个维度组成(x、y和颜色通道)。现在你有一个维度到很多。我的输入已经是张量了。我还是尝试了一下,在transforms.ToTensor()中出现了以下错误:pic应该是PIL Image或ndarray。得到了
除了作为张量的要求外,
的输入将进行变换。规范化
必须由三个维度组成(x、y和颜色通道)。目前你有一个维度到多个维度。