JingjingJiang commited on
Commit
0c65d31
1 Parent(s): 5153a89

Upload filter_pt_data.py

Browse files
Files changed (1) hide show
  1. filter_pt_data.py +40 -0
filter_pt_data.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+
4
+ def load_json(file_path):
5
+ with open(file_path, "r") as f:
6
+ return json.load(f)
7
+
8
+
9
+ def save_json(data, file_path):
10
+ with open(file_path, "w") as f:
11
+ json.dump(data, f, indent=4)
12
+
13
+
14
+ def main():
15
+ # 1,246,901
16
+ sharegpt4_pt = load_json(
17
+ "data/ShareGPT4V-PT/share-captioner_coco_lcs_sam_1246k_1107.json")
18
+
19
+ # sharegpt4v_pt_sam = [a for a in sharegpt4_pt if "sam/" in a["image"]]
20
+ sharegpt4v_pt_coco = [a for a in sharegpt4_pt if "coco/" in a["image"]]
21
+ sharegpt4v_pt_llava = [a for a in sharegpt4_pt if "llava/" in a["image"]]
22
+
23
+ data_pt = sharegpt4v_pt_coco + sharegpt4v_pt_llava
24
+ print(f"data_pt: {len(data_pt)}")
25
+
26
+ sharegpt4v = load_json(
27
+ "data/ShareGPT4V-PT/sharegpt4v_instruct_gpt4-vision_cap100k.json")
28
+ sharegpt4v_dict = {ann['image']: ann for ann in sharegpt4v}
29
+
30
+ for datum in data_pt:
31
+ if datum['image'] in sharegpt4v_dict:
32
+ datum['conversations'] = sharegpt4v_dict[datum['image']][
33
+ 'conversations']
34
+
35
+ save_json(data_pt,"data/sharegpt4v_filtered_676k.json")
36
+
37
+
38
+ if __name__ == '__main__':
39
+ main()
40
+