np.transpose()将numpy矩阵的纬度按[2,0,1]矩阵交换,np.expand_dims()维度拓展一个维度,位置为axis = 1,维度。一般直接用.copy()进行矩阵复制,不要直接相等。
rgb = np.expand_dims(np.transpose(rgb,[2,0,1]),axis=1).copy()
- “RuntimeError: Input type (torch.cuda.DoubleTensor) and weight type (torch.cuda.FloatTensor) should be the same”错误解决办法
input = torch.from_numpy(rgb)
target = torch.from_numpy(rad)
input = input.cuda()
target = target.cuda()
因为pytorch中的weight的类型存储为float32存储,而input为double(64)位,所以input和weight都为cuda()型的。并且类型要一样,但是numpy自动存储的类型为double(Float32),所以要将input的类型调整为double()型。
input = torch.from_numpy(rgb)
target = torch.from_numpy(rad)
input = input.type(torch.FloatTensor)
input = input.cuda()
target = target.cuda()
将tensor转化为numpy,转化为数值。当转化的时候要先转化为Tensor.cpu(),在转化为Tensor.numpy()
testLoss = testLoss.cpu().numpy()