(image, net, scale, threshold)
return boxes[keep]
Run P-Net, generate bounding boxes, and do NMS.

    Arguments:
        image: an instance of PIL.Image.
        net: an instance of pytorch's nn.Module, P-Net.
        scale: a float number,
            scale width and height of the image by this number.
        threshold: a float number,
            threshold on the probability of a face when generating
            bounding boxes from predictions of the net.

    Returns:
        a float numpy array of shape [n_boxes, 9],
            bounding boxes with scores and offsets (4 + 1 + 4).
Run P-Net, generate bounding boxes, and do NMS.
Run P - Net generate bounding boxes and do NMS .
def run_first_stage(image, net, scale, threshold):
    """Run P-Net, generate bounding boxes, and do NMS.

    Arguments:
        image: an instance of PIL.Image.
        net: an instance of pytorch's nn.Module, P-Net.
        scale: a float number,
            scale width and height of the image by this number.
        threshold: a float number,
            threshold on the probability of a face when generating
            bounding boxes from predictions of the net.

    Returns:
        a float numpy array of shape [n_boxes, 9],
            bounding boxes with scores and offsets (4 + 1 + 4).
    """

    # scale the image and convert it to a float array
    width, height = image.size
    sw, sh = math.ceil(width*scale), math.ceil(height*scale)
    img = image.resize((sw, sh), Image.BILINEAR)
    img = np.asarray(img, 'float32')
    #img = Variable(torch.FloatTensor(_preprocess(img)), volatile=True)
    with torch.no_grad():
        img = torch.FloatTensor(_preprocess(img))
    output = net(img)
    probs = output[1].data.numpy()[0, 1, :, :]
    offsets = output[0].data.numpy()
    # probs: probability of a face at each sliding window
    # offsets: transformations to true bounding boxes

    boxes = _generate_bboxes(probs, offsets, scale, threshold)
    if len(boxes) == 0:
        return None

    keep = nms(boxes[:, 0:5], overlap_threshold=0.5)
    return boxes[keep]
def run_first_stage ( image , net , scale , threshold ) : # scale the image and convert it to a float array width , height = image . size sw , sh = math . ceil ( width * scale ) , math . ceil ( height * scale ) img = image . resize ( ( sw , sh ) , Image . BILINEAR ) img = np . asarray ( img , 'float32' ) #img = Variable(torch.FloatTensor(_preprocess(img)), volatile=True) with torch . no_grad ( ) : img = torch . FloatTensor ( _preprocess ( img ) ) output = net ( img ) probs = output [ 1 ] . data . numpy ( ) [ 0 , 1 , : , : ] offsets = output [ 0 ] . data . numpy ( ) # probs: probability of a face at each sliding window # offsets: transformations to true bounding boxes boxes = _generate_bboxes ( probs , offsets , scale , threshold ) if len ( boxes ) == 0 : return None keep = nms ( boxes [ : , 0 : 5 ] , overlap_threshold = 0.5 ) return boxes [ keep ]