Any body know about confusion matrix calculation for cnn model

losses=[]
accuracy=[]
for epoch in range(epochs):
epoch_loss = 0.0
epoch_accuracy = 0.0

for features, labels in train_data:
    outputs = model(features)
    loss = criterion(outputs, labels)
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    epoch_loss += loss.item() # here we are accumulating loss for each training batch.
    epoch_accuracy += (outputs.argmax(1) == labels).float().mean()

losses.append(epoch_loss/batches)
accuracy.append(epoch_accuracy/batches)   
print(f'Epoch: {epoch} -> Loss: {(epoch_loss/batches):.8f}, Accuracy: {(epoch_accuracy/batches):.8f}')

You could use the sklearn implementation or the code from this post.