class_docstr: MNIST-M Dataset.
  Auto-downloads the dataset and provide the torch Dataset API.
  
  Args:
      root (str): path to directory where the MNISTM folder will be created (or exists.)
      train (bool, optional): defaults to True.
          If True, loads the training data. Otherwise, loads the test data.
      transform (callable, optional): defaults to None.
          A function/transform that takes in
          an PIL image and returns a transformed version.
          E.g., ``transforms.RandomCrop``
          This preprocessing function applied to all images (whether source or target)
  
      target_transform (callable, optional): default to None, similar to transform.
          This preprocessing function applied to all target images, after `transform`
  
      download (bool optional): defaults to False.
          Whether to allow downloading the data if not found on disk.
docstr: Download the MNISTM data.
docstr_tok: ["Download","the","MNISTM","data","."]
code: def download(self):
      """Download the MNISTM data."""
      # import essential packages
      import gzip
      import pickle
  
      # Ignore comment is used here because type stubs for 'six.moves' are not available. This suppresses mypy errors.
      from six.moves import urllib  # type: ignore
      from torchvision import datasets
  
      # check if dataset already exists
      if self._check_exists():
          return
  
      # make data dirs
      try:
          os.makedirs(os.path.join(self.root, self.raw_folder))
          os.makedirs(os.path.join(self.root, self.processed_folder))
      except OSError as e:
          if e.errno == errno.EEXIST:
              pass
          else:
              raise
  
      # download pkl files
      logging.info("Downloading " + self.url)
      filename = self.url.rpartition("/")[2]
      file_path = os.path.join(self.root, self.raw_folder, filename)
      if not os.path.exists(file_path.replace(".gz", "")):
          data = urllib.request.urlopen(self.url)
          with open(file_path, "wb") as f:
              f.write(data.read())
          with open(
              file_path.replace(".gz", ""), "wb"
          ) as out_f, gzip.GzipFile(file_path) as zip_f:
              out_f.write(zip_f.read())
          os.unlink(file_path)
  
      # process and save as torch files
      logging.info("Processing...")
  
      # load MNIST-M images from pkl file
      with open(file_path.replace(".gz", ""), "rb") as f:
          mnist_m_data = pickle.load(f, encoding="bytes")
      mnist_m_train_data = torch.ByteTensor(mnist_m_data[b"train"])
      mnist_m_test_data = torch.ByteTensor(mnist_m_data[b"test"])
  
      # get MNIST labels
      mnist_train_labels = datasets.MNIST(
          root=self.mnist_root, train=True, download=True
      ).targets
      mnist_test_labels = datasets.MNIST(
          root=self.mnist_root, train=False, download=True
      ).targets
  
      # save MNIST-M dataset
      training_set = (mnist_m_train_data, mnist_train_labels)
      test_set = (mnist_m_test_data, mnist_test_labels)
      with open(
          os.path.join(
              self.root, self.processed_folder, self.training_file
          ),
          "wb",
      ) as f:
          torch.save(training_set, f)
      with open(
          os.path.join(
              self.root, self.processed_folder, self.test_file
          ),
          "wb",
      ) as f:
          torch.save(test_set, f)
  
      logging.info("[DONE]")
  
file_path: pykale/kale/loaddata/mnistm.py
imports: from __future__ import print_function
  import errno
  import logging
  import os
  import torch
  import torch.utils.data
  from PIL import Image
label_desc: Use image node_id 5 for calling the MNISTM obj's underlying member method code with example usage: obj.download() without return types