首页 > 其他分享 >yoloV1 bbox标签转换为yolo

yoloV1 bbox标签转换为yolo

时间:2022-12-29 21:56:23浏览次数:45  
标签:yoloV1 yolo label cy cx grid bbox size

import numpy as np


def convert_bbox2labels(bboxes):
    """
    :param bboxes:(N,5)的bbox信息列表
    :return:(30,7,7)的yolov1格式的label,需要将(cls_index,dx,dy,dw,dh)转换成(cx,cy,dw,dh,confidence,cx,cy,dw,dh,confidence,....)

    tips:(30,7,7) = (info_dim,x,y)
    这里进来的值相当于是已经归一化了的
    """
    grid_size = 1 / 7.0
    label = np.zeros(shape=(30, 7, 7))
    # 遍历每一个bbox,把它放入该放的地方
    for i in range(len(bboxes)):
        bbox = bboxes[i]
        # 获取中心点所在-下标-
        grid_x = int(bbox[1] // grid_size) #grid_x\grid_y 是物体中心点所在网格的左上角坐标位置
        grid_y = int(bbox[2] // grid_size)
        cx = bbox[1] / grid_size - grid_x #cx\cy 是物体中心点相对于网格的偏移距离 0~1
        cy = bbox[2] / grid_size - grid_y
        label[0:5, grid_x, grid_y] = np.array([cx, cy, bbox[3], bbox[4], 1]) # 第一个bounding_box
        label[5:10, grid_x, grid_y] = np.array([cx, cy, bbox[3], bbox[4], 1]) # 第二个bounding_box
        label[10 + int(bbox[0]), grid_x, grid_y] = 1 # 类别概率
    return label

标签:yoloV1,yolo,label,cy,cx,grid,bbox,size
From: https://www.cnblogs.com/tccjx/p/17013629.html

相关文章