File size: 4,216 Bytes
2b2ae2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import json
import os


# # >>> CLEVR
# with open("../transformer/data/clevr/splits.json", "r") as f:
#     splits = json.load(f)

# # Change Captions
# with open("../transformer/data/clevr/change_captions.json", "r") as f:
#     change_captions = json.load(f)

# # no_change Captions
# with open("../transformer/data/clevr/no_change_captions.json", "r") as f:
#     no_change_captions = json.load(f)

# images = []
# annotations = []
# for image_id in splits["train"] + splits["val"] + splits["test"]:
#     images.append({
#         "id": f"{image_id:0>6}c",
#         "file_name": f"{image_id:0>6}c"
#     })
#     images.append({
#         "id": f"{image_id:0>6}nc",
#         "file_name": f"{image_id:0>6}nc"
#     })

# idx = 0
# for image_id in splits["train"] + splits["val"] + splits["test"]:
#     key = f"CLEVR_default_{image_id:0>6}.png"
#     change_caption = change_captions[key]
#     no_change_caption = no_change_captions[key]
    
#     for caption in change_caption:
#         annotations.append({
#             "image_id": f"{image_id:0>6}c",
#             "id": idx,
#             "caption": caption,
#         })
#         idx += 1
#     for caption in no_change_caption:
#         annotations.append({
#             "image_id": f"{image_id:0>6}nc",
#             "id": idx,
#             "caption": caption,
#         })
#         idx += 1

# with open("./clevr_data/total_change_captions_reformat.json", "wt") as f:
#     json.dump({"images": images, "annotations": annotations}, f)
# # <<<


# # >>> Spot-the-Diff
# with open("../transformer/data/spot/captions/filter_test.json", "r") as f:
#     spot_captions = json.load(f)

# with open("../transformer/data/spot/captions/filter_train.json", "r") as f:
#     spot_captions += json.load(f)

# with open("../transformer/data/spot/captions/filter_val.json", "r") as f:
#     spot_captions += json.load(f)

# images = []
# annotations = []
# idx = 0
# for item in spot_captions:
#     image_id, captions = item["img_id"], item["sentences"]
#     images.append({
#         "id": image_id,
#         "file_name": image_id
#     })
#     for caption in captions:
#         annotations.append({
#             "image_id": image_id,
#             "id": idx,
#             "caption": caption,
#         })
#         idx += 1

# with open("./spot_data/total_change_captions_reformat.json", "wt") as f:
#     json.dump({"images": images, "annotations": annotations}, f)
# # <<<


# # >>> Image-Editing-Request
# with open("../transformer/data/edit/test.json", "r") as f:
#     edit_captions = json.load(f)

# with open("../transformer/data/edit/train.json", "r") as f:
#     edit_captions += json.load(f)

# with open("../transformer/data/edit/val.json", "r") as f:
#     edit_captions += json.load(f)
    
# images = []
# annotations = []
# idx = 0
# for item in edit_captions:
#     image_id, captions = item["uid"], item["sents"]
#     images.append({
#         "id": image_id,
#         "file_name": image_id
#     })
#     for caption in captions:
#         annotations.append({
#             "image_id": image_id,
#             "id": idx,
#             "caption": caption,
#         })
#         idx += 1

# with open("./edit_data/total_change_captions_reformat.json", "wt") as f:
#     json.dump({"images": images, "annotations": annotations}, f)
# # <<<

# >>> Refined Spot-the-Diff
with open("./refined_spot_data/reformat_train.json", "r") as f:
    refined_spot_captions = json.load(f)
with open("./refined_spot_data/reformat_val.json", "r") as f:
    refined_spot_captions += json.load(f)
with open("./refined_spot_data/reformat_test.json", "r") as f:
    refined_spot_captions += json.load(f)
images = []
annotations = []
idx = 0
for item in refined_spot_captions:
    image_id, captions = item["img_id"], item["sentences"]
    images.append({
        "id": image_id,
        "file_name": image_id
    })
    for caption in captions:
        annotations.append({
            "image_id": image_id,
            "id": idx,
            "caption": caption,
        })
        idx += 1
        
with open("./refined_spot_data/total_change_captions_reformat.json", "wt") as f:
    json.dump({"images": images, "annotations": annotations}, f)
# <<<