python类fix()的实例源码

util.py 文件源码 项目:wradlib 作者: wradlib 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def filter_window_cartesian(img, wsize, fun, scale, **kwargs):
    r"""Apply a filter of square window size `fsize` on a given
    cartesian image `img`.

    Parameters
    ----------
    img : :class:`numpy:numpy.ndarray`
        2d array of values to which the filter is to be applied
    wsize : float
        Half size of the window centred on the pixel [m]
    fun : string
        name of the 2d filter from :mod:`scipy:scipy.ndimage`
    scale : tuple of 2 floats
        x and y scale of the cartesian grid [m]

    Returns
    -------
    output : :class:`numpy:numpy.ndarray`
        Array with the same shape as `img`, containing the filter's results.

    """
    fun = getattr(filters, "%s_filter" % fun)
    size = np.fix(wsize / scale + 0.5).astype(int)
    data_filtered = fun(img, size, **kwargs)
    return data_filtered
detect_and_align.py 文件源码 项目:FaceRecognition 作者: habrman 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride = 2
    cellsize = 12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:, :, 0])
    dy1 = np.transpose(reg[:, :, 1])
    dx2 = np.transpose(reg[:, :, 2])
    dy2 = np.transpose(reg[:, :, 3])
    y, x = np.where(imap >= t)
    if y.shape[0] == 1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y, x)]
    reg = np.transpose(np.vstack([dx1[(y, x)], dy1[(y, x)], dx2[(y, x)], dy2[(y, x)]]))
    if reg.size == 0:
        reg = np.empty((0, 3))
    bb = np.transpose(np.vstack([y, x]))
    q1 = np.fix((stride * bb + 1) / scale)
    q2 = np.fix((stride * bb + cellsize - 1 + 1) / scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score, 1), reg])
    return boundingbox, reg
estimation.py 文件源码 项目:psola 作者: jcreinhold 项目源码 文件源码 阅读 51 收藏 0 点赞 0 评论 0
def pitch_strength_all_candidates(f_erbs, L, pc):
    """
    Calculates the pitch ``strength'' of all candidate
    pitches

    Args:
        f_erbs (array): frequencies in ERBs
        L     (matrix): loudness matrix
        pc     (array): pitch candidates array

    Returns:
        S   (array): strength of pitches corresponding to pc's
    """
    # create pitch strength matrix
    S = np.zeros((pc.size, L.shape[1]))

    # define integration regions
    k = np.zeros(pc.size+1)

    for j in range(k.size-1):
        idx = int(k[j])
        f = f_erbs[idx:]
        val = find(f > pc[j] / 4)[0]
        k[j+1] = k[j] + val

    k = k[1:]  # TODO: fix this sloppiness

    # create loudness normalization matrix
    N = np.sqrt(np.flipud(np.cumsum(np.flipud(L * L), 0)))
    for j in range(pc.size):
        # normalize loudness
        n = N[int(k[j]), :]
        n[n == 0] = -np.inf  # to make zero-loudness equal zero after normalization
        nL = L[int(k[j]):] / np.tile(n, (int(L.shape[0] - k[j]), 1))

        # compute pitch strength
        S[j] = pitch_strength_one_candidate(f_erbs[int(k[j]):], nL, pc[j])

    return S
tools_matrix.py 文件源码 项目:keras-mtcnn 作者: xiangrufan 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def detect_face_12net(cls_prob,roi,out_side,scale,width,height,threshold):
    in_side = 2*out_side+11
    stride = 0
    if out_side != 1:
        stride = float(in_side-12)/(out_side-1)
    (x,y) = np.where(cls_prob>=threshold)
    boundingbox = np.array([x,y]).T
    bb1 = np.fix((stride * (boundingbox) + 0 ) * scale)
    bb2 = np.fix((stride * (boundingbox) + 11) * scale)
    boundingbox = np.concatenate((bb1,bb2),axis = 1)
    dx1 = roi[0][x,y]
    dx2 = roi[1][x,y]
    dx3 = roi[2][x,y]
    dx4 = roi[3][x,y]
    score = np.array([cls_prob[x,y]]).T
    offset = np.array([dx1,dx2,dx3,dx4]).T
    boundingbox = boundingbox + offset*12.0*scale
    rectangles = np.concatenate((boundingbox,score),axis=1)
    rectangles = rect2square(rectangles)
    pick = []
    for i in range(len(rectangles)):
        x1 = int(max(0     ,rectangles[i][0]))
        y1 = int(max(0     ,rectangles[i][1]))
        x2 = int(min(width ,rectangles[i][2]))
        y2 = int(min(height,rectangles[i][3]))
        sc = rectangles[i][4]
        if x2>x1 and y2>y1:
            pick.append([x1,y1,x2,y2,sc])
    return NMS(pick,0.3,'iou')
