def evaluate(sess, env, X_data, y_data, batch_size=128):
    """
    Evaluate TF model by running env.loss and env.acc.
    """

    n_sample = X_data.shape[0]
    n_batch = int((n_sample + batch_size - 1) / batch_size)
    loss, acc, avg_acc = 0, 0, 0

    for batch in range(n_batch):
        # print(' batch {0}/{1}'.format(batch + 1, n_batch), end='\r')
        start = batch * batch_size
        end = min(n_sample, start + batch_size)
        cnt = end - start
        batch_loss, batch_acc, batch_avg_acc = sess.run(
            [env.loss, env.acc, env.avg_acc], feed_dict={env.x: X_data[start:end], env.y: y_data[start:end]}
        )

        loss += batch_loss * cnt
        acc += batch_acc * cnt
        avg_acc += batch_avg_acc * cnt

    loss /= n_sample
    acc /= n_sample
    avg_acc /= n_sample

    # print(' loss: {0:.4f} acc: {1:.4f}'.format(loss, acc))
    return loss, acc, avg_acc