class_docstr: Get data directly from caltech101 dataset from Internet.
class_docstr_tok: ["Get","data","directly","from","caltech101","dataset","from","Internet","."]
code: def __init__(
      self, width, height, padding, train=True, shuffle=False, rng=None
  ):
      super(Caltech101DataSource, self).__init__(
          shuffle=shuffle, rng=rng
      )
      data_uri = "http://data.caltech.edu/records/mzrjq-6wc02/files/caltech-101.zip"
      logger.info("Getting labeled data from {}.".format(data_uri))
      r = download(data_uri)  # file object returned
      label_dict = dict()
      with zipfile.ZipFile(r, "r") as zipf:
          with zipf.open(
              "caltech-101/101_ObjectCategories.tar.gz", "r"
          ) as tr:
              with tarfile.open(fileobj=tr, mode="r:gz") as fpin:
                  images = []
                  labels = []
                  for name in fpin.getnames():
                      if ".jpg" not in name or "Google" in name:
                          continue
                      label, filename = name.split("/")[-2:]
                      if label not in label_dict:
                          label_dict[label] = len(label_dict)
                      with fpin.extractfile(
                          name
                      ) as imf, BytesIO() as imio:
                          imio.name = name
                          imio.write(imf.read())
                          imio.seek(0)
                          im = imread(imio, num_channels=3)
                          arranged_images = self._resize_image(
                              im, width, height, padding
                          )
                          images.append(arranged_images)
                          labels.append(label_dict[label])
                  self._size = len(images)
                  self._images = np.array(images)
                  self._labels = np.array(labels).reshape(-1, 1)
      r.close()
      logger.info("Getting labeled data from {}.".format(data_uri))
  
      self._size = self._labels.size
      self._variables = ("x", "y")
      if rng is None:
          rng = np.random.RandomState(313)
      self.rng = rng
      self._indexes = rng.permutation(self._size)
  
file_path: nnabla/tutorial/caltech101_data.py
imports: import numpy
  import tarfile
  import zipfile
  from io import BytesIO
  from nnabla.logger import logger
  from nnabla.utils.data_iterator import data_iterator
  from nnabla.utils.data_source import DataSource
  from nnabla.utils.data_source_loader import download, get_data_home
  from nnabla.utils.image_utils import imresize, imread
label_desc: Use image node_id 3 to create a new Caltech101DataSource object from inherited base classes: DataSource with example: obj = Caltech101DataSource(width, height, padding, train, shuffle, rng)