gen_onet_widerface.py 文件源码 项目:mtcnn 作者: daikankan 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def generateBoundingBox(map, reg, scale, t):
    stride = 2
    cellsize = 12
    map = map.T
    dx1 = reg[0,:,:].T
    dy1 = reg[1,:,:].T
    dx2 = reg[2,:,:].T
    dy2 = reg[3,:,:].T
    (x, y) = np.where(map >= t)

    yy = y
    xx = x


    score = map[x,y]
    reg = np.array([dx1[x,y], dy1[x,y], dx2[x,y], dy2[x,y]])

    if reg.shape[0] == 0:
        pass
    boundingbox = np.array([yy, xx]).T

    bb1 = np.fix((stride * (boundingbox) + 1) / scale).T # matlab index from 1, so with "boundingbox-1"
    bb2 = np.fix((stride * (boundingbox) + cellsize - 1 + 1) / scale).T # while python don't have to
    score = np.array([score])

    boundingbox_out = np.concatenate((bb1, bb2, score, reg), axis=0)

    return boundingbox_out.T
gen_onet_celeba.py 文件源码 项目:mtcnn 作者: daikankan 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def generateBoundingBox(map, reg, scale, t):
    stride = 2
    cellsize = 12
    map = map.T
    dx1 = reg[0,:,:].T
    dy1 = reg[1,:,:].T
    dx2 = reg[2,:,:].T
    dy2 = reg[3,:,:].T
    (x, y) = np.where(map >= t)

    yy = y
    xx = x


    score = map[x,y]
    reg = np.array([dx1[x,y], dy1[x,y], dx2[x,y], dy2[x,y]])

    if reg.shape[0] == 0:
        pass
    boundingbox = np.array([yy, xx]).T

    bb1 = np.fix((stride * (boundingbox) + 1) / scale).T # matlab index from 1, so with "boundingbox-1"
    bb2 = np.fix((stride * (boundingbox) + cellsize - 1 + 1) / scale).T # while python don't have to
    score = np.array([score])

    boundingbox_out = np.concatenate((bb1, bb2, score, reg), axis=0)

    return boundingbox_out.T
detect_util.py 文件源码 项目:tensorflow_face 作者: ZhihengCV 项目源码 文件源码 阅读 108 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0] == 1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size == 0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg


# function pick = nms(boxes,threshold,type)
detect_face.py 文件源码 项目:faceNet_RealTime 作者: jack55436001 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
est_rel_entro_HJW.py 文件源码 项目:HJW_KL_divergence_estimator 作者: Mathegineer 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def formalize_sample(samp):
    samp = np.array(samp)
    if np.any(samp != np.fix(samp)):
        raise ValueError('Input sample must only contain integers.')
    if samp.ndim == 1 or samp.ndim == 2 and samp.shape[0] == 1:
        samp = samp.reshape((samp.size, 1))
    return samp
est_rel_entro_MLE.py 文件源码 项目:HJW_KL_divergence_estimator 作者: Mathegineer 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def formalize_sample(samp):
    samp = np.array(samp)
    if np.any(samp != np.fix(samp)):
        raise ValueError('Input sample must only contain integers.')
    if samp.ndim == 1 or samp.ndim == 2 and samp.shape[0] == 1:
        samp = samp.reshape((samp.size, 1))
    return samp
detect_face.py 文件源码 项目:icyface_api 作者: bupticybee 项目源码 文件源码 阅读 49 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
exact_rep.py 文件源码 项目:drmad 作者: bigaidream-projects 项目源码 文件源码 阅读 66 收藏 0 点赞 0 评论 0
def float_to_rational(self, a):
        assert np.all(a > 0.0)
        d = 2**16 / np.fix(a+1).astype(int) # Uglier than it used to be: np.int(a + 1)
        n = np.fix(a * d + 1).astype(int)
        return  n, d
detect_face.py 文件源码 项目:real_time_face_recognition 作者: shanren7 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
index.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def to_julian_date(self):
        """
        Convert DatetimeIndex to Float64Index of Julian Dates.
        0 Julian date is noon January 1, 4713 BC.
        http://en.wikipedia.org/wiki/Julian_day
        """

        # http://mysite.verizon.net/aesir_research/date/jdalg2.htm
        year = self.year
        month = self.month
        day = self.day
        testarr = month < 3
        year[testarr] -= 1
        month[testarr] += 12
        return Float64Index(day +
                            np.fix((153 * month - 457) / 5) +
                            365 * year +
                            np.floor(year / 4) -
                            np.floor(year / 100) +
                            np.floor(year / 400) +
                            1721118.5 +
                            (self.hour +
                             self.minute / 60.0 +
                             self.second / 3600.0 +
                             self.microsecond / 3600.0 / 1e+6 +
                             self.nanosecond / 3600.0 / 1e+9
                             ) / 24.0)
test_indexing.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_getitem_setitem_ellipsis(self):
        s = Series(np.random.randn(10))

        np.fix(s)

        result = s[...]
        assert_series_equal(result, s)

        s[...] = 5
        self.assertTrue((result == 5).all())
test_indexing.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_reindex_corner(self):
        # (don't forget to fix this) I think it's fixed
        self.empty.reindex(self.ts.index, method='pad')  # it works

        # corner case: pad empty series
        reindexed = self.empty.reindex(self.ts.index, method='pad')

        # pass non-Index
        reindexed = self.ts.reindex(list(self.ts.index))
        assert_series_equal(self.ts, reindexed)

        # bad fill method
        ts = self.ts[::2]
        self.assertRaises(Exception, ts.reindex, self.ts.index, method='foo')
detect_face.py 文件源码 项目:face 作者: xpzouying 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
cross_validation.py 文件源码 项目:pyEMG 作者: agamemnonc 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def _segpoints(self, stimulus):
        """Find segmentation points."""
        stim_diff = np.diff(stimulus)
        changepoints = np.nonzero(stim_diff)[0]
        changepoints = np.hstack([0, changepoints, stimulus.size])
        changepoints_diff = np.diff(changepoints)
        segpoints = changepoints[:-1] + np.fix(changepoints_diff/2)
        segpoints = segpoints[0::2] # Sub-sample every 2 points
        return segpoints
mtcnn_detector.py 文件源码 项目:prepare-faces-zyf 作者: walkoncross 项目源码 文件源码 阅读 52 收藏 0 点赞 0 评论 0
def generate_bboxes(scores_map, reg, scale, t):
    stride = 2
    cellsize = 12

    (y, x) = np.where(scores_map >= t)

    if len(y) < 1:
        return None

    scores = scores_map[y, x]

    dx1, dy1, dx2, dy2 = [reg[i, y, x] for i in range(4)]

    reg = np.array([dx1, dy1, dx2, dy2])

    bbox = np.array([y, x])
#    bb1 = np.fix((stride * bbox) / scale)
#    bb2 = np.fix((stride * bbox + cellsize) / scale)

    # !!! Use fix() for top-left point, and round() for bottom-right point
    # !!! So we can cover a 'whole' face !!! added by zhaoyafei 2017-07-18
    bb1 = np.fix((stride * bbox) / scale)
    bb2 = np.round((stride * bbox + cellsize) / scale)

#    print 'bb1.shape:', bb1.shape
#    print 'bb2.shape:', bb2.shape
#    print 'scores.shape:', scores.shape
#    print 'reg.shape:', reg.shape

    bbox_out = np.vstack((bb1, bb2, scores, reg))
#    print 'bbox_out.shape:', bbox_out.shape

    return bbox_out.T
detect_face.py 文件源码 项目:facenet 作者: davidsandberg 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    """Use heatmap to generate bounding boxes"""
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
mtcnn.py 文件源码 项目:Face-Recognition 作者: aswl01 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride = 2
    cellsize = 12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:, :, 0])
    dy1 = np.transpose(reg[:, :, 1])
    dx2 = np.transpose(reg[:, :, 2])
    dy2 = np.transpose(reg[:, :, 3])
    y, x = np.where(imap >= t)

    if y.shape[0] == 1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y, x)]
    reg = np.transpose(np.vstack([dx1[(y, x)], dy1[(y, x)], dx2[(y, x)], dy2[(y, x)]]))
    if reg.size == 0:
        reg = np.empty((0, 3))
    bb = np.transpose(np.vstack([y, x]))
    q1 = np.fix((stride * bb + 1) / scale)
    q2 = np.fix((stride * bb + cellsize - 1 + 1) / scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score, 1), reg])
    return boundingbox, reg


