Closed YicunDuanUMich closed 2 months ago
Hi! thanks for your contribution!, great first issue!
Hi @YicunDuanUMich, sorry for the late reply.
I am pretty sure that the bug you are seeing was fixes in later versions of torchmetrics. In particular I think this PR probably contains the solution for your issues: https://github.com/Lightning-AI/torchmetrics/pull/2571.
Just as an example, here is a script that initializes the classification metric precision with both average="macro"
and average="weighted"
e.g. two metric where there states are the same and they only differ how values are aggregated in the end.
import torchmetrics
import torch
collection = torchmetrics.MetricCollection({
"micro_precision": torchmetrics.Precision(task="multiclass", average='weighted', num_classes=3),
"macro_precision": torchmetrics.Precision(task="multiclass", average='macro', num_classes=3),
})
for _ in range(3):
x = torch.randn(10, 3).softmax(dim=1)
y = torch.randint(0, 3, (10,))
collection.update(x, y)
out = collection.compute()
print(out)
In v0.11.3 of torchmetrics I am seeing somewhat the same behavior you are describing, that the second metric is not being updated correctly. However in the newest version of torchmetrics things are working as expected. Therefore, please update to the newest version of torchmetrics. Closing issue.
🐛 Bug
When I use
MetricCollection
to store similar metrics, thecompute_groups
feature will automatically merge the states without any warning. I have two similar metrics "star classification accuracy" and "galaxy classification accuracy" whose only difference is a string attributesource_type_filter
("star"
v.s."galaxy"
) which instructs them to conduct different filter behaviors. During validation, i find that "star classification accuracy" is always equal to "galaxy classification accuracy" becauseMetricCollection
merges their states.To Reproduce
I attach my hydra config file here to show my env:
Expected behavior
The default value of
compute_groups
inMetricCollection
isFalse
Environment
conda
,pip
, build from source): 0.11.3Additional context