code: def fetch_imagenet_10(url_id: int = 0) -> Dict:
      """
      Sample dataset extracted from imagenet in a dictionary format.
      The train set contains 1000 random samples, 100 for each of the following 10 selected classes:
  
      * stingray
      * trilobite
      * centipede
      * slug
      * snail
      * Rhodesian ridgeback
      * beagle
      * golden retriever
      * sea lion
      * espresso
  
      The test set contains 50 random samples, 5 for each of the classes above.
  
      Parameters
      ----------
      url_id
          Index specifying which URL to use for downloading.
  
      Returns
      -------
      Dictionary with the following keys:
  
          * trainset - train set tuple (X_train, y_train)
          * testset - test set tuple (X_test, y_test)
          * int_to_str_labels - map from target to target name
          * str_to_int_labels -  map from target name to target
      """
      url = IMAGENET_URLS[url_id]
      try:
          resp = requests.get(url, timeout=2)
          resp.raise_for_status()
      except RequestException:
          logger.exception(
              "Could not connect, URL may be out of service"
          )
          raise
      tar = tarfile.open(fileobj=BytesIO(resp.content), mode="r:gz")
  
      def keystoint(x):
          return {int(k): v for k, v in x}
  
      int_to_str_labels = json.load(
          tar.extractfile("imagenet10/int_to_str_labels.json"),  # type: ignore[arg-type]
          object_pairs_hook=keystoint,
      )
      str_to_int_labels = json.load(tar.extractfile("imagenet10/str_to_int_labels.json"))  # type: ignore[arg-type]
  
      # hack to load npy files from a tar archive
      # see https://github.com/numpy/numpy/issues/7989
      mean_channels_af = BytesIO()
      mean_channels_af.write(tar.extractfile("imagenet10/mean_channels.npy").read())  # type: ignore[union-attr]
      mean_channels_af.seek(0)
      mean_channels = np.load(mean_channels_af)
  
      X_train_af = BytesIO()
      X_train_af.write(tar.extractfile("imagenet10/trainset/X.npy").read())  # type: ignore[union-attr]
      X_train_af.seek(0)
      X_train = np.load(X_train_af)
  
      y_train_af = BytesIO()
      y_train_af.write(tar.extractfile("imagenet10/trainset/y.npy").read())  # type: ignore[union-attr]
      y_train_af.seek(0)
      y_train = np.load(y_train_af)
  
      X_test_af = BytesIO()
      X_test_af.write(tar.extractfile("imagenet10/testset/X.npy").read())  # type: ignore[union-attr]
      X_test_af.seek(0)
      X_test = np.load(X_test_af)
  
      y_test_af = BytesIO()
      y_test_af.write(tar.extractfile("imagenet10/testset/y.npy").read())  # type: ignore[union-attr]
      y_test_af.seek(0)
      y_test = np.load(y_test_af)
  
      # buiding dataset dict
      imagenet10 = {
          "trainset": (X_train, y_train),
          "testset": (X_test, y_test),
          "int_to_str_labels": int_to_str_labels,
          "str_to_int_labels": str_to_int_labels,
          "mean_channels": mean_channels,
      }
  
      return imagenet10
  
file_path: alibi/alibi/datasets/default.py
imports: import logging
  import pkgutil
  import tarfile
  import json
  from io import BytesIO, StringIO
  from typing import Optional, Tuple, Union, Dict
  import numpy
  import pandas
  import PIL
  import requests
  from requests import RequestException
  from sklearn.preprocessing import LabelEncoder
  from alibi.utils.data import Bunch
label_desc: Use image node_id 1 for calling a global function with example usage: fetch_imagenet_10(url_id) and returns: imagenet10, unknown