因为论文里面关于数据集介绍的部分想要放一下数据集关于大中小三类目标的比例,所以写了个脚本来计算,需要的自取:
import json
def calculate_area(bbox):
# 计算bbox的像素面积
width = bbox[2]
height = bbox[3]
area = width * height
return area
def categorize_object(size):
# 根据像素面积判断目标大小
if size < 32*32:
return "小"
elif size < 96*96:
return "中"
else:
return "大"
def count_object_sizes(data):
small_count = 0
medium_count = 0
large_count = 0
i = 1
d_number = 0
a = 0
for annotation in data['annotations']:
print("当前是图片的是",annotation["image_id"])
bbox = annotation['bbox']
area = calculate_area(bbox)
size_category = categorize_object(area)
sc = small_count
mc = medium_count
lc = large_count
# 根据目标大小类别进行统计
if size_category == "小":
small_count += 1
elif size_category == "中":
medium_count += 1
else:
large_