Prediction error while generating confusion matrix

Hi, after trying a couple of solutions I am getting two errors. I have my defined and all the simulation runs correctly. The problem appears just while evaluation of the code with a confusion matrix in this piece of code:

heatmap of confusion matrix

truelabels = []
predictions = []
print(“Getting predictions from test set…”)
for data, target in test_loader:
data = data.cpu().numpy()
#, dtype=torch.cuda.float)
# data, target =,
# data = torch.from_numpy(data).float().to(‘cuda’)
# target = target
for label in target.numpy():
for prediction in model(data).data.argmax(1):


I m getting either this. I tried to put it,
then I also tried to put data.cpu.numpy(), but nothing really works… I would be greatful for any help

RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same.
TypeError: conv2d(): argument ‘input’ (position 1) must be Tensor, not numpy.ndarray


In calss function:
def forward(self,x):


x =x.cuda()

and adding
for prediction in model(data).data.**cpu().**numpy().argmax(1):