Skip to content
Discussion options

You must be logged in to vote

@Northo's workaround above is on the right track — manually computing and logging the dict works. Let me add a bit more context on why and provide a clean pattern you can reuse.

Why self.log doesn't work directly with ClasswiseWrapper:
Lightning's self.log expects either a scalar Tensor or a Metric whose .compute() returns a scalar. ClasswiseWrapper.compute() returns a dict[str, Tensor], so Lightning doesn't know how to handle it. This isn't a bug per se — it's a design mismatch between Lightning's logging and per-class metrics.

Recommended pattern (TorchMetrics >= v1.9.0):

Use ClasswiseWrapper inside a MetricCollection, then log the whole collection with self.log_dict:

from torchmetrics i…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@patrontheo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Northo
Comment options

Answer selected by Borda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants