在infer的时候,metrics.Auc和layers.auc得出的auc值相差10个百分点
Created by: minhozhou
- 版本、环境信息:
1)PaddlePaddle版本:1.4.1
2)CPU
3)系统环境:centos
-预测信息
1)使用
fluid.io.load_persistables
进行加载预测 - 问题描述:在infer的时候,metrics.Auc比layers.auc得出的auc值低10个百分点
- auc预测代码:
在网络中的auc定义为
auc_var, batch_auc_var, auc_states = layers.auc(input=fc, label=self.datas[-1])
infer_program = fluid.default_main_program().clone(for_test=True)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
fluid.io.load_persistables(exe, args.model_output_dir + '/pass-', infer_program)
inference_scope = fluid.Scope()
def set_zero(var_name):
param = inference_scope.var(var_name).get_tensor()
param_array = np.zeros(param._get_dims()).astype("int64")
param.set(param_array, place)
for auc_state in auc_states:
set_zero(auc_state.name)
batch_id = 0
py_reader.start()
while True:
try:
results, auc_val = exe.run(infer_program, fetch_list=[cost, auc_var])
if batch_id % 100 == 0:
logger.info("TEST --> batch: {} loss:{} auc:{}".format(batch_id, results, auc_val))
except fluid.core.EOFException:
py_reader.reset()
break
2.Auc预测代码
infer_program = fluid.default_main_program().clone(for_test=True)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
fluid.io.load_persistables(exe, args.model_output_dir + '/pass-', infer_program)
batch_id = 0
py_reader.start()
auc_metric = fluid.metrics.Auc("ROC")
while True:
try:
results, y_pred, y_true = exe.run(infer_program, fetch_list=[cost, preds, label])
auc_metric.update(y_pred, y_true)
if batch_id % 100 == 0:
logger.info("TEST --> batch: {} loss:{} auc:{}".format(batch_id, results, auc_metric.eval()))
except fluid.core.EOFException:
py_reader.reset()
break