You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtorchfromtorchmetricsimportMetricclassMyAccuracy(Metric):
def__init__(self):
# remember to call supersuper().__init__()
# call `self.add_state`for every internal state that is needed for the metrics computations# dist_reduce_fx indicates the function that should be used to reduce# state from multiple processesself.add_state("correct", default=torch.tensor(0), dist_reduce_fx="sum")
self.add_state("total", default=torch.tensor(0), dist_reduce_fx="sum")
defupdate(self, preds: torch.Tensor, target: torch.Tensor) ->None:
# extract predicted class index for computing accuracypreds=preds.argmax(dim=-1)
assertpreds.shape==target.shape# update metric statesself.correct+=torch.sum(preds==target)
self.total+=target.numel()
defcompute(self) ->torch.Tensor:
# compute final resultreturnself.correct.float() /self.totalmy_metric=MyAccuracy()
preds=torch.randn(10, 5).softmax(dim=-1)
target=torch.randint(5, (10,))
print(my_metric(preds, target))
The text was updated successfully, but these errors were encountered:
https://github.com/layer6ai-labs/dgm-eval/blob/master/dgm_eval/metrics/fd.py
structure
The text was updated successfully, but these errors were encountered: