class_docstr: Wraps the MSCOCO datasets and is used by the iterator to fetch data.
class_docstr_tok: ["Wraps","the","MSCOCO","datasets","and","is","used","by","the","iterator","to","fetch","data","."]
docstr: Called by the iterator to fetch a data sample.
  
  A data sample from MSCOCO consists of an image and its corresponding
  caption.
  
  The returned image has the shape (channel, height, width).
docstr_tok: ["Called","by","the","iterator","to","fetch","a","data","sample",".","A","data","sample","from","MSCOCO","consists","of","an","image","and","its","corresponding","caption",".","The","returned","image","has","the","shape","(","channel",",","height",",","width",")","."]
code: def get_example(self, i):
      """Called by the iterator to fetch a data sample.
  
      A data sample from MSCOCO consists of an image and its corresponding
      caption.
  
      The returned image has the shape (channel, height, width).
      """
      ann = self.anns[i]
  
      # Load the image
      img_id = ann["image_id"]
      img_file_name = self.coco.loadImgs([img_id])[0]["file_name"]
      img = Image.open(
          os.path.join(self.coco_root, self.coco_data, img_file_name)
      )
      if img.mode == "RGB":
          img = np.asarray(img, np.float32).transpose(2, 0, 1)
      elif img.mode == "L":
          img = np.asarray(img, np.float32)
          img = np.broadcast_to(img, (3,) + img.shape)
      else:
          raise ValueError("Invalid image mode {}".format(img.mode))
  
      # Load the caption, i.e. sequence of tokens
      tokens = [
          self.vocab.get(w, _unk)
          for w in ["<bos>"] + split(ann["caption"]) + ["<eos>"]
      ]
      tokens = np.array(tokens, np.int32)
  
      return img, tokens
  
file_path: chainer/examples/image_captioning/datasets.py
imports: from collections import defaultdict
  import os
  import numpy
  from PIL import Image
  from pycocotools.coco import COCO
  from chainer import dataset
  from chainer.dataset.convert import to_device
label_desc: Use image node_id 3 for calling the MsCocoDataset obj's underlying member method code with example usage: obj.get_example(i) and returns: img,  tokens