ObjectRelator-Original / scripts /merge_result.py
YuqianFu's picture
Upload folder using huggingface_hub
625a17f verified
import json
# filepath: /home/yuqian_fu/merge_results.py
# 定义两个 JSON 文件的路径
json_file_1 = "/path/to/first_result.json"
json_file_2 = "/path/to/second_result.json"
output_file = "/path/to/merged_result.json"
# 加载两个 JSON 文件
with open(json_file_1, "r") as f1, open(json_file_2, "r") as f2:
result_1 = json.load(f1)
result_2 = json.load(f2)
# 检查是否有重复的 take_id
overlap = set(result_1) & set(result_2)
if overlap:
print(f"WARNING: 以下 take_id 在两个文件中都出现了,将以第二个文件为准覆盖:{sorted(overlap)}")
# 合并两个 result 字典
merged_result = {**result_1, **result_2}
# 将合并后的结果保存到新的 JSON 文件
with open(output_file, "w") as out:
json.dump(merged_result, out)
print(f"Merged result saved to {output_file}")