Faceboxes pytorch代码解读(一) box_utils.py(上篇)

Faceboxes pytorch代码解读(一) box_utils.py(上篇)

有幸读到Shifeng Zhang老师团队的人脸检测论文,感觉对自己的人脸学习论文十分有帮助。通过看别人的paper,学习别人的代码,能够使得我们对人脸检测算法的学习有更近一步的理解。
但是在学习的时候发现,自己看别人的代码是一个耗时而又头疼的事情。毕竟每个人的思路都不一样,跟着别人的思路走确实不容易。所以希望能够分享一下自己在学习代码时的理解,希望对刚刚入门的你们有所帮助。
我也是深度学习的小白一枚,如若出现错误希望大佬们能够指正,谢谢!

论文原文地址:http://www.cbsr.ia.ac.cn/users/sfzhang/Shifeng%20Zhang’s%20Homepage_files/FaceBoxes_NC.pdf

github代码地址:
https://github.com/zisianw/FaceBoxes.PyTorch

point_form()函数

功能:将坐标由(cx,cy,w,h)形式转换为(xmin, ymin, xmax, ymax)形式

def point_form(boxes):#将坐标由(cx,cy,w,h)形式转换为(xmin, ymin, xmax, ymax)形式
    """ Convert prior_boxes to (xmin, ymin, xmax, ymax)
    representation for comparison to point form ground truth data.
    Args:
        boxes: (tensor) center-size default boxes from priorbox layers.
    Return:
        boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes.
    """
    return torch.cat((boxes[:, :2] - boxes[:, 2:]/2,     # xmin, ymin
                     boxes[:, :2] + boxes[:, 2:]/2), 1)  # xmax, ymax
    #torch.cat是将两个张量(tensor)拼接在一起 维度1表示进行横向拼接

center_size()函数

功能:将坐标由(xmin, ymin, xmax, ymax)形式转换为(cx,cy,w,h)形式

def center_size(boxes):#将坐标由(xmin, ymin, xmax, ymax)形式转换为(cx,cy,w,h)形式
    """ Convert prior_boxes to (cx, cy, w, h)
    representation for comparison to center-size form ground truth data.
    Args:
        boxes: (tensor) point_form boxes
    Return:
        boxes: (tensor) Converted xmin, ymin, xmax, ymax form of boxes.
    """
    return torch.cat((boxes[:, 2:] + boxes[:, :2])/2,  # cx, cy
                     boxes[:

你可能感兴趣的:(pytorch,深度学习,神经网络,python,算法)