# function pick = nms(boxes,threshold,type)
mtcnn_detect.py 文件源码 项目:FaceRec 作者: vudung45 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride = 2
    cellsize = 12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:, :, 0])
    dy1 = np.transpose(reg[:, :, 1])
    dx2 = np.transpose(reg[:, :, 2])
    dy2 = np.transpose(reg[:, :, 3])
    y, x = np.where(imap >= t)
    if y.shape[0] == 1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y, x)]
    reg = np.transpose(np.vstack([dx1[(y, x)], dy1[(y, x)], dx2[(y, x)], dy2[(y, x)]]))
    if reg.size == 0:
        reg = np.empty((0, 3))
    bb = np.transpose(np.vstack([y, x]))
    q1 = np.fix((stride * bb + 1) / scale)
    q2 = np.fix((stride * bb + cellsize - 1 + 1) / scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score, 1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
tools_matrix.py 文件源码 项目:mtcnn-caffe 作者: CongWeilin 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def detect_face_12net(cls_prob,roi,out_side,scale,width,height,threshold):
    in_side = 2*out_side+11
    stride = 0
    if out_side != 1:
        stride = float(in_side-12)/(out_side-1)
    (x,y) = np.where(cls_prob>=threshold)
    boundingbox = np.array([x,y]).T
    bb1 = np.fix((stride * (boundingbox) + 0 ) * scale)
    bb2 = np.fix((stride * (boundingbox) + 11) * scale)
    boundingbox = np.concatenate((bb1,bb2),axis = 1)
    dx1 = roi[0][x,y]
    dx2 = roi[1][x,y]
    dx3 = roi[2][x,y]
    dx4 = roi[3][x,y]
    score = np.array([cls_prob[x,y]]).T
    offset = np.array([dx1,dx2,dx3,dx4]).T
    boundingbox = boundingbox + offset*12.0*scale
    rectangles = np.concatenate((boundingbox,score),axis=1)
    rectangles = rect2square(rectangles)
    pick = []
    for i in range(len(rectangles)):
    x1 = int(max(0     ,rectangles[i][0]))
    y1 = int(max(0     ,rectangles[i][1]))
    x2 = int(min(width ,rectangles[i][2]))
    y2 = int(min(height,rectangles[i][3]))
    sc = rectangles[i][4]
    if x2>x1 and y2>y1:
        pick.append([x1,y1,x2,y2,sc])
    return NMS(pick,0.5,'iou')
detect_face.py 文件源码 项目:real-time-face-recognition 作者: iwantooxxoox 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
detect_face.py 文件源码 项目:273project 作者: zacharyzhong1116 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
detect_face.py 文件源码 项目:273project 作者: zacharyzhong1116 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
detect_face.py 文件源码 项目:273project 作者: zacharyzhong1116 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def generateBoundingBox(imap, reg, scale, t):
    # use heatmap to generate bounding boxes
    stride=2
    cellsize=12

    imap = np.transpose(imap)
    dx1 = np.transpose(reg[:,:,0])
    dy1 = np.transpose(reg[:,:,1])
    dx2 = np.transpose(reg[:,:,2])
    dy2 = np.transpose(reg[:,:,3])
    y, x = np.where(imap >= t)
    if y.shape[0]==1:
        dx1 = np.flipud(dx1)
        dy1 = np.flipud(dy1)
        dx2 = np.flipud(dx2)
        dy2 = np.flipud(dy2)
    score = imap[(y,x)]
    reg = np.transpose(np.vstack([ dx1[(y,x)], dy1[(y,x)], dx2[(y,x)], dy2[(y,x)] ]))
    if reg.size==0:
        reg = np.empty((0,3))
    bb = np.transpose(np.vstack([y,x]))
    q1 = np.fix((stride*bb+1)/scale)
    q2 = np.fix((stride*bb+cellsize-1+1)/scale)
    boundingbox = np.hstack([q1, q2, np.expand_dims(score,1), reg])
    return boundingbox, reg

# function pick = nms(boxes,threshold,type)
estimation.py 文件源码 项目:psola 作者: jcreinhold 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def pitch_strength_one_candidate(f_erbs, nL, pc):
    """
    Calculates the pitch ``strength'' for a single
    candidate

    Args:
        f_erbs (array):
        nL           : normalized loudness
        pc           : pitch candidate

    Returns:
        s     (float): value of strength for a pitch
    """

    # fix rounds a number *towards* zero
    n = int(np.fix(f_erbs[-1] / pc - 0.75))  # number of harmonics
    if n == 0:
        return np.nan
    k = np.zeros(f_erbs.shape)  # kernel

    # normalize freq w.r.t. candidate
    q = f_erbs / pc

    # create kernel
    primes = np.concatenate((np.ones(1), primes_2_to_n(n)))
    for i in primes:
        a = np.abs(q - i)

        # peak's weight
        p = a < 0.25
        k[p] = np.cos(2 * np.pi * q[p])

        # valley's weight
        v = np.logical_and(0.25 < a, a < 0.75)
        k[v] = k[v] + np.cos(2 * np.pi * q[v]) / 2

    # apply envelope
    k = k * np.sqrt(1 / f_erbs)

    # K+-normalized kernel
    k = k / np.linalg.norm(k[k>0])

    # strength value of pitch
    s = np.dot(k, nL)

    return s
pyPPPETM_new.py 文件源码 项目:Parallel.GAMIT 作者: demiangomez 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, cnn=None, NetworkCode=None, StationCode=None, t=None):

        if t is None:
            ppp_soln = PPP_soln(cnn, NetworkCode, StationCode)
            t = ppp_soln.t

        # wrap around the solutions
        wt = np.sort(np.unique(t - np.fix(t)))

        # analyze the gaps in the data
        dt = np.diff(wt)

        # max dt (internal)
        dtmax = np.max(dt)

        # dt wrapped around
        dt_interyr = 1 - wt[-1] + wt[0]

        if dt_interyr > dtmax:
            dtmax = dt_interyr

        # save the value of the max wrapped delta time
        self.dt_max = dtmax

        # if dtmax < 3 months (90 days = 0.1232), then we can fit the annual
        # if dtmax < 1.5 months (45 days = 0.24657), then we can fit the semi-annual too

        if dtmax <= 0.1232:
            # all components (annual and semi-annual)
            self.A = np.array([sin(2 * pi * t), cos(2 * pi * t), sin(4 * pi * t), cos(4 * pi * t)]).transpose()
            self.frequencies = 2

        elif dtmax <= 0.2465:
            # only annual
            self.A = np.array([sin(2 * pi * t), cos(2 * pi * t)]).transpose()
            self.frequencies = 1

        else:
            # no periodic terms
            self.A = np.array([])
            self.frequencies = 0

        self.terms = self.frequencies * 2

        return
