This is the code:
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
import torchvision.transforms as transforms
import torch.optim as optim
dev = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")

batch_size = 5  
learning_rate = 0.001
num_epoch = 10
num_classes = 10

transform = transforms.Compose(
    [transforms.ToTensor(),
     transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
                                        download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size,
                                          shuffle=True, num_workers=1)

testset = torchvision.datasets.CIFAR10(root='./data', train=False,
                                       download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=batch_size,
                                         shuffle=False, num_workers=1)

classes = ('plane', 'car', 'bird', 'cat','deer', 'dog', 'frog', 'horse', 'ship', 'truck')


Net = torchvision.models.resnet18(pretrained=True)
net = Net().to(dev)


criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=learning_rate, momentum=0.9)  

for epoch in range(10):
    for i, data in enumerate(trainloader, 0): 
        inputs, labels = data
        inputs, labels = inputs.to(dev), labels.to(dev)
        outputs = net(inputs)
        loss = criterion(outputs, labels)  
        outputs = net(inputs) 
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()        
correct = 0
total = 0
for data in testloader:
    inputs, labels = data
    inputs, labels = inputs.to(dev), labels.to(dev) 
    outputs = net(inputs)
    _, predicted = torch.max(outputs.data, 1)
    total += labels.size(0)
    correct += (predicted == labels).sum()

print('Accuracy of the network on the 10000 test images: %d %%' % (
    100 * correct / total))