Accuracy
It says Accuracy, but it actually hands you a count
- y_hat
- y
- accuracy
- count
CdlAccuracy is the "did the model get it right" checker for classification training loops. You feed it predictions and true labels, and it tells you how many matched. It's a tiny node, but it's worth reading the fine print before you wire it into a plot, because the output is not the 0-to-1 accuracy you're picturing.
What it does
This is a straight port of the accuracy(y_hat, y) helper from Dive into Deep Learning (d2l), which is what ComfyDL is built on. Given a batch of model outputs and a batch of ground-truth labels, it:
- if
y_hathas more than one column - i.e. it's raw logits or class probabilities - takesargmaxover dim 1 to turn each row into a predicted class index; - casts predictions to the label's dtype and compares element-wise;
- sums up the matches.
That's it. Both outputs are the same number: the count of correct predictions. The accuracy output is that count as a FLOAT; count is the same value as an INT. Nothing here divides by the batch size, so don't wire accuracy straight into a bar chart expecting a 0–1 fraction - you'd be charting how many, not how accurate. In the d2l codebase the division happens in the caller (evaluate_accuracy), and here you're the caller, so keep the batch size in mind if you want a ratio.
The inputs
Two slots, both cdlTensor - the custom tensor type ComfyDL uses to pass raw torch.Tensor objects between its own nodes:
y_hat- your model's output. A[batch, num_classes]tensor of logits/probabilities, or a[batch]tensor of already-decided labels.y- the true labels,[batch].
Where it fits
In a ComfyDL training workflow: run your forward pass, compute loss, feed y_hat and y here, and use the outputs for logging or for an early-stopping decision. It pairs naturally with the other ComfyDL/TorchOps nodes - CdlSquaredLoss for the loss, CdlGradClipping and CdlSgdStep for the update step - and it's the natural companion to the LeNet and ResNet examples in the README.
Installing it
CdlAccuracy ships with the ComfyDL pack, so install the whole pack once:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ./ComfyDL/requirements.txt
Then restart ComfyUI. ComfyUI Manager works too - search "ComfyDL" and install. The only extra dependency is matplotlib; torch and torchvision are already there through ComfyUI itself.
Gotchas
- The
accuracyoutput is a raw count, not a ratio - the most common beginner misread here. cdlTensorslots only accept outputs from other ComfyDL nodes, not a standard ComfyUIIMAGE. If you're coming from image-generation workflows and expect to drop a latent or image in here, that's not this node's job.- ComfyDL is a niche, educational pack (a learning tool built on d2l, not an image-generation suite), so you won't find much community discussion of it - the README and the example workflows are your best docs.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| y_hat | TENSOR | — | |
| y | TENSOR | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| accuracy | FLOAT | — |
| count | INT | — |