class_docstr: This class loads in the sentences and CNN image features for image captioning
  that have been taken from Andrej Karpathy's
  `Deep Visual-Semantic Alignments <http://cs.stanford.edu/people/karpathy/deepimagesent/>`_
  work. They are converted to pkl format to avoid using scipy for loading the .mat
  image features.
  
  The dataset assumes the model takes the precomputed VGG features of an
  image and a sentence converted to its one hot representation. The model
  then transforms both the image and the sentence to the same space and
  prepends the image to the sentence so that it is treated as the first word
  of the sequence to be fed to a RNN.
docstr: Load vocab and image features. Convert sentences to indices
  
  Args:
      path (str): Directory containing sentences and image features.
      max_images (int): Number of images to load. Set to -1 for max.
code: def __init__(self, path, max_images=-1):
      """
      Load vocab and image features. Convert sentences to indices
  
      Args:
          path (str): Directory containing sentences and image features.
          max_images (int): Number of images to load. Set to -1 for max.
      """
      super(ImageCaption, self).__init__(name=None)
  
      self.path = path
      neon_logger.display(
          "Reading train images and sentences from %s" % self.path
      )
      self.read_images("train")
      self.load_vocab()
  
      trainSents, trainImgs = [], []
      for i, img_sent in enumerate(self.iterImageSentencePair()):
          if len(trainSents) > max_images and max_images > 0:
              break
          trainImgs.append(img_sent["image"])
          sent = [self.end_token] + [
              x
              for x in img_sent["sentence"]["tokens"]
              if x in self.vocab_to_index
          ]
          trainSents.append(sent[: self.max_sentence_length])
  
      self.nbatches = len(trainImgs) // self.be.bsz
      self.ndata = self.nbatches * self.be.bsz
  
      self.X = np.zeros((len(trainSents), self.max_sentence_length))
      self.y = np.zeros((len(trainSents), self.max_sentence_length + 1))
      self.images = np.vstack(trainImgs)
  
      self.sent_length = np.array([len(x) + 1 for x in trainSents])
      self.sent_ends = np.arange(self.max_sentence_length + 1)[
          :, np.newaxis
      ]
      for sent_idx, sent in enumerate(trainSents):
          self.X[sent_idx, : len(sent)] = [
              self.vocab_to_index[word] for word in sent
          ]
      self.y[:, :-1] = self.X
  
imports: from collections import Counter
  import numpy
  import os
  from neon import logger
  from neon.data.dataiterator import NervanaDataIterator
  from neon.data.datasets import Dataset
  from neon.util.compat import xrange
label_desc: Use image node_id 1 to create a new ImageCaption object from inherited base classes: NervanaDataIterator with example: obj = ImageCaption(path, max_images)