3a770cbc97085c2cd4eaa0a46b2bc037f35389c2,utils.py,,evaluate_accuracy,#Any#Any#Any#,77

Before Change


        data, label = _get_batch(batch, ctx)
        output = net(data)
        acc += accuracy(output, label)
    return acc / (i+1)

def train(train_data, test_data, net, loss, trainer, ctx, num_epochs, print_batches=None):
    Train a network
    for epoch in range(num_epochs):

After Change


    for batch in data_iterator:
        data, label, batch_size = _get_batch(batch, ctx)
        for X, y in zip(data, label):
            acc += nd.sum(net(X).argmax(axis=1)==y).copyto(mx.cpu())
        acc.wait_to_read() // don"t push too many operators into backend
        n += batch_size
    return acc.asscalar() / n
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: d2l-ai/d2l-zh
Commit Name: 3a770cbc97085c2cd4eaa0a46b2bc037f35389c2
Time: 2017-10-25
Author: muli@cs.cmu.edu
File Name: utils.py
Class Name:
Method Name: evaluate_accuracy


Project Name: dmlc/gluon-nlp
Commit Name: e137b24f4e7350342d0e7a2686e166bf378a405b
Time: 2020-09-02
Author: xshiab@connect.ust.hk
File Name: tests/test_models.py
Class Name:
Method Name: test_get_backbone


Project Name: dmlc/gluon-nlp
Commit Name: 02c0ef855321a2c9e681927b9cdaf0996c310893
Time: 2020-10-14
Author: xshiab@connect.ust.hk
File Name: tests/test_models.py
Class Name:
Method Name: test_get_backbone