def evaluate_accuracy(data_iterator, net, ctx, loss_fun, num_classes):
    """
    This function is used for evaluating accuracy of
    a given data iterator. (Either Train/Test data)
    It takes in the loss function used too!
    """
    acc = mx.metric.Accuracy()
    loss_avg = 0.
    for i, ((data, length), label) in enumerate(data_iterator):
        data = data.as_in_context(ctx)  # .reshape((-1,784))
        length = length.astype('float32').as_in_context(ctx)
        label = label.as_in_context(ctx)
        output = net(data, length)
        loss = loss_fun(output, label)
        preds = []
        if num_classes == 2:
            preds = (nd.sign(output) + 1) / 2
            preds = preds.reshape(-1)
        else:
            preds = nd.argmax(output, axis=1)
        acc.update(preds=preds, labels=label)
        loss_avg = loss_avg * i / (i + 1) + nd.mean(loss).asscalar() / (i + 1)
    return acc.get()[1], loss_avg
This function is used for evaluating accuracy of
    a given data iterator. (Either Train/Test data)
    It takes in the loss function used too!