You would need to convert the PIL images to a Tensor. There is an inbuilt function in pytorch that does this, which is shown below.
dataset = torchvision.datasets.MNIST("data_nn/",transform=torchvision.transforms.ToTensor()) 

Also change the data loader part as shown below:
for step,(img,label) in enumerate(data_loader):
    print(img.shape)