Ejemplo n.º 1
0
def prepare_gt_as_class(gt_locs):
    assert len(gt_locs) <= 1
    if len(gt_locs) == 1:
        azi, ele = apkit.vec2ae(gt_locs[0])
        return int((azi + np.pi) // (2 * np.pi / _N_CLASSES))
    else:
        return 0  # assume one and only one source
Ejemplo n.º 2
0
def load_gt_cont(path):
    with open(path) as s:
        gt = pickle.load(s)

    ae = np.array([apkit.vec2ae(p) for p, _, _, _, _, _, in gt[4]])
    assert len(ae) == 1
    return ae[0, 0]
Ejemplo n.º 3
0
def prepare_gt_as_heatmap(gt_locs):
    hmap = np.zeros(_N_CLASSES)
    aindex = np.arange(_N_CLASSES, dtype='float32') \
                                        * 2 * np.pi / _N_CLASSES
    for l in gt_locs:
        azi, ele = apkit.vec2ae(l)
        d = np.remainder(aindex - azi, 2 * np.pi)
        d[d > np.pi] -= 2 * np.pi
        h = np.exp(-d**2 / _SIGMA**2)
        hmap = np.maximum(hmap, h)
    return hmap.astype('float32', copy=False)
Ejemplo n.º 4
0
def prepare_gt_as_ordered_posterior(gt_locs):
    assert len(gt_locs) <= 2
    labels = []
    for l in gt_locs:
        azi, ele = apkit.vec2ae(l)
        labels.append(
            int(azi / (2 * np.pi / _OPOST_N_DIR) + 0.5) % _OPOST_N_DIR)
    for _ in xrange(2 - len(labels)):
        labels.append(_OPOST_N_DIR)
    labels = sorted(labels)
    post = np.zeros(2 * (_OPOST_N_DIR + 1))
    post[labels[0]] = 1.0
    post[labels[1] + _OPOST_N_DIR + 1] = 1.0
    return post.astype('float32', copy=False)
Ejemplo n.º 5
0
def prepare_gtf_location_and_snsc(gt):
    res = np.zeros((2, _N_CLASSES), dtype='float32')

    if len(gt) > 0:
        ctb = np.zeros((len(gt), _N_CLASSES))
        for i, (l, _, _) in enumerate(gt):
            azi, ele = apkit.vec2ae(l)
            d = np.remainder(_AZI_DIRECTIONS - azi, 2 * np.pi)
            d[d > np.pi] -= 2 * np.pi
            ctb[i] = np.exp(-d**2 / _SIGMA**2)
        stype = np.array([t for _, t, _ in gt], dtype='float32')

        # localization map (likelihood)
        res[0] = np.max(ctb, axis=0)

        # speech/non-speech map
        res[1] = stype[np.argmax(ctb, axis=0)]

    return res
Ejemplo n.º 6
0
def _gt_azimuth_distance(src_doa, ref_doas):
    azi, ele = apkit.vec2ae(src_doa)
    d = np.remainder(ref_doas - azi, 2 * np.pi)
    d[d > np.pi] -= 2 * np.pi
    return d
Ejemplo n.º 7
0
def prepare_gt_as_posterior(gt_locs):
    post = np.zeros(_N_CLASSES)
    for l in gt_locs:
        azi, ele = apkit.vec2ae(l)
        post[int(azi / (2 * np.pi / _N_CLASSES) + 0.5) % _N_CLASSES] = 1.0
    return post.astype('float32', copy=False)