def reshape_to_yolo_size(img):
input_width, input_height = img.size
min_pixel = 320.0
#max_pixel = 608
max_pixel = 1024.0
min_edge = np.minimum(input_width, input_height)
if min_edge < min_pixel:
input_width *= min_pixel / min_edge
input_height *= min_pixel / min_edge
max_edge = np.maximum(input_width, input_height)
if max_edge > max_pixel:
input_width *= max_pixel / max_edge
input_height *= max_pixel / max_edge
input_width = int(input_width / 32.0 + round(input_width % 32 / 32.0)) * 32
input_height = int(input_height / 32.0 + round(input_height % 32 / 32.0)) * 32
img = img.resize((input_width, input_height))
return img
评论列表
文章目录