utils.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:real_time_face_detection 作者: Snowapril 项目源码 文件源码
def horizontal_flip(imgs, labels):
    if imgs.ndim != 2:
        print("Image dimension must be 2")
        raise Exception

    if imgs.shape[0] != labels.shape[0]:
        print("Images num and labels num must be equal")
        raise Exception

    #flip the img horizontally
    imgs = imgs.reshape(-1, 96, 96)
    imgs = np.flip(imgs, axis=2)
    imgs = imgs.reshape(-1, 96*96)

    #when flip the image horizontally, img's ypos does not change but xpos reflect on img's center pos
    result = np.copy(labels)

    for idx in range(labels.shape[0]):
        result[idx][::2] = 96 - result[idx][::2]

    return imgs, labels
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号