目标检测数据集目标尺度分析

该文主要对目标检测数据集进行尺度分析,包括计算目标的绝对尺度和相对尺度。通过`numpy`和`matplotlib`库处理DOTA数据集,提取边界框并转换为最小外接矩形,进一步计算尺度。文章还展示了如何绘制尺度的直方图,用于理解不同目标的尺度分布情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目标检测数据集目标尺度分析

尺度计算

计算公式分绝对尺度和相对尺度:
A S ( G i j ) = w i j ∗ h i j R S ( G i j ) = w i j ∗ h i j W i ∗ H i \begin{aligned} A S\left(G_{i j}\right) & =\sqrt{w_{i j} * h_{i j}} \\ R S\left(G_{i j}\right) & =\sqrt{\frac{w_{i j} * h_{i j}}{W_{i} * H_{i}}} \end{aligned} AS(Gij)RS(Gij)=wijhij =WiHiwijhij

代码

import os
import os.path
import numpy as np
import cv2
import matplotlib.pyplot as plt

train_list = os.listdir("/data/facias/DOTA/train_split/labelTxt")
base_path = "/data/facias/DOTA/train_split/labelTxt/"

def poly2obb_np_le90(poly):
    bboxps = np.array(poly).reshape((4, 2))
    rbbox = cv2.minAreaRect(bboxps)
    x, y, w, h, a = rbbox[0][0], rbbox[0][1], rbbox[1][0], rbbox[1][1], rbbox[
        2]
    if w < 2 or h < 2:
        return
    a = a / 180 * np.pi
    if w < h:
        w, h = h, w
        a += np.pi / 2
    while not np.pi / 2 > a >= -np.pi / 2:
        if a >= np.pi / 2:
            a -= np.pi
        else:
            a += np.pi
    assert np.pi / 2 > a >= -np.pi / 2
    return x, y, w, h, a

total_dict = {}
relative_max = 0
relative_min = 0
isum = 0
number = 0

for file in train_list:
    with open(base_path + file) as f:
        s = f.readlines()
        for si in s:
            bbox_info = si.split()
            poly = np.array(bbox_info[:8], dtype=np.float32)
            label = bbox_info[8]
            try:
                x, y, w, h, a = poly2obb_np_le90(poly)
            except:  # noqa: E722
                continue
            absolute_size = pow((w * h), 0.5)
            relative_size = pow((w * h) / (1024.0 * 1024.0), 0.5)

            if relative_size > relative_max:
                relative_max = relative_size
            elif relative_size < relative_min:
                relative_min = relative_size
            isum = isum + relative_size
            number = number + 1

            if label not in total_dict.keys():
                total_dict[label] = {}
                total_dict[label]['absolute'] = []
                total_dict[label]['relative'] = []
                total_dict[label]['absolute'].append(absolute_size)
                total_dict[label]['relative'].append(relative_size)
            else:
                total_dict[label]['absolute'].append(absolute_size)
                total_dict[label]['relative'].append(relative_size)

#画直方图
for label in total_dict:
    medium = isum / number
    label_dict = total_dict[label]
    relative_list = total_dict[label]['relative']
    relative_np = np.array(relative_list)
    # hist, bins = np.histogram(relative_np, bins=50, range=(relative_min, relative_max))
    plt.hist(relative_np, bins=200, histtype='stepfilled', alpha=0.3)
    plt.savefig('./' + label + '.jpg')
    plt.clf()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值