def __init__(self, path_list, params):

        self.path_list = path_list
        self.params = params

        # culculate the number of dimentions
        dims = params["feature"]["n_mels"] * params["feature"]["n_frames"]

        # iterate to file_to_vector_array()
        for idx in tqdm(range(len(path_list))):
            vectors = com.file_to_vectors(
                path_list[idx],
                n_mels=params["feature"]["n_mels"],
                n_frames=params["feature"]["n_frames"],
                n_fft=params["feature"]["n_fft"],
                hop_length=params["feature"]["hop_length"],
                power=params["feature"]["power"])
            vectors = vectors[::params["feature"]["n_hop_frames"], :]
            if idx == 0:
                data = np.zeros((len(path_list) * vectors.shape[0], dims),
                                np.float32)
            data[vectors.shape[0] * idx:vectors.shape[0] *
                 (idx + 1), :] = vectors

        self.feat_data = data
Exemplo n.º 2
0
def file_list_to_data(file_list,
                      msg="calc...",
                      n_mels=64,
                      n_frames=5,
                      n_hop_frames=1,
                      n_fft=1024,
                      hop_length=512,
                      power=2.0):
    """
    convert the file_list to a vector array.
    file_to_vector_array() is iterated, and the output vector array is concatenated.

    file_list : list [ str ]
        .wav filename list of dataset
    msg : str ( default = "calc..." )
        description for tqdm.
        this parameter will be input into "desc" param at tqdm.

    return : numpy.array( numpy.array( float ) )
        data for training (this function is not used for test.)
        * dataset.shape = (number of feature vectors, dimensions of feature vectors)
    """
    # calculate the number of dimensions
    dims = n_mels * n_frames

    # iterate file_to_vector_array()
    for idx in tqdm(range(len(file_list)), desc=msg):
        vectors = com.file_to_vectors(file_list[idx],
                                                n_mels=n_mels,
                                                n_frames=n_frames,
                                                n_fft=n_fft,
                                                hop_length=hop_length,
                                                power=power)
        vectors = vectors[: : n_hop_frames, :]
        if idx == 0:
            data = np.zeros((len(file_list) * vectors.shape[0], dims), float)
        data[vectors.shape[0] * idx : vectors.shape[0] * (idx + 1), :] = vectors

    return data
Exemplo n.º 3
0
                    result=param["result_directory"],
                    machine_type=machine_type,
                    section_name=section_name,
                    dir_name=dir_name)
                decision_result_list = []

                print(
                    "\n============== BEGIN TEST FOR A SECTION ==============")
                y_pred = [0. for k in files]
                for file_idx, file_path in tqdm(enumerate(files),
                                                total=len(files)):
                    try:
                        data = com.file_to_vectors(
                            file_path,
                            n_mels=param["feature"]["n_mels"],
                            n_frames=param["feature"]["n_frames"],
                            n_fft=param["feature"]["n_fft"],
                            hop_length=param["feature"]["hop_length"],
                            power=param["feature"]["power"])
                    except:
                        com.logger.error("File broken!!: {}".format(file_path))

                    y_pred[file_idx] = np.mean(
                        np.square(data - model.predict(data)))

                    # store anomaly scores
                    anomaly_score_list.append(
                        [os.path.basename(file_path), y_pred[file_idx]])

                    # store decision results
                    if y_pred[file_idx] > decision_threshold: