Closed 007-codes closed 4 months ago
Hi, thanks for your interest in our work. The core codes for "json to txt" are pasted as follows:
dir_out = r'xxx'
dict_anno = json.load(open(r'xxx/val_half.json')) # gt json
list_pred = json.load(open(r'xxx/detection.json')) # yolox json
images = dict_anno['images']
print('1.汇总图像ID信息...')
dict_id_info = dict()
for image in images:
video_name, _, image_name = image['file_name'].split('/')
id_ = image['id']
dict_id_info[id_] = {
'video_name': video_name,
'image_name': image_name
}
print('2.汇总预测信息...')
dict_video_pred = defaultdict(list)
for pred in list_pred:
image_id = pred['image_id']
score = pred['score']
x, y, w, h = pred['bbox']
video_name = dict_id_info[image_id]['video_name']
image_name = dict_id_info[image_id]['image_name']
frame_id = int(image_name[:-4])
dict_video_pred[video_name].append(
[frame_id, -1, x, y, w, h, score, -1, -1, -1]
)
print('3.保存...')
if not exists(dir_out): os.mkdir(dir_out)
for video, pred in dict_video_pred.items():
pred = np.array(pred)
pred = pred[np.argsort(pred[:, 0])]
np.savetxt(join(dir_out, video + '.txt'), pred, fmt='%d,%d,%.2f,%.2f,%.2f,%.2f,%.5f,%d,%d,%d')
I hope this will help you.
Hello,
Thank you so much for providing us with a well-documented code and for your contributions.
Replicating most elements of the project was successful - however, I am still not certain about how generated detection through the Auxillary tutorial can be converted to a .txt file that can be used to generate features. The YOLOX_xxx.json file simply converted to a .txt file looks as follows (first line):
[{"image_id": 302, "category_id": 1, "bbox": [889.6500244140625, 422.5500183105469, 137.699951171875, 520.425048828125], "score": 0.9375600814819336, "segmentation": []}, {"image_id": 302, "category_id": 1, "bbox": [508.6125183105469, 456.3000183105469, 32.399993896484375, 105.30001831054688], "score": 0.9346942901611328, "segmentation": []},
This .txt file does not work as an input to generate features.
It would be great if you could provide us with a script to convert the .json file to .txt input, or the .txt file itself in the correct format. I know this issue has been raised previously too (#97), so I am sure a lot of people would benefit if you could walk us through this.
I believe this would greatly help us trying to reproduce your results.
Thanks again!