acc

paddle.distributed.fleet.metrics.metric. acc ( correct, total, scope=None, util=None ) [source]

distributed accuracy in fleet

Parameters
  • correct (numpy.array|Variable|string) – correct Variable

  • total (numpy.array|Variable) – total Variable

  • scope (Scope) – specific scope

Returns

accuracy value

Return type

acc(float)

Example

# in model.py
correct = fluid.layers.create_global_var(dtype='float32', shape=[1], value=0)
total = fluid.layers.create_global_var(dtype='float32', shape=[1], value=0)
acc = fluid.layers.acc(predict, label, k=1, correct=correct, total=total)

global_correct = fluid.layers.create_global_var(persistable=True, dtype='float32', shape=[1], value=0)
tmp1 = fluid.layers.elementwise_min(correct, global_correct)
fluid.layers.assign(tmp1, global_correct)

global_total = fluid.layers.create_global_var(persistable=True, dtype='float32', shape=[1], value=0)
tmp2 = fluid.layers.elementwise_min(total, global_total)
fluid.layers.assign(tmp2, global_total)

# in train.py, after train or infer
correct_num = np.array(scope.find_var(correct.name).get_tensor())
total_num = np.array(scope.find_var(total.name).get_tensor())
print("accuracy: ", paddle.distributed.fleet.acc(correct_num, total_num))