code: def cal_predicts_accuracy(
      char_ops,
      preds,
      preds_lod,
      labels,
      labels_lod,
      is_remove_duplicate=False,
  ):
      """
      Calculate prediction accuracy
      Args:
          char_ops: CharacterOps
          preds: preds result,text index
          preds_lod: lod tensor of preds
          labels: label of input image, text index
          labels_lod:  lod tensor of label
          is_remove_duplicate: Whether to remove duplicate characters,
                                   The default is False
      Return:
          acc: The accuracy of test set
          acc_num: The correct number of samples predicted
          img_num: The total sample number of the test set
      """
      acc_num = 0
      img_num = 0
      for ino in range(len(labels_lod) - 1):
          beg_no = preds_lod[ino]
          end_no = preds_lod[ino + 1]
          preds_text = preds[beg_no:end_no].reshape(-1)
          preds_text = char_ops.decode(preds_text, is_remove_duplicate)
  
          beg_no = labels_lod[ino]
          end_no = labels_lod[ino + 1]
          labels_text = labels[beg_no:end_no].reshape(-1)
          labels_text = char_ops.decode(
              labels_text, is_remove_duplicate
          )
          img_num += 1
  
          if preds_text == labels_text:
              acc_num += 1
      acc = acc_num * 1.0 / img_num
      return acc, acc_num, img_num
  
file_path: PaddleHub/modules/image/text_recognition/chinese_ocr_db_crnn_server/character.py
imports: import string
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: cal_predicts_accuracy(char_ops, preds, preds_lod, labels, labels_lod, is_remove_duplicate) and returns: acc,  acc_num,  img_num