my-VIST-dataset / replace.py
StarThomas1002's picture
Upload replace.py with huggingface_hub
6be535c verified
raw
history blame
695 Bytes
import json
# 输入文件路径
input_file_path = '/home/yiyangai/stephenqs/datasets/VIST/sis/test.story-in-sequence.json'
# 输出文件路径
output_file_path = '/home/yiyangai/stephenqs/datasets/VIST/sis/updated_test.story-in-sequence.json'
# 读取 JSON 文件
with open(input_file_path, 'r') as file:
data = json.load(file)
# 遍历 images 列表
for image in data['images']:
image_id = image['id'] # 获取 id 的值
# 替换 url_o 的值
image['url_o'] = f"./../test/{image_id}.jpg"
# 将更新后的数据写入新文件
with open(output_file_path, 'w') as file:
json.dump(data, file, indent=4)
print(f"URL 替换已完成,并保存到: {output_file_path}")