code: def line_map_to_segments(
      junctions: Tensor, line_map: Tensor
  ) -> Tensor:
      """Convert a junction connectivity map to a Nx2x2 tensor of segments."""
      junc_loc1, junc_loc2 = where(torch.triu(line_map))
      segments = stack([junctions[junc_loc1], junctions[junc_loc2]], 1)
      return segments
  
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 1 for calling a global function with example usage: line_map_to_segments(junctions, line_map) and returns: segments