-
Notifications
You must be signed in to change notification settings - Fork 1
/
json2txt.py
31 lines (23 loc) · 896 Bytes
/
json2txt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import pandas as pd
def json2txt(src, dest):
with open(src) as json_file:
data = json.load(json_file)
all_images = []
all_captions = []
for i in data:
image_name = i['id']
captions = i['captions']
captions = captions.split('\n')
for cap in captions:
all_images.append(image_name)
all_captions.append(cap)
df = {'id': all_images, 'captions': all_captions}
df = pd.DataFrame(df)
df.to_csv(dest)
if __name__ == '__main__':
# file_path = "../data/vietcap4h-public-test/sample_submission.json"
# file_path = "../data/viecap4h-public-train/viecap4h-public-train/train_captions.json"
file_path = "../data/vietcap4h-private-test/vietcap4h-private-test/private_sample_sub.json"
dest_path = './train_files/private_captions.csv'
json2txt(file_path, dest_path)