I implemented the code like below:
class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()

        self.conv = nn.Sequential(
            nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(kernel_size=2))

        self.dense = nn.Sequential(
            nn.Linear(16*16*128, 1024),
            nn.ReLU(),
            nn.Dropout(p=0.5),
            nn.Linear(1024, 10)
        )

    def forward(self, input):
        output = self.conv(input)
        output = output.view(-1, 16*16*128)
        output = self.dense(output)

        return output

model = Model()
print(model)

cost = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters())

n_epochs = 5

for epoch in range(n_epochs):
    running_loss = 0.0
    running_correct = 0
    print("Epoch {}/{}".format(epoch, n_epochs))
    print("-" * 10)
    for data in data_loader_train:
        images, labels = data
        images, labels = Variable(images), Variable(labels)
        outputs = model(images)
        _,pred = torch.max(outputs.data, 1)
        optimizer.zero_grad()
        loss = cost(outputs, labels)
        print(loss)

        loss.backward()
        optimizer.step()
        running_loss += loss.data.item()
        running_correct += torch.sum(pred == labels.data)
    
    testing_correct = 0
    for data in data_loader_test:
        images, labels = data
        images, labels = Variable(images), Variable(labels)
        outputs = model(images)
        _,pred = torch.max(outputs.data, 1)
        testing_correct += torch.sum(pred == labels.data)
    print("Loss is:{:.4f}, Train Accuracy is:{:.4f}%, Test Accuracy is:{:.4f}".format(running_loss/len(data_train), 100*running_correct/len(data_train), 100*testing_correct/len(data_test)))

But I got the error code like this(line 94 is loss = cost(outputs, labels)):
RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed.  at C:\w\1\s\tmp_conda_3.7_055457\conda\conda-bld\pytorch_1565416617654\work\aten\src\THNN/generic/ClassNLLCriterion.c:94

How can I solve this problem? Could you help me? Thank you!