Python tool method 41 resize data in VOC|YOLO format

In target detection, compared with the yolo format, both the voc format and the coco format use absolute values ​​to describe the size of boxes, which has certain defects in the fusion of multiple data sets. Especially when there are ultra-high-definition images (the existence of ultra-high-definition images in the data set usually makes the dataloader memory insufficient, or causes data loading to freeze), we cannot only resize the image (we also need to resize the xml or json file at the same time The described boxes are scaled accordingly). For this purpose, the resize operation of yolo data and voc data is realized.

For yolo data, you can directly resize large images in batches; for voc data, you need to convert it to yolo format first, then resize the image in yolo format, and finally convert the yolo format data to voc format .

1, yolo format data resize

yolo format data resize, no additional operations are required, just use the following code.
The root in the code is the storage path of the image in the yolo format data, and max_height is the maximum height of the limited image (images larger than this height will be resized to this height in equal proportions)

import cv2
import os
root='./images/'
max_height=

Guess you like

Origin blog.csdn.net/a486259/article/details/131175043