Datasets:
Tasks:
Image-Text-to-Text
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
1K - 10K
ArXiv:
License:
File size: 1,559 Bytes
1e9a83f |
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 |
import json
import os
# 文件路径
json_dir = "/nfs/data3/zhen/Flamingo_jz/jz-icl/VL-ICL/clevr"
query_file = os.path.join(json_dir, "query.json")
support_file = os.path.join(json_dir, "support.json")
# 加载 JSON 数据
with open(query_file, 'r') as f:
query_data = json.load(f)
with open(support_file, 'r') as f:
support_data = json.load(f)
# 定义一个函数,将数据根据属性种类进行分类并保存为独立的 JSON 文件
def split_by_attribute(data, base_folder, data_type):
# 创建一个字典来存储不同属性的样本
attribute_dict = {}
for sample in data:
# 从 question 提取属性类型
attribute_type, _ = sample["question"].split(": ")
# 将样本按属性类型添加到相应的列表中
if attribute_type not in attribute_dict:
attribute_dict[attribute_type] = []
attribute_dict[attribute_type].append(sample)
# 将不同属性的样本分别保存为 JSON 文件
for attribute_type, samples in attribute_dict.items():
output_file = os.path.join(base_folder, f"{data_type}_{attribute_type}.json")
with open(output_file, 'w') as f:
json.dump(samples, f, indent=4)
print(f"{data_type} samples for attribute '{attribute_type}' saved to {output_file}")
# 对 query 和 support 数据分别进行分类并保存
split_by_attribute(query_data, json_dir, "query")
split_by_attribute(support_data, json_dir, "support")
print("文件分类并保存完成。")
|