def _get_caption_info(self, key):
if self._is_train:
pseudo, pseudo_concepts = self._pseudos[key]
self._sample['pseudo'], self._sample['pseudo_lens'] = \
self._pad(pseudo)
self._sample['pseudo_concepts'],
self._sample['pseudo_concept_lens'] = \
self._pad(pseudo_concepts)
caption, concepts = self._captions[key]
self._sample['caption'], self._sample['caption_len'] = \
self._pad(caption)
self._sample['caption_concepts'],
self._sample['caption_concept_lens'] = \
self._pad(concepts)
def _get_image_info(self, key):
images = []
image_path = key
image = Image.open(image_path).convert('RGB')
image = self._transform(image, 256)
for imsize in self._imsizes:
if imsize != self._imsizes[-1]:
image = transforms.Resize(imsize)(image)
else:
image = image
images.append(image)
self._sample['images'] = images
def __getitem__(self, index):
self._sample = {}
key = self._image_filenames[index]
self._get_image_info(key)
self._caption_info(key)
self._sample['key'] = key
self._sample['class_id'] = self._class_id[index]
return self._sample