import torch
# import our library
import torchmetrics 

# initialize metric
metric = torchmetrics.Accuracy()

n_batches = 10
for i in range(n_batches):
    # simulate a classification problem
    preds = torch.randn(10, 5)#.softmax(dim=-1)
    target = torch.randint(5, (10,))

    # metric on current batch
    acc = metric(preds, target)
    print(f"Accuracy on batch {i}: {acc}")    

# metric on all batches using custom accumulation
acc = metric.compute()
print(f"Accuracy on all data: {acc}")
598eb6f9deec6a20ac313d1726cd0c54e6c85b94
<mask token>

<mask token>
for i in range(n_batches):
    preds = torch.randn(10, 5)
    target = torch.randint(5, (10,))
    acc = metric(preds, target)
    print(f'Accuracy on batch {i}: {acc}')
<mask token>
print(f'Accuracy on all data: {acc}')

<mask token>
metric = torchmetrics.Accuracy()
n_batches = 10
for i in range(n_batches):
    preds = torch.randn(10, 5)
    target = torch.randint(5, (10,))
    acc = metric(preds, target)
    print(f'Accuracy on batch {i}: {acc}')
acc = metric.compute()
print(f'Accuracy on all data: {acc}')

import torch
import torchmetrics
metric = torchmetrics.Accuracy()
n_batches = 10
for i in range(n_batches):
    preds = torch.randn(10, 5)
    target = torch.randint(5, (10,))
    acc = metric(preds, target)
    print(f'Accuracy on batch {i}: {acc}')
acc = metric.compute()
print(f'Accuracy on all data: {acc}')

import torch
# import our library
import torchmetrics 

# initialize metric
metric = torchmetrics.Accuracy()

n_batches = 10
for i in range(n_batches):
    # simulate a classification problem
    preds = torch.randn(10, 5)#.softmax(dim=-1)
    target = torch.randint(5, (10,))

    # metric on current batch
    acc = metric(preds, target)
    print(f"Accuracy on batch {i}: {acc}")    

# metric on all batches using custom accumulation
acc = metric.compute()
print(f"Accuracy on all data: {acc}")