(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.
Load vocab and image features. Convert sentences to indices
Load vocab and image features . Convert sentences to indices
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
def __init__ ( self , path , max_images = - 1 ) : 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