docstr: Translate probability heatmap tensor to text region boudning boxes.
  
  Parameters
  ----------
  image_tensor : torch.tensor
      Image tensor.
  original_shapes : tuple
      Original size of the image (height, width) of the input image (before
      rounded to the closest multiple of 32).
  hmap : torch.tensor
      Probability heatmap tensor.
  text_threshold : float, optional
      Minimum probability for each pixel of heatmap tensor to be considered
      as a valid text pixel. The default is 0.2.
  bbox_min_score : float, optional
      Minimum score for each detected bounding box to be considered as a
      valid text bounding box. The default is 0.2.
  bbox_min_size : int, optional
      Minimum size for each detected bounding box to be considered as a
      valid text bounding box. The default is 3.
  max_candidates : int, optional
      Maximum number of detected bounding boxes to be considered as 
      candidates for valid text bounding box. Setting it to 0 implies
      no maximum. The default is 0.
  as_polygon : boolean, optional
      If True, return the bounding box as polygon (fine vertrices), 
      otherwise return as rectangular. The default is False.
  
  Returns
  -------
  boxes_batch : list of lists
      Bounding boxes of each text box.
  scores_batch : list of floats
      Confidence scores of each text box.
docstr_tok: ["Translate","probability","heatmap","tensor","to","text","region","boudning","boxes",".","Parameters","--","--","--","--","--","image_tensor",":","torch.tensor","Image","tensor",".","original_shapes",":","tuple","Original","size","of","the","image","(","height",",","width",")","of","the","input","image","(","before","rounded","to","the","closest","multiple","of","32",")",".","hmap",":","torch.tensor","Probability","heatmap","tensor",".","text_threshold",":","float",",","optional","Minimum","probability","for","each","pixel","of","heatmap","tensor","to","be","considered","as","a","valid","text","pixel",".","The","default","is","0.2.","bbox_min_score",":","float",",","optional","Minimum","score","for","each","detected","bounding","box","to","be","considered","as","a","valid","text","bounding","box",".","The","default","is","0.2.","bbox_min_size",":","int",",","optional","Minimum","size","for","each","detected","bounding","box","to","be","considered","as","a","valid","text","bounding","box",".","The","default","is","3.","max_candidates",":","int",",","optional","Maximum","number","of","detected","bounding","boxes","to","be","considered","as","candidates","for","valid","text","bounding","box",".","Setting","it","to","0","implies","no","maximum",".","The","default","is","0.","as_polygon",":","boolean",",","optional","If","True",",","return","the","bounding","box","as","polygon","(","fine","vertrices",")",",","otherwise","return","as","rectangular",".","The","default","is","False",".","Returns","--","--","--","-","boxes_batch",":","list","of","lists","Bounding","boxes","of","each","text","box",".","scores_batch",":","list","of","floats","Confidence","scores","of","each","text","box","."]
code: def hmap2bbox(
      self,
      image_tensor,
      original_shapes,
      hmap,
      text_threshold=0.2,
      bbox_min_score=0.2,
      bbox_min_size=3,
      max_candidates=0,
      as_polygon=False,
  ):
      """
      Translate probability heatmap tensor to text region boudning boxes.
  
      Parameters
      ----------
      image_tensor : torch.tensor
          Image tensor.
      original_shapes : tuple
          Original size of the image (height, width) of the input image (before
          rounded to the closest multiple of 32).
      hmap : torch.tensor
          Probability heatmap tensor.
      text_threshold : float, optional
          Minimum probability for each pixel of heatmap tensor to be considered
          as a valid text pixel. The default is 0.2.
      bbox_min_score : float, optional
          Minimum score for each detected bounding box to be considered as a
          valid text bounding box. The default is 0.2.
      bbox_min_size : int, optional
          Minimum size for each detected bounding box to be considered as a
          valid text bounding box. The default is 3.
      max_candidates : int, optional
          Maximum number of detected bounding boxes to be considered as
          candidates for valid text bounding box. Setting it to 0 implies
          no maximum. The default is 0.
      as_polygon : boolean, optional
          If True, return the bounding box as polygon (fine vertrices),
          otherwise return as rectangular. The default is False.
  
      Returns
      -------
      boxes_batch : list of lists
          Bounding boxes of each text box.
      scores_batch : list of floats
          Confidence scores of each text box.
  
      """
      segmentation = self.binarize(hmap, threshold=text_threshold)
      boxes_batch = []
      scores_batch = []
      for batch_index in range(image_tensor.size(0)):
          height, width = original_shapes[batch_index]
          if as_polygon:
              boxes, scores = self.polygons_from_bitmap(
                  hmap[batch_index],
                  segmentation[batch_index],
                  width,
                  height,
                  bbox_min_score=bbox_min_score,
                  bbox_min_size=bbox_min_size,
                  max_candidates=max_candidates,
              )
          else:
              boxes, scores = self.boxes_from_bitmap(
                  hmap[batch_index],
                  segmentation[batch_index],
                  width,
                  height,
                  bbox_min_score=bbox_min_score,
                  bbox_min_size=bbox_min_size,
                  max_candidates=max_candidates,
              )
  
          boxes_batch.append(boxes)
          scores_batch.append(scores)
  
      boxes_batch, scores_batch = zip(
          *[
              zip(
                  *[
                      (box, score)
                      for (box, score) in zip(boxes, scores)
                      if score > 0
                  ]
              )
              if any(scores > 0)
              else [(), ()]
              for (boxes, scores) in zip(boxes_batch, scores_batch)
          ]
      )
  
      return boxes_batch, scores_batch
  
imports: import os
  import math
  import yaml
  from shapely.geometry import Polygon
  import PIL.Image
  import numpy
  import cv2
  import pyclipper
  import torch
  from .model.constructor import Configurable
label_desc: Use image node_id 12 for calling the DBNet obj's underlying member method code with example usage: obj.hmap2bbox(image_tensor, original_shapes, hmap, text_threshold, bbox_min_score, bbox_min_size, max_candidates, as_polygon) and returns: boxes_batch,  scores_batch