Numpy Pytorch:将[1,x]大小的张量转换为[x]大小的张量
当我尝试在Pytorch 0.4.0中加载一个可能由Pytorch 0.3.1生成的模型时,我不断遇到这样的错误:Numpy Pytorch:将[1,x]大小的张量转换为[x]大小的张量,numpy,pytorch,Numpy,Pytorch,当我尝试在Pytorch 0.4.0中加载一个可能由Pytorch 0.3.1生成的模型时,我不断遇到这样的错误: While copying the parameter named "conv1_7x7_s2_bn.bias", whose dimensions in the model are torch.Size([64]) and whose dimensions in the checkpoint are torch.Size([1, 64]). 我想如果我在每个张量上应用了转置,那
While copying the parameter named "conv1_7x7_s2_bn.bias", whose dimensions in the
model are torch.Size([64]) and whose dimensions in the checkpoint are torch.Size([1, 64]).
我想如果我在每个张量上应用了转置
,那么它会工作,但它仍然失败,因为维度变成了[64,1]
,而不是我需要的[64]
我可以去掉多余的维度,从而把一行矩阵变成一个向量吗
注意:当调用火炬.展平
时,我得到:
AttributeError: module 'torch' has no attribute 'flatten'
删除空维度称为“压缩”,和 因此,正确的命令是:
torch.squeeze(tensor)
你试过火炬吗?@NilsWerner谢谢,成功了!我建议你把它写下来作为答案,这样我就可以接受了。再次感谢!