Dear Alban, thanks very much for your time and guidance. I have been able to figure it out. It was just a syntax problem. I changed the first line as shown below and it works
 for i, data in enumerate(test_loader): 
    
        x, y_true = data 

        if torch.cuda.is_available():
         x, y_true = x.cuda(), y_true.cuda()
        out = model(x)
        out = F.softmax(out, dim=1)
        loss = criterion(out, y_true)
       

Before, I had written the first line as
 for  data in enumerate(test_loader):  

and this way is wrong