If you are working with a rather small dataset, you could load all images and pass it as a single batch.
However, usually your data is too large to be loaded all at once or passed into the model together, so you could just store the results in a list and call concatenate it after the DataLoader loop.
Assuming you don’t need to backprop on your cosine loss, something like this should work:
outputs = []
with torch.no_grad():
    for data, target in loader:
        output = model(data)
        outputs.append(output.detach())
outputs = torch.cat(outputs)