It works perfectly.  I made one small change:
class CaptioningData(Dataset):
    def __init__(self, root, df, vocab):
        self.df = df.reset_index(drop=True)
        self.root = root
        self.vocab = vocab
        self.id_to_path = dict()
        for dirpath, _, filenames in os.walk(self.root):
            for filename in filenames:
                id, ext = os.path.splitext(filename)
                if ext == '.png':
                    self.id_to_path[id] = os.path.join(dirpath, filename)
        self.transform = transforms.Compose([ 
            transforms.Resize(224),
            transforms.RandomCrop(224),
            transforms.RandomHorizontalFlip(), 
            transforms.ToTensor(), 
            transforms.Normalize((0.485, 0.456, 0.406), 
                                 (0.229, 0.224, 0.225))]
        )

Thank you again!