常见的bbox标注格式

在图像上标记目标的矩形(bounding box, bbox)。常见的标注格式为Pascal VOC、COCO、YOLO

Pascal VOC

bbox:[x_min, y_min, x_max, y_max]

格式:左上右下

COCO

bbox:[x_min, ymin, width, height]

格式:左上宽高

YOLO

bbox [x_center, y_center, width, height]

并进行数据规范化(normalized)

格式:中心坐标,宽高

Pasic VOC 转 YOLO

def convert_box(size, box):
    # Convert VOC box to YOLO xywh box
    dw = 1. / size[0]
    dh = 1. / size[1]
return ((box[0] + box[1]) / 2.0 * dw, (box[2] + box[3]) / 2.0 * dh , (box[1] - box[0]) * dw, (box[3] - box[2]) * * dh)

COCO 转 YOLO

    def convert_box(size, box):
        # Convert COCO box to YOLO xywh box
        dw = 1. / size[0]
        dh = 1. / size[1]

        return (box[0] + box[2] / 2) * dw, (box[1] + box[3] / 2) * dh, box[2] * dw, box[3] * dh

YOLO Decode

def xywhn2xyxy(x, w=640, h=640, padw=0, padh=0):
    # 将yolo格式的box直接读取
    # Convert nx4 boxes from [x, y, w, h] normalized to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right
    y = x.clone() if isinstance(x, torch.Tensor) else np.copy(x)
    y[:, 0] = w * (x[:, 0] - x[:, 2] / 2) + padw  # top left x
    y[:, 1] = h * (x[:, 1] - x[:, 3] / 2) + padh  # top left y
    y[:, 2] = w * (x[:, 0] + x[:, 2] / 2) + padw  # bottom right x
    y[:, 3] = h * (x[:, 1] + x[:, 3] / 2) + padh  # bottom right y
    return y
COCO(Common Objects in Context)数据集是计算机视觉领域广泛使用的数据集之一,其标注文件的命名方式和格式具有一定的规范性。通常,COCO数据集的标注文件以 `.json` 格式存储,并按照训练集、验证集以及任务类型进行分类。 常见的COCO标注文件命名方式如下: - `instances_train2017.json` - `instances_val2017.json` - `captions_train2017.json` - `person_keypoints_train2017.json` - `person_keypoints_val2017.json` 其中: - `instances` 表示目标检测任务中的实例分割标注; - `captions` 表示图像描述任务的标注; - `person_keypoints` 表示人体关键点检测任务的标注; - `train2017` 和 `val2017` 分别表示2017年的训练集和验证集。 这些标注文件的结构通常包含多个字段,例如 `images`、`annotations`、`categories` 等,分别记录图像信息、标注信息以及类别定义。以下是COCO标注文件的一个简化结构示例: ```json { "images": [ { "id": 1, "file_name": "000000001.jpg", "width": 640, "height": 480 } ], "annotations": [ { "id": 1, "image_id": 1, "category_id": 1, "bbox": [100, 100, 200, 200], "area": 40000, "iscrowd": 0 } ], "categories": [ { "id": 1, "name": "person" } ] } ``` 在实际应用中,标注文件的内容需与图像文件相对应,确保每个标注条目都能正确关联到对应的图像[^2]。此外,为了便于模型训练和评估,建议遵循官方提供的文件组织结构,并保持标注文件和图像文件路径的一致性。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值