The first thing you need to do is to separate your dataset into a training, validation and test set. For each of these you create a loader exactly like you’ve done for the training loader. Assuming you’ve done that and have a training_loader, validation_loader, and test_loader, you could then define a separate function to check the accuracy which will be general in the way that you just need to send in the loader you’ve created.
This could look something like this:
def check_accuracy(loader, model):
    num_correct = 0
    num_samples = 0
    model.eval()
    
    with torch.no_grad():
        for x, y in loader:
            x = x.to(device=device)
            y = y.to(device=device)
            
            scores = model(x)
            _, predictions = scores.max(1)
            num_correct += (predictions == y).sum()
            num_samples += predictions.size(0)
        
        print(f'Got {num_correct} / {num_samples} with accuracy {float(num_correct)/float(num_samples)*100:.2f}') 
    
    model.train()

Where you need to have defined device, but you could also send this to the function.