retinaface自定义增强

宽高分别裁剪增强

import cv2
import numpy as np
import random
from utils.box_utils import matrix_iof


def _crop(image, boxes, labels, img_size):
    #随意裁剪,裁剪到最后resize,会有放大效果,不会缩小,小目标检测无帮助
    height, width, _ = image.shape
    pad_image_flag = True
    if boxes[0][1] == 0:
        scale = random.uniform(0.3, 1.0)
        crop_height = int(scale * height)
        crop_width = int(scale * width)

        crop_left = 0
        if width != crop_width:
            crop_left = random.randrange(width - crop_width)
        crop_top = 0
        if height != crop_height:
            crop_top = random.randrange(height - crop_height)
        roi = np.array((crop_left, crop_top, crop_left + crop_width, crop_top + crop_height))

        image_t = image[roi[1]:roi[3], roi[0]:roi[2]]
        pad_image_flag = False
        return image_t, boxes, labels, pad_

你可能感兴趣的:(深度学习宝典,python宝典)