def evaluate(dataloader):
total_L = <NUM_LIT:0.0><EOL>total_sample_num = <NUM_LIT:0><EOL>total_correct_num = <NUM_LIT:0><EOL>start_log_interval_time = time.time()<EOL>print('<STR_LIT>')<EOL>for i, ((data, valid_length), label) in enumerate(dataloader):<EOL><INDENT>data = mx.nd.transpose(data.as_in_context(context))<EOL>valid_length = valid_length.as_in_context(context).astype(np.float32)<EOL>label = label.as_in_context(context)<EOL>output = net(data, valid_length)<EOL>L = loss(output, label)<EOL>pred = (output > <NUM_LIT:0.5>).reshape((-<NUM_LIT:1>,))<EOL>total_L += L.sum().asscalar()<EOL>total_sample_num += label.shape[<NUM_LIT:0>]<EOL>total_correct_num += (pred == label).sum().asscalar()<EOL>if (i + <NUM_LIT:1>) % args.log_interval == <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>'.format(<EOL>i + <NUM_LIT:1>, len(dataloader), time.time() - start_log_interval_time))<EOL>start_log_interval_time = time.time()<EOL><DEDENT><DEDENT>avg_L = total_L / float(total_sample_num)<EOL>acc = total_correct_num / float(total_sample_num)<EOL>return avg_L, acc<EOL>
Evaluate network on the specified dataset