def validate(net, val_data, ctx, loss, plot=False):
    metric = mtc.Accuracy()
    val_loss = 0
    ebs = []
    lbs = []
    for (i, batch) in enumerate(val_data):
        data = gluon.utils.split_and_load(batch[0], ctx_list=ctx, batch_axis=0, even_split=False)
        labels = gluon.utils.split_and_load(batch[1], ctx_list=ctx, batch_axis=0, even_split=False)
        ots = [net(X) for X in data]
        embedds = [ot[0] for ot in ots]
        outputs = [ot[1] for ot in ots]
        losses = [loss(yhat, y) for (yhat, y) in zip(outputs, labels)]
        metric.update(labels, outputs)
        val_loss += (sum([l.mean().asscalar() for l in losses]) / len(losses))
        if plot:
            for (es, ls) in zip(embedds, labels):
                assert (len(es) == len(ls))
                for idx in range(len(es)):
                    ebs.append(es[idx].asnumpy())
                    lbs.append(ls[idx].asscalar())
    if plot:
        ebs = np.vstack(ebs)
        lbs = np.hstack(lbs)
    (_, val_acc) = metric.get()
    return (val_acc, (val_loss / len(val_data)), ebs, lbs)
def validate(net, val_data, ctx, loss, plot=False):
    metric = mtc.Accuracy()
    val_loss = 0
    ebs = []
    lbs = []
    for (i, batch) in enumerate(val_data):
        data = gluon.utils.split_and_load(batch[0], ctx_list=ctx, batch_axis=0, even_split=False)
        labels = gluon.utils.split_and_load(batch[1], ctx_list=ctx, batch_axis=0, even_split=False)
        ots = [net(X) for X in data]
        embedds = [ot[0] for ot in ots]
        outputs = [ot[1] for ot in ots]
        losses = [loss(yhat, y) for (yhat, y) in zip(outputs, labels)]
        metric.update(labels, outputs)
        val_loss += (sum([l.mean().asscalar() for l in losses]) / len(losses))
        if plot:
            for (es, ls) in zip(embedds, labels):
                assert (len(es) == len(ls))
                for idx in range(len(es)):
                    ebs.append(es[idx].asnumpy())
                    lbs.append(ls[idx].asscalar())
    if plot:
        ebs = np.vstack(ebs)
        lbs = np.hstack(lbs)
    (_, val_acc) = metric.get()
    return (val_acc, (val_loss / len(val_data)), ebs, lbs)