'int' object has no attribute 'size'"
F.nll_loss: I am getting 


  AttributeError: 'int' object has no attribute 'size'


when I try to run this code. I also get a snippet of the module code.


  raise ValueError('Expected 2 or more dimensions (got {})'.format(dim))
      if input.size(0) != target.size(0):
        raise ValueError('Expected input batch_size ({}) to match target batch_size ({}).'
        format(input.size(0), target.size(0)))


import torch
from torchvision import transforms, datasets
import torch.nn as nn
import torch.nn.functional as F
import matplotlib.pylab as plt

train_dataset = datasets.MNIST(root = '', train =True, download = True,
                                transform =transforms.Compose([transforms.ToTensor()]))

test_dataset = datasets.MNIST(root ='', download =True, train =False,
                               transform =transforms.Compose([transforms.ToTensor()]))
batch_size = 10
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size, shuffle =True)

test_dataset = torch.utils.data.DataLoader(test_dataset, batch_size, shuffle =True)
class Net(nn.Module):

  def __init__(self):
    super().__init__()
    self.fc1 = nn.Linear(28*28, 64)
    self.fc2 = nn.Linear(64,64)
    self.fc3 = nn.Linear(64,64)
    self.fc4 = nn.Linear(64,10)

  def forward(self, x):
      x = F.relu(self.fc1(x))
      x = F.relu(self.fc2(x))
      x = F.relu(self.fc2(x))
      x = self.fc4(x)
      return F.log_softmax(x, dim=1)

x=torch.rand((28,28))
x=x.view(-1,28*28)
net =Net()
out=net(x)
out
import torch.optim as optim

optimizer =optim.Adam(net.parameters(), lr=0.001)

EPOCHS = 3
for epoch in range(EPOCHS):
  for data in train_dataset:
      x, y = data
      net.zero_grad()
      x=x.view(-1, 28*28)
      output = net(x)
      loss = F.nll_loss(output, y)
      loss.backward()
      optimizer.step()
  print(loss)


Just change the for loop from:

for data in train_dataset:


to 

for data in train_loader:

