Meta Byte Track
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mix_data_test_mot17.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import json
  2. import os
  3. """
  4. cd datasets
  5. mkdir -p mix_det/annotations
  6. cp mot/annotations/val_half.json mix_det/annotations/val_half.json
  7. cp mot/annotations/test.json mix_det/annotations/test.json
  8. cd mix_det
  9. ln -s ../mot/train mot_train
  10. ln -s ../crowdhuman/CrowdHuman_train crowdhuman_train
  11. ln -s ../crowdhuman/CrowdHuman_val crowdhuman_val
  12. ln -s ../Cityscapes cp_train
  13. ln -s ../ETHZ ethz_train
  14. cd ..
  15. """
  16. mot_json = json.load(open('datasets/mot/annotations/train.json','r'))
  17. img_list = list()
  18. for img in mot_json['images']:
  19. img['file_name'] = 'mot_train/' + img['file_name']
  20. img_list.append(img)
  21. ann_list = list()
  22. for ann in mot_json['annotations']:
  23. ann_list.append(ann)
  24. video_list = mot_json['videos']
  25. category_list = mot_json['categories']
  26. print('mot17')
  27. max_img = 10000
  28. max_ann = 2000000
  29. max_video = 10
  30. crowdhuman_json = json.load(open('datasets/crowdhuman/annotations/train.json','r'))
  31. img_id_count = 0
  32. for img in crowdhuman_json['images']:
  33. img_id_count += 1
  34. img['file_name'] = 'crowdhuman_train/' + img['file_name']
  35. img['frame_id'] = img_id_count
  36. img['prev_image_id'] = img['id'] + max_img
  37. img['next_image_id'] = img['id'] + max_img
  38. img['id'] = img['id'] + max_img
  39. img['video_id'] = max_video
  40. img_list.append(img)
  41. for ann in crowdhuman_json['annotations']:
  42. ann['id'] = ann['id'] + max_ann
  43. ann['image_id'] = ann['image_id'] + max_img
  44. ann_list.append(ann)
  45. print('crowdhuman_train')
  46. video_list.append({
  47. 'id': max_video,
  48. 'file_name': 'crowdhuman_train'
  49. })
  50. max_img = 30000
  51. max_ann = 10000000
  52. crowdhuman_val_json = json.load(open('datasets/crowdhuman/annotations/val.json','r'))
  53. img_id_count = 0
  54. for img in crowdhuman_val_json['images']:
  55. img_id_count += 1
  56. img['file_name'] = 'crowdhuman_val/' + img['file_name']
  57. img['frame_id'] = img_id_count
  58. img['prev_image_id'] = img['id'] + max_img
  59. img['next_image_id'] = img['id'] + max_img
  60. img['id'] = img['id'] + max_img
  61. img['video_id'] = max_video
  62. img_list.append(img)
  63. for ann in crowdhuman_val_json['annotations']:
  64. ann['id'] = ann['id'] + max_ann
  65. ann['image_id'] = ann['image_id'] + max_img
  66. ann_list.append(ann)
  67. print('crowdhuman_val')
  68. video_list.append({
  69. 'id': max_video,
  70. 'file_name': 'crowdhuman_val'
  71. })
  72. max_img = 40000
  73. max_ann = 20000000
  74. ethz_json = json.load(open('datasets/ETHZ/annotations/train.json','r'))
  75. img_id_count = 0
  76. for img in ethz_json['images']:
  77. img_id_count += 1
  78. img['file_name'] = 'ethz_train/' + img['file_name'][5:]
  79. img['frame_id'] = img_id_count
  80. img['prev_image_id'] = img['id'] + max_img
  81. img['next_image_id'] = img['id'] + max_img
  82. img['id'] = img['id'] + max_img
  83. img['video_id'] = max_video
  84. img_list.append(img)
  85. for ann in ethz_json['annotations']:
  86. ann['id'] = ann['id'] + max_ann
  87. ann['image_id'] = ann['image_id'] + max_img
  88. ann_list.append(ann)
  89. print('ETHZ')
  90. video_list.append({
  91. 'id': max_video,
  92. 'file_name': 'ethz'
  93. })
  94. max_img = 50000
  95. max_ann = 25000000
  96. cp_json = json.load(open('datasets/Cityscapes/annotations/train.json','r'))
  97. img_id_count = 0
  98. for img in cp_json['images']:
  99. img_id_count += 1
  100. img['file_name'] = 'cp_train/' + img['file_name'][11:]
  101. img['frame_id'] = img_id_count
  102. img['prev_image_id'] = img['id'] + max_img
  103. img['next_image_id'] = img['id'] + max_img
  104. img['id'] = img['id'] + max_img
  105. img['video_id'] = max_video
  106. img_list.append(img)
  107. for ann in cp_json['annotations']:
  108. ann['id'] = ann['id'] + max_ann
  109. ann['image_id'] = ann['image_id'] + max_img
  110. ann_list.append(ann)
  111. print('Cityscapes')
  112. video_list.append({
  113. 'id': max_video,
  114. 'file_name': 'cityperson'
  115. })
  116. mix_json = dict()
  117. mix_json['images'] = img_list
  118. mix_json['annotations'] = ann_list
  119. mix_json['videos'] = video_list
  120. mix_json['categories'] = category_list
  121. json.dump(mix_json, open('datasets/mix_det/annotations/train.json','w'))