(sess, model, x_, y_)
return total_loss / data_len, total_acc / data_len
评估 val data 的准确率和损失
评估 val data 的准确率和损失
评估 val data 的准确率和损失
def evaluate(sess, model, x_, y_):
    """
    评估 val data 的准确率和损失
    """
    data_len = len(x_)
    batch_eval = batch_iter(x_, y_, 64)
    total_loss = 0.0
    total_acc = 0.0
    for x_batch, y_batch in batch_eval:
        batch_len = len(x_batch)
        feed_dict = {model.input_x: x_batch, model.input_y: y_batch,
                     model.keep_prob: 1}
        loss, acc = sess.run([model.loss, model.acc], feed_dict=feed_dict)
        total_loss += loss * batch_len
        total_acc += acc * batch_len

    return total_loss / data_len, total_acc / data_len
def evaluate ( sess , model , x_ , y_ ) : data_len = len ( x_ ) batch_eval = batch_iter ( x_ , y_ , 64 ) total_loss = 0.0 total_acc = 0.0 for x_batch , y_batch in batch_eval : batch_len = len ( x_batch ) feed_dict = { model . input_x : x_batch , model . input_y : y_batch , model . keep_prob : 1 } loss , acc = sess . run ( [ model . loss , model . acc ] , feed_dict = feed_dict ) total_loss += loss * batch_len total_acc += acc * batch_len return total_loss / data_len , total_acc / data_len