01-byoc/code/dataset.py [31:67]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def __init__(self, params):
        """Init SoundDataset with params
        Args:
            params (class): all arguments parsed from argparse
            train (bool): train or val dataset
        """
        self.params = params
        self.csvfile = params.csv_path
        self.data_dir = params.data_dir
        self.normalize = self.params.normalize
        self.preload = self.params.preload

        self.X, self.Y, self.filenames = self.read_data(self.csvfile)
        if self.preload:
            self.X = self.convert_to_spec(self.X)
            self.shape = self.get_shape(self.X[0])
        else:
            self.shape = self.get_shape(self.preprocessing(self.X[0][0], self.X[0][1]))

    def read_data(self, csvfile):
        """Read wav file from csv
        Args:
            csvfile: A string specifying the path of csvfile
        Return:
            data: A list of tuple (wav data in np.int16 data type, sampling rate of wav file)
            label: A list of labels corresponding to the wav data
            filenames: A list of filenames of the wav file
        """
        df = pd.read_csv(csvfile)
        data, label, filenames = [], [], []
        print("reading wav files...")
        for i in tqdm(range(len(df))):
            row = df.iloc[i]
            path = os.path.join(self.data_dir, row.Filename + ".wav")
            wav_data, sr = wav_read(path)
            assert wav_data.dtype == np.int16
            data.append((wav_data, sr))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



01-byoc/code/dataset.py [158:181]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def __init__(self, params):
        self.params = params
        self.csvfile = params.csv_path
        self.data_dir = params.data_dir
        self.normalize = self.params.normalize
        self.preload = self.params.preload

        self.X, self.Y, self.filenames = self.read_data(self.csvfile)
        if self.preload:
            self.X = self.convert_to_spec(self.X)
            self.shape = self.get_shape(self.X[0])
        else:
            self.shape = self.get_shape(self.preprocessing(self.X[0][0], self.X[0][1]))

    def read_data(self, csvfile):
        df = pd.read_csv(csvfile)
        data, label, filenames = [], [], []
        print("reading wav files...")
        for i in tqdm(range(len(df))):
            row = df.iloc[i]
            path = os.path.join(self.data_dir, row.Filename + ".wav")
            wav_data, sr = wav_read(path)
            assert wav_data.dtype == np.int16
            data.append((wav_data, sr))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



