code: def _decode(
      sample,
      image_key="jpg",
      image_mode="RGB",
      target_key="cls",
      alt_label="",
  ):
      """Custom sample decode
      * decode and convert PIL Image
      * cls byte string label to int
      * pass through JSON byte string (if it exists) without parse
      """
      # decode class label, skip if alternate label not valid
      if alt_label:
          # alternative labels are encoded in json metadata
          meta = json.loads(sample["json"])
          class_label = int(meta[alt_label])
          if class_label < 0:
              # skipped labels currently encoded as -1, may change to a null/None value
              return None
      else:
          class_label = int(sample[target_key])
  
      # decode image
      img = getfirst(sample, image_key)
      with io.BytesIO(img) as b:
          img = Image.open(b)
          img.load()
      if image_mode:
          img = img.convert(image_mode)
  
      # json passed through in undecoded state
      decoded = dict(
          jpg=img, cls=class_label, json=sample.get("json", None)
      )
      return decoded
  
imports: import io
  import json
  import logging
  import math
  import os
  import random
  import sys
  from dataclasses import dataclass
  from functools import partial
  from itertools import islice
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import torch
  import torch.distributed
  import yaml
  from PIL import Image
  from torch.utils.data import Dataset, IterableDataset, get_worker_info
  from .class_map import load_class_map
  from .reader import Reader
  from .shared_count import SharedCount
label_desc: Use image node_id 4 for calling a global function with example usage: _decode(sample, image_key, image_mode, target_key, alt_label) and returns: decoded, None