I am getting this error while visualizing the data
This is how I have loaded the data.
num_classes = 2
batch_size = 13
net=CNN(out_1=13, out_2=32)

DATA_PATH_TRAIN ="F:/project/d2"
DATA_PATH_TEST ="F:/project/d2"


trans = transforms.Compose([
    transforms.ToTensor(),
    #transforms.Resize((100, 100))
    ])

train_dataset = datasets.ImageFolder(root=DATA_PATH_TRAIN, transform=trans)
train_loader = DataLoader(dataset=train_dataset, batch_size=batch_size, shuffle=True)
validation_dataset=train_dataset
validation_loader = DataLoader(dataset=validation_dataset, batch_size=batch_size, shuffle=True)

criterion = nn.CrossEntropyLoss()
learning_rate = 0.001
optimizer = torch.optim.Adam(net.parameters(), lr = learning_rate)


Function for Visualizing
class_names = ["not a face","face"]

def visualize_model(net, num_images=6):
    was_training = net.training
    net.eval()
    images_so_far = 0
    fig = plt.figure()

    with torch.no_grad():
        for i, (inputs, labels) in enumerate(validation_loader):

            outputs = net(inputs)
            _, preds = torch.max(outputs, 1)

            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(class_names[preds[j]]))
                imshow(inputs.data[j])

                if images_so_far == num_images:
                    net.train(mode=was_training)
                    return
        net.train(mode=was_training)

my function for imshow
def imshow(img):
    #img = img / 2 + 0.5 
    plt.imshow(np.transpose(img[0].numpy(), (1, 2, 0)))
    plt.show()

def main():
    dataiter = iter(train_loader)
    images, labels = dataiter.next()
    imshow(images)
    print(labels)

if __name__ == "__main__":
    main()

I am getting proper output for this imshow after loading my data
as shown in the image below…

imshow.jpg1171×747 89.1 KB

I am also getting label for that particular image…