【发布时间】:2021-09-11 07:32:51
【问题描述】:
我收到了 jpg 格式的图像数据集和 JSON 格式的标签,但我在尝试使用暗网 yolov4 进行训练时遇到了问题。
JSON格式的标签如下。
"annotations": [
{
"image_id": 0,
"file_name": "image_47010552850673.jpg",
"objects": [
{
"object_id": 0,
"class": "person",
"position": [1480, 151, 1508, 169]
},
{
"object_id": 1,
"class": "car",
"position": [792, 123, 843, 246]
},
{
"object_id": 2,
"class": "person",
"position": [245, 667, 286, 695]
}
]
},
{
"image_id": 1,
"file_name": "image_68475401035381.jpg",
"objects": [
{
"object_id": 3,
"class": "person",
"position": [1090, 374, 1096, 389]
},
{
"object_id": 4,
"class": "car",
"position": [1279, 620, 1346, 655]
}
]
}, ...
位置的格式如下。
position = [xmin, ymin, xmax, ymax] <- pixel values
总共有六个类,每个标签类对应的编号如下。
汽车:0,卡车:1,公共汽车:2,等等车辆:3,自行车:4,人:5
图片尺寸为 1920x1080
它有大约 100,000 张图像和 36GB 的容量。
所有图像都标记在一个 JSON 文件中,JSON 文件的容量约为 124 MB。
我想把上面的JSON文件转换成标准化yolo格式的文本文件。
例如)
文件名:image_name.txt
内容:
class_number normalized_center_x normalized_center_y normalized_width normalized_height
另外,
normalized_centered_x = (xmin+xmax)÷2÷x_sizeof_image
normalized_centered_y = (ymin+ymax)÷2÷y_sizeof_image
normalized_width = (xmax-xmin)÷x_sizeof_image
normalized_height = (ymax-ymin)÷y_sizeof_image
就我而言,
normalized_centered_x = (位置[0]+位置[2])÷2÷1920
normalized_centered_y = (位置[1]+位置[3])÷2÷1080
normalized_width = (位置[2]-位置[0])÷1920
normalized_height = (位置[3]-位置[1])÷1080
上述json的darknet yolov4 txt文件列表实际示例如下。
文件名:image_47010552850673.txt
内容:
5 0.778125 0.148148148 0.014583333 0.016666667
0 0.42578125 0.170833333 0.0265625 0.113888889
5 0.13828125 0.630555556 0.021354167 0.025925926
文件名:image_68475401035381.txt
内容:
5 0.569270833 0.353240741 0.003125 0.013888889
0 0.68359375 0.590277778 0.034895833 0.032407407
如何在 Python 中做到这一点?
【问题讨论】:
标签: python json object-detection yolo darknet