pyPPPETM.py 文件源码 项目:Parallel.GAMIT 作者: demiangomez 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __init__(self, cnn=None, NetworkCode=None, StationCode=None, t=None):

        if t is None:
            ppp_soln = PPP_soln(cnn, NetworkCode, StationCode)
            t = ppp_soln.t

        # wrap around the solutions
        wt = np.sort(np.unique(t - np.fix(t)))

        # analyze the gaps in the data
        dt = np.diff(wt)

        # max dt (internal)
        dtmax = np.max(dt)

        # dt wrapped around
        dt_interyr = 1 - wt[-1] + wt[0]

        if dt_interyr > dtmax:
            dtmax = dt_interyr

        # save the value of the max wrapped delta time
        self.dt_max = dtmax

        # if dtmax < 3 months (90 days = 0.1232), then we can fit the annual
        # if dtmax < 1.5 months (45 days = 0.24657), then we can fit the semi-annual too

        if dtmax <= 0.1232:
            # all components (annual and semi-annual)
            self.A = np.array([sin(2 * pi * t), cos(2 * pi * t), sin(4 * pi * t), cos(4 * pi * t)]).transpose()
            self.frequencies = 2

        elif dtmax <= 0.2465:
            # only annual
            self.A = np.array([sin(2 * pi * t), cos(2 * pi * t)]).transpose()
            self.frequencies = 1

        else:
            # no periodic terms
            self.A = np.array([])
            self.frequencies = 0

        # variables to store the periodic amplitudes
        self.sin = np.array([])
        self.cos = np.array([])

        self.params = self.frequencies * 2


问题


面经


文章

微信
公众号

扫码关注公众号