Wangt-CN:

caption = self.captions[index]


Based on this line, seems you just want to return one caption with one image.
Btw, it seems you forget to return the target and several other things…



 Wangt-CN:

target = torch.Tensor(caption)
return image, index, img_id