def evaluate(model, dataloader):
    score = 0
    V_loss = 0
    upper_bound = 0
    num_data = 0
    for (v, b, q, a) in iter(dataloader):
        v = Variable(v, volatile=True).cuda()
        b = Variable(b, volatile=True).cuda()
        q = Variable(q, volatile=True).cuda()
        a = Variable(a, volatile=True).cuda()
        pred = model(v, b, q, None)
        loss = instance_bce_with_logits(pred, a)
        V_loss += (loss.data[0] * v.size(0))
        batch_score = compute_score_with_logits(pred, a.data).sum()
        score += batch_score
        upper_bound += a.max(1)[0].sum()
        num_data += pred.size(0)
    score = (score / len(dataloader.dataset))
    V_loss /= len(dataloader.dataset)
    upper_bound = (upper_bound / len(dataloader.dataset))
    return (score, upper_bound, V_loss)
def evaluate(model, dataloader):
    score = 0
    V_loss = 0
    upper_bound = 0
    num_data = 0
    for (v, b, q, a) in iter(dataloader):
        v = Variable(v, volatile=True).cuda()
        b = Variable(b, volatile=True).cuda()
        q = Variable(q, volatile=True).cuda()
        a = Variable(a, volatile=True).cuda()
        pred = model(v, b, q, None)
        loss = instance_bce_with_logits(pred, a)
        V_loss += (loss.data[0] * v.size(0))
        batch_score = compute_score_with_logits(pred, a.data).sum()
        score += batch_score
        upper_bound += a.max(1)[0].sum()
        num_data += pred.size(0)
    score = (score / len(dataloader.dataset))
    V_loss /= len(dataloader.dataset)
    upper_bound = (upper_bound / len(dataloader.dataset))
    return (score, upper_bound, V_loss)