code: def compute_weight_mask(
      mask: np.ndarray, edge_weight=4
  ) -> np.ndarray:
      from skimage.morphology import binary_dilation, binary_erosion
  
      binary_mask = mask > 0
      weight_mask = np.ones(mask.shape[:2]).astype(np.float32)
  
      if binary_mask.any():
          dilated = binary_dilation(
              binary_mask, structure=np.ones((5, 5), dtype=np.bool)
          )
          eroded = binary_erosion(
              binary_mask, structure=np.ones((5, 5), dtype=np.bool)
          )
  
          a = dilated & ~binary_mask
          b = binary_mask & ~eroded
  
          weight_mask = (a | b).astype(np.float32) * edge_weight + 1
          weight_mask = cv2.GaussianBlur(
              weight_mask, ksize=(5, 5), sigmaX=5
          )
      return weight_mask
  
file_path: pytorch-toolbelt/pytorch_toolbelt/datasets/segmentation.py
imports: from functools import partial
  from typing import Optional, List, Callable
  import albumentations
  import cv2
  import numpy
  from skimage.measure import block_reduce
  from torch.utils.data import Dataset
  from .common import read_image_rgb, INPUT_IMAGE_KEY, INPUT_IMAGE_ID_KEY, INPUT_INDEX_KEY, TARGET_MASK_WEIGHT_KEY, TARGET_MASK_KEY, name_for_stride
  from ..utils import fs, image_to_tensor
label_desc: Use image node_id 3 for calling a global function with example usage: compute_weight_mask(mask, edge_weight) and returns: weight_mask