Actually the function is like:
def visualize_model(model, num_images=6):
images_so_far = 0
fig = plt.figure()
for i, data in enumerate(dset_loaders['val']):
    inputs, labels = data
    if use_gpu:
        inputs, labels = Variable(inputs.cuda()), Variable(labels.cuda())
    else:
        inputs, labels = Variable(inputs), Variable(labels)

    outputs = model(inputs)
    _, preds = torch.max(outputs.data, 1)
    
    #preds = (preds).data.cpu().numpy()
    
    for j in range(inputs.size()[0]):
        images_so_far += 1
        ax = plt.subplot(num_images//2, 2, images_so_far)
        ax.axis('off')
        ax.set_title('predicted: {}'.format(dset_classes[preds[j]]))
        (Variable(j).data).cpu().numpy()
        imshow(inputs.cpu().data[j])

        if images_so_far == num_images:
            return

While calling visualize_model(model_ft) at the end to see the output running in GPU it is throwing the error:

TypeError                                 Traceback (most recent call last)
 in ()
----> 1 visualize_model(model_ft)
 in visualize_model(model, num_images)
19             ax = plt.subplot(num_images//2, 2, images_so_far)
20             ax.axis(‘off’)
—> 21             ax.set_title(‘predicted: {}’.format(dset_classes[preds[j]]))
22             (Variable(j).data).cpu().numpy()
23             imshow(inputs.cpu().data[j])
TypeError: list indices must be integers, not torch.cuda.LongTensor