class_docstr: Dataset class suitable for segmentation tasks
class_docstr_tok: ["Dataset","class","suitable","for","segmentation","tasks"]
code: def __getitem__(self, index):
      image = self.read_image(self.images[index])
      data = {"image": image}
      if self.masks is not None:
          data["mask"] = self.read_mask(self.masks[index])
  
      data = self.transform(**data)
  
      image = data["image"]
      sample = {
          INPUT_INDEX_KEY: index,
          INPUT_IMAGE_ID_KEY: self.image_ids[index],
          INPUT_IMAGE_KEY: image_to_tensor(image),
      }
  
      if self.masks is not None:
          mask = data["mask"]
          sample[TARGET_MASK_KEY] = self.make_target(mask)
          if self.need_weight_mask:
              sample[TARGET_MASK_WEIGHT_KEY] = image_to_tensor(
                  compute_weight_mask(mask)
              ).float()
  
          if self.need_supervision_masks:
              for i in range(1, 6):
                  stride = 2**i
                  mask = block_reduce(
                      mask,
                      (2, 2),
                      partial(_block_reduce_dominant_label),
                  )
                  sample[
                      name_for_stride(TARGET_MASK_KEY, stride)
                  ] = self.make_target(mask)
  
      return sample
  
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 the SegmentationDataset obj's underlying member method code with example usage: obj.__getitem__(index) and returns: sample