import os
import sys
sys.path.append('/opt/cocoapi/PythonAPI')
from pycocotools.coco import COCO

# initialize COCO API for instance annotations
dataDir = '/opt/cocoapi'
dataType = 'val2014'
instances_annFile = os.path.join(dataDir, 'annotations/instances_{}.json'.format(dataType))
coco = COCO(instances_annFile)

# initialize COCO API for caption annotations
captions_annFile = os.path.join(dataDir, 'annotations/captions_{}.json'.format(dataType))
coco_caps = COCO(captions_annFile)

annotations = {}
for file in os.listdir('coco_data'):
    if file[0] == '.':
        continue

    file = file[:-4]
    id = int(file)

    annIds = coco_caps.getAnnIds(imgIds=id)
    ann_dict = coco_caps.loadAnns(annIds)
    anns = [x['caption'] for x in ann_dict]

    annotations[id] = anns

import json
with open('captions.json', 'w') as f:
    json.dump(annotations, f)
79077211422f17ac3110450ac76f6cf4f12800b5
<mask token>

<mask token>
sys.path.append('/opt/cocoapi/PythonAPI')
<mask token>
for file in os.listdir('coco_data'):
    if file[0] == '.':
        continue
    file = file[:-4]
    id = int(file)
    annIds = coco_caps.getAnnIds(imgIds=id)
    ann_dict = coco_caps.loadAnns(annIds)
    anns = [x['caption'] for x in ann_dict]
    annotations[id] = anns
<mask token>
with open('captions.json', 'w') as f:
    json.dump(annotations, f)

<mask token>
sys.path.append('/opt/cocoapi/PythonAPI')
<mask token>
dataDir = '/opt/cocoapi'
dataType = 'val2014'
instances_annFile = os.path.join(dataDir, 'annotations/instances_{}.json'.
    format(dataType))
coco = COCO(instances_annFile)
captions_annFile = os.path.join(dataDir, 'annotations/captions_{}.json'.
    format(dataType))
coco_caps = COCO(captions_annFile)
annotations = {}
for file in os.listdir('coco_data'):
    if file[0] == '.':
        continue
    file = file[:-4]
    id = int(file)
    annIds = coco_caps.getAnnIds(imgIds=id)
    ann_dict = coco_caps.loadAnns(annIds)
    anns = [x['caption'] for x in ann_dict]
    annotations[id] = anns
<mask token>
with open('captions.json', 'w') as f:
    json.dump(annotations, f)

import os
import sys
sys.path.append('/opt/cocoapi/PythonAPI')
from pycocotools.coco import COCO
dataDir = '/opt/cocoapi'
dataType = 'val2014'
instances_annFile = os.path.join(dataDir, 'annotations/instances_{}.json'.
    format(dataType))
coco = COCO(instances_annFile)
captions_annFile = os.path.join(dataDir, 'annotations/captions_{}.json'.
    format(dataType))
coco_caps = COCO(captions_annFile)
annotations = {}
for file in os.listdir('coco_data'):
    if file[0] == '.':
        continue
    file = file[:-4]
    id = int(file)
    annIds = coco_caps.getAnnIds(imgIds=id)
    ann_dict = coco_caps.loadAnns(annIds)
    anns = [x['caption'] for x in ann_dict]
    annotations[id] = anns
import json
with open('captions.json', 'w') as f:
    json.dump(annotations, f)

import os
import sys
sys.path.append('/opt/cocoapi/PythonAPI')
from pycocotools.coco import COCO

# initialize COCO API for instance annotations
dataDir = '/opt/cocoapi'
dataType = 'val2014'
instances_annFile = os.path.join(dataDir, 'annotations/instances_{}.json'.format(dataType))
coco = COCO(instances_annFile)

# initialize COCO API for caption annotations
captions_annFile = os.path.join(dataDir, 'annotations/captions_{}.json'.format(dataType))
coco_caps = COCO(captions_annFile)

annotations = {}
for file in os.listdir('coco_data'):
    if file[0] == '.':
        continue

    file = file[:-4]
    id = int(file)

    annIds = coco_caps.getAnnIds(imgIds=id)
    ann_dict = coco_caps.loadAnns(annIds)
    anns = [x['caption'] for x in ann_dict]

    annotations[id] = anns

import json
with open('captions.json', 'w') as f:
    json.dump(annotations, f)