image-processing - COWC 数据集注释

标签 image-processing keras deep-learning annotations retinanet

我是深度学习的新手。目前,我正在做一个项目,使用 Retinanet 模型检测航空图像中的汽车,我计划使用 COWC 数据集。我对标注部分有疑问,目前我正在使用labelImg标注工具来标注航拍图像中的汽车。由于 labelImg 生成 xml 格式的注释,我已将其转换为下面提到的 Retinanet 模型所需的格式。

(图像名称)(边界框坐标)(类名称)

还有其他方法可以使 COWC 数据集中的注释变得更容易吗?

提前致谢:)

最佳答案

COWC 数据集附带注释,其中每辆车都标有一个点。 PNG 文件包含注释。以下是我在 PNG 文件中查找注释位置的方法。

import numpy as np
from PIL import Image

annotation_path = 'cowc/datasets/ground_truth_sets/Toronto_ISPRS/03553_Annotated_Cars.png'
im = Image.open(annotation_path)
data = np.asarray(im)

这里的问题是这两个值都将被索引为非零,但我们只需要其中一个。 COWC 数据集用红点标记汽车,用蓝点标记负数,我们不需要 Alpha channel ,因此需要对新数组进行切片,这样我们就不会计算 Alpha channel 并获得重复的索引值。

data = data[:,:,0:3]
y_ind, x_ind, rgba_ind = data.nonzero()

您现在拥有注释文件中所有点的索引。 y_ind 对应于高度尺寸,x_ind 对应于宽度。这意味着在第一个 x, y 位置,我们应该看到一个类似于 [255, 0, 0] 的数组。这是当我从索引查找第一个 x, y 位置时得到的结果

>>> data[y_ind[0], x_ind[0]]
array([255,   0,   0], dtype=uint8)

Here作者决定创建一个边界框,其一侧为 20 像素,以数据集中提供的注释为中心。要为此图像中的第一个注释创建单个边界框,您可以尝试这样做。

# define bbox given x, y and ensure bbox is within image bounds
def get_bbox(x, y, x_max, y_max):
    x1 = max(0, x - 20)     # returns zero if x-20 is negative
    x2 = min(x_max, x + 20) # returns x_max if x+20 is greater than x_max
    y1 = max(0, y - 20)
    y2 = min(y_max, y + 20)
    return x1, y1, x2, y2

x1, y1, x2, y2 = get_bbox(x_ind[0], y_ind[0], im.width, im.height) 

您必须循环遍历所有 x、y 值才能制作图像的所有边界框。这是为单个图像创建 csv 文件的一种粗糙而肮脏的方法。

img_path = 'cowc/datasets/ground_truth_sets/Toronto_ISPRS/03553.png'
with open('anno.csv', 'w') as f:
    for x, y in zip(x_ind, y_ind):
        x1, y1, x2, y2 = get_bbox(x, y, im.width, im.height)
        line = f'{img_path},{x1},{y1},{x2},{y2},car\n'
        f.write(line)

我计划将一个巨大的图像分解成更小的图像,这将改变边界框的值。我希望您觉得本文很有帮助,并且是一个很好的起点。

关于image-processing - COWC 数据集注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59334163/

相关文章:

machine-learning - 如果您使用批量归一化,是否需要标准化输入?

android - 卡住 Android 的 tensor_forest 图

python - 使用opencv查找两个多边形之间的最大和最小距离

image-processing - 如何计算图像的逆平稳小波变换?

python - 将类信息添加到 keras 网络

optimization - Pytorch - backward() 函数应该在 epoch 或 batch 的循环中吗?

python-3.x - Dropout 和批量归一化 - 层的顺序重要吗?

c++ - 使蒙版外全部透明

c++ - 特定颜色范围内的阈值图像

python - 检查输入 : expected input_1 to have 4 dimensions, 但获得形状为 (224, 224, 3) 的数组时出错