File size: 1,046 Bytes
625a17f |
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 |
import json
import os
from PIL import Image
import numpy as np
from pycocotools.mask import encode, decode, frPyObjects
from tqdm import tqdm
import copy
if __name__ == '__main__':
data_path = "/home/yuqian_fu/Projects/DAVIS_test_gap20_instruction.json"
save_path = "/home/yuqian_fu/Projects/DAVIS_test_gap20_instruction_final.json"
k = 0
sent_id = 0
with open(data_path, "r") as fp:
datas = json.load(fp)
new_datalist = []
for data in datas:
if data['anns'] == []:
continue
data['new_img_id'] = k
k += 1
instruct_list = data["instruction"]
instruct_list_new = []
for sample in instruct_list:
sample["sent_id"] = sent_id
sent_id += 1
instruct_list_new.append(sample)
data["instruction"] = instruct_list_new
new_datalist.append(data)
print(len(new_datalist))
print("sent_id:", sent_id)
with open(save_path, 'w') as json_file:
json.dump(new_datalist, json_file)
|