def preprocess(image):
"""Takes an image and apply preprocess"""
# ????????????
image = cv2.resize(image, (data_shape, data_shape))
# ?? BGR ? RGB
image = image[:, :, (2, 1, 0)]
# ?mean?????float
image = image.astype(np.float32)
# ? mean
image -= np.array([123, 117, 104])
# ??? [batch-channel-height-width]
image = np.transpose(image, (2, 0, 1))
image = image[np.newaxis, :]
# ?? ndarray
image = nd.array(image)
return image
评论列表
文章目录