Processing and tokenizing data
With the data downloaded and placed in the correct folders, let’s define the directories containing the required data:
trainval_image_dir = os.path.join('data', 'train2014', 'train2014')
trainval_captions_dir = os.path.join('data', 'annotations_trainval2014', 'annotations')
test_image_dir = os.path.join('data', 'val2017', 'val2017')
test_captions_dir = os.path.join('data', 'annotations_trainval2017', 'annotations')
trainval_captions_filepath = os.path.join(trainval_captions_dir, 'captions_train2014.json')
test_captions_filepath = os.path.join(test_captions_dir, 'captions_val2017.json')
Here we have defined the directories containing training and testing images as well as the file paths of the JSON files that contain the captions of the training and testing images.
Preprocessing data
As the...