class_docstr: Module extracting line segments from junctions and line heatmaps.
  
  Args:
      detect_thresh: The probability threshold for mean activation (0. ~ 1.)
      num_samples: Number of sampling locations along the line segments.
      inlier_thresh: The min inlier ratio to satisfy (0. ~ 1.) => 0. means no threshold.
      heatmap_low_thresh: The lowest threshold for the pixel to be considered as candidate in junction recovery.
      heatmap_high_thresh: The higher threshold for NMS in junction recovery.
      max_local_patch_radius: The max patch to be considered in local maximum search.
      lambda_radius: The lambda factor in linear local maximum search formulation
      use_candidate_suppression: Apply candidate suppression to break long segments into short sub-segments.
      nms_dist_tolerance: The distance tolerance for nms. Decide whether the junctions are on the line.
      use_heatmap_refinement: Use heatmap refinement method or not.
      heatmap_refine_cfg: The configs for heatmap refinement methods.
      use_junction_refinement: Use junction refinement method or not.
      junction_refine_cfg: The configs for junction refinement methods.
docstr: Global heatmap refinement method.
docstr_tok: ["Global","heatmap","refinement","method","."]
code: def refine_heatmap(
      self,
      heatmap: Tensor,
      ratio: float = 0.2,
      valid_thresh: float = 1e-2,
  ) -> Tensor:
      """Global heatmap refinement method."""
      # Grab the top 10% values
      heatmap_values = heatmap[heatmap > valid_thresh]
      sorted_values = torch.sort(heatmap_values, descending=True)[0]
      top10_len = math.ceil(sorted_values.shape[0] * ratio)
      max20 = torch.mean(sorted_values[:top10_len])
      heatmap = torch.clamp(heatmap / max20, min=0.0, max=1.0)
      return heatmap
  
imports: import math
  from typing import Any, Dict, Optional, Tuple
  import torch
  from kornia.core import Module, Tensor, concatenate, sin, stack, tensor, where, zeros
  from kornia.core.check import KORNIA_CHECK_SHAPE
  from kornia.geometry.bbox import nms
  from kornia.utils import map_location_to_cpu, torch_meshgrid
  from .backbones import SOLD2Net
label_desc: Use image node_id 3 for calling the LineSegmentDetectionModule obj's underlying member method code with example usage: obj.refine_heatmap(heatmap, ratio, valid_thresh) and returns: heatmap