code: def ohem_single(score, gt_text, training_mask):
      # online hard example mining
  
      pos_num = int(paddle.sum(gt_text > 0.5)) - int(
          paddle.sum((gt_text > 0.5) & (training_mask <= 0.5))
      )
  
      if pos_num == 0:
          # selected_mask = gt_text.copy() * 0 # may be not good
          selected_mask = training_mask
          selected_mask = paddle.cast(
              selected_mask.reshape(
                  (1, selected_mask.shape[0], selected_mask.shape[1])
              ),
              "float32",
          )
          return selected_mask
  
      neg_num = int(
          paddle.sum((gt_text <= 0.5) & (training_mask > 0.5))
      )
      neg_num = int(min(pos_num * 3, neg_num))
  
      if neg_num == 0:
          selected_mask = training_mask
          selected_mask = paddle.cast(
              selected_mask.reshape(
                  (1, selected_mask.shape[0], selected_mask.shape[1])
              ),
              "float32",
          )
          return selected_mask
  
      # hard example
      neg_score = score[(gt_text <= 0.5) & (training_mask > 0.5)]
      neg_score_sorted = paddle.sort(-neg_score)
      threshold = -neg_score_sorted[neg_num - 1]
  
      selected_mask = ((score >= threshold) | (gt_text > 0.5)) & (
          training_mask > 0.5
      )
      selected_mask = paddle.cast(
          selected_mask.reshape(
              (1, selected_mask.shape[0], selected_mask.shape[1])
          ),
          "float32",
      )
      return selected_mask
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  from paddle import nn
  import paddle.nn.functional
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: ohem_single(score, gt_text, training_mask) and returns: selected_mask, selected_mask, selected_mask