code: def prob_to_junctions(
      prob: Tensor,
      dist: float,
      prob_thresh: float = 0.01,
      top_k: int = 0,
  ) -> Tensor:
      """Extract junctions from a probability map, apply NMS, and extract the top k candidates."""
      # Extract the junctions
      junctions = stack(where(prob >= prob_thresh), -1).float()
      if len(junctions) == 0:
          return junctions
  
      # Perform NMS
      boxes = concatenate(
          [junctions - dist / 2, junctions + dist / 2], 1
      )
      scores = prob[prob >= prob_thresh]
      remainings = nms(boxes, scores, 0.001)
      junctions = junctions[remainings]
  
      # Keep only the topk values
      if top_k > 0:
          k = min(len(junctions), top_k)
          junctions = junctions[:k]
  
      return junctions
  
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 2 for calling a global function with example usage: prob_to_junctions(prob, dist, prob_thresh, top_k) and returns: junctions, junctions