示例#1
0
def run(args):
    if not os.path.exists(args.cache_dir):
        os.makedirs(args.cache_dir)

    ark_reader = ArchiveReader(args.srp_ark)
    for key, mat in ark_reader:
        dst = os.path.join(args.cache_dir, key.replace(".", "-"))
        save_figure(key,
                    mat,
                    dst,
                    hop=args.frame_hop * 1e-3,
                    samp_tdoa=args.tdoa)
示例#2
0
def run(args):
    src_reader = ScriptReader(
        args.src_dec) if args.src == "scp" else ArchiveReader(args.src_dec)
    num_done = 0
    WriterImpl = {"npy": NumpyWriter, "mat": MatWriter}[args.dst]
    with WriterImpl(args.dst_dir, args.scp) as writer:
        for key, mat in src_reader:
            if args.trans:
                mat = np.transpose(mat)
            writer.write(key, mat)
            num_done += 1
    logger.info(f"Copy {num_done} into directory {args.dst_dir}")
示例#3
0
def run(args):
    if not os.path.exists(args.cache_dir):
        os.makedirs(args.cache_dir)

    ark_reader = ArchiveReader(args.srp_ark)
    for key, mat in ark_reader:
        dst = os.path.join(args.cache_dir, key.replace('.', '-'))
        save_figure(key,
                    mat,
                    dst,
                    shift=args.frame_shift * 1e-3,
                    samp_tdoa=args.samp_tdoa)
示例#4
0
def run(args):
    src_format = args.input == "matrix"
    src_reader = ScriptReader(
        args.src_dec,
        matrix=src_format) if args.src == "scp" else ArchiveReader(
            args.src_dec, matrix=src_format)
    num_done = 0
    WriterImpl = {"npy": NumpyWriter, "mat": MatWriter}[args.dst]
    with WriterImpl(args.dst_dir, args.scp) as writer:
        for key, mat in src_reader:
            if args.trans:
                mat = np.transpose(mat)
            writer.write(key, mat)
            num_done += 1
    logger.info("Copy {0} {1} into directory {2}".format(
        num_done, "matrices" if src_format else "vectors", args.dst_dir))
示例#5
0
def run(args):
    pca = PCA(n_components=args.dim)

    is_dir = os.path.isdir(args.rspec_or_dir)
    samples = []
    feats_reader = ArchiveReader(args.rspec_or_dir, matrix=(
        args.matrix)) if not is_dir else NumpyReader(args.rspec_or_dir)
    for _, feats in feats_reader:
        if feats.ndim != 1:
            feats = np.average(feats, 0)
        samples.append(feats)
    org_mat = np.stack(samples)
    pca_mat = pca.fit_transform(org_mat)

    fig = plt.figure()
    ax = fig.add_subplot(111, projection="3d")
    ax.scatter(pca_mat[:, 0], pca_mat[:, 1], pca_mat[:, 2])
    plt.show()
示例#6
0
def run(args):
    if not os.path.exists(args.cache_dir):
        os.makedirs(args.cache_dir)
    is_dir = os.path.isdir(args.rspec_or_dir)
    # ndarrays or archives
    mat_reader = ArchiveReader(
        args.rspec_or_dir) if not is_dir else NumpyReader(args.rspec_or_dir)
    for key, mat in mat_reader:
        if args.apply_log:
            mat = np.log10(mat)
        if args.transpose:
            mat = np.transpose(mat)
        save_figure(
            key,
            mat,
            os.path.join(args.cache_dir, key.replace('.', '-')),
            binary=args.binary,
            shift=args.frame_shift * 1e-3,
            frequency=16000)
示例#7
0
def run(args):
    if not os.path.exists(args.cache_dir):
        os.makedirs(args.cache_dir)
    is_dir = os.path.isdir(args.rspec_or_dir)
    # ndarrays or archives
    mat_reader = ArchiveReader(
        args.rspec_or_dir) if not is_dir else NumpyReader(args.rspec_or_dir)
    for key, mat in mat_reader:
        if args.apply_log:
            mat = np.log10(mat)
        if args.trans:
            mat = np.transpose(mat)
        if args.norm:
            mat = mat / np.max(np.abs(mat))
        save_figure(key,
                    mat,
                    os.path.join(args.cache_dir, key.replace('.', '-')),
                    cmap=args.cmap,
                    hop=args.frame_hop * 1e-3,
                    sr=args.sr,
                    size=args.size)