9766d2c13ddca10d5e45280450ee9cab649afb18,pytorch/cls_metrics.py,TopKAccuracy,update,#TopKAccuracy#Any#Any#,105
Before Change
pred_label = preds.cpu().numpy().astype(np.int32)
pred_label = np.argpartition(pred_label, -self.top_k)
label = labels.cpu().numpy().astype(np.int32)
assert (label.shape == pred_label.shape)
num_samples = pred_label.shape[0]
num_dims = len(pred_label.shape)
if num_dims == 1:
self.sum_metric += (pred_label.flat == label.flat).sum()
After Change
_, pred = preds.topk(k=self.top_k, dim=1, largest=True, sorted=True)
pred = pred.t()
correct = pred.eq(labels.view(1, -1).expand_as(pred))
num_correct = correct.view(-1).float().sum(dim=0, keepdim=True).item()
num_samples = labels.size(0)
assert (num_correct <= num_samples)
self.sum_metric += num_correct
self.global_sum_metric += num_correct
self.num_inst += num_samples
self.global_num_inst += num_samples
else:
assert(len(preds.shape) <= 2), "Predictions should be no more than 2 dims"
In pattern: SUPERPATTERN
Frequency: 6
Non-data size: 3
Instances
Project Name: osmr/imgclsmob
Commit Name: 9766d2c13ddca10d5e45280450ee9cab649afb18
Time: 2019-05-10
Author: osemery@gmail.com
File Name: pytorch/cls_metrics.py
Class Name: TopKAccuracy
Method Name: update
Project Name: reinforceio/tensorforce
Commit Name: 3441307d09545ca741396122e2ce83d56c7fcebc
Time: 2020-05-06
Author: alexkuhnle@t-online.de
File Name: test/test_parameters.py
Class Name: TestParameters
Method Name: float_unittest
Project Name: victoresque/pytorch-template
Commit Name: 6027fdf7aa77c038bf533ebcf7b704b1c79c3bc4
Time: 2018-09-16
Author: sunq0313@gmail.com
File Name: model/metric.py
Class Name:
Method Name: my_metric
Project Name: tensorflow/tensorboard
Commit Name: ba2ef0a2dac5881f37f81a55f17e18b7f9008416
Time: 2017-08-15
Author: wchargin@gmail.com
File Name: tensorboard/data_compat_test.py
Class Name: MigrateValueTest
Method Name: test_scalar
Project Name: asappresearch/sru
Commit Name: 6629a7801184d9ff646c266154a09e94d643c39d
Time: 2020-10-11
Author: hp@asapp.com
File Name: test/test_regression_2.py
Class Name:
Method Name: run
Project Name: asappresearch/sru
Commit Name: 2a15843223ac09c1331b1ca444da179ccab735d9
Time: 2020-10-07
Author: hp@asapp.com
File Name: test/test_regression_2.py
Class Name:
Method Name: run