写pytroch代码过程中遇到的错误
此篇博客用来记录写pytorch代码过程中遇到的各种奇奇怪怪的错误以及解决办法,持续更新。
1.RuntimeError: expected dtype Double but got dtype Float 这个错误,我觉得应该后面加上 .double() ,但是不知道为什么实际是加上 .float() 才好了
2.TypeError: ‘int’ object is not callable 训练集需要用torch.from_numpy()转换为tensor类型
3.RuntimeError: Given groups=1, weight of size [24, 3, 3, 3], expected input[100, 32, 32, 3] to have 3 channels, but got 32 channels instead torch和keras处理图片的维度顺序有所不同,torch需要将维度放在最前面,用permute()改变维度顺序
5.RuntimeError: Input type (torch.cuda.DoubleTensor) and weight type (torch.cuda.FloatTensor) should be the same 需要用float()改变输入,改变图片即可,标签不用动
6.RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 ‘target’ 用long()改变标签
7.RuntimeError: multi-target not supported at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:15 使用交叉熵函数,标签必须为1D的,2D的不行
8.TypeError: expected np.ndarray (got list) 用np.array()转换一下