Beispiel #1
0
def GetAllData(fe_fd, csv_file, agg_num, hop):
    """
    Input: Features folder(String), CSV file(String), agg_num(Integer), hop(Integer).
    Output: Loaded features(Numpy Array) and labels(Numpy Array).
    Loads all the features saved as pickle files.
    """
    # read csv
    with open( csv_file, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)
    
    # init list
    X3d_all = []
    y_all = []
    i=0
    for li in lis:
        # load data
        [na, lb] = li[0].split('\t')
        na = na.split('/')[1][0:-4]
        path = fe_fd + '/' + na + '.f'
        X = aud_feature.load(path)
        # reshape data to (n_block, n_time, n_freq)
        i+=1
        X3d = aud_utils.mat_2d_to_3d( X, agg_num, hop )
        X3d_all.append( X3d )
        y_all += [ lb_to_id[lb] ] * len( X3d )
    
    print "Features loaded",i                
    print 'All files loaded successfully'
    # concatenate list to array
    X3d_all = np.concatenate( X3d_all )
    y_all = np.array( y_all )
    
    return X3d_all, y_all
Beispiel #2
0
    def get_train_data(self):
        """
        Loads all the features saved as pickle files.
        Input: Features folder(str), CSV file(str)
        Output: Loaded features(np array) and labels(np array).
        """
        feature = self.feature
        fe_fd = cfg.dev_fd + '/' + feature
        csv_file = cfg.meta_train_csv
        agg_num = self.agg_num
        hop = self.hop
        # read csv
        with open(csv_file, 'rb') as f:
            reader = csv.reader(f)
            lis = list(reader)

        # init list
        X3d_all = []
        y_all = []
        i = 0
        for li in lis:
            # load data
            na = li[1]
            path = fe_fd + '/' + na + '.f'
            info_path = cfg.label_csv + '/' + na + '.csv'
            with open(info_path, 'rb') as g:
                reader2 = csv.reader(g)
                lis2 = list(reader2)
            tags = lis2[-2][1]

            y = np.zeros(len(cfg.labels))
            for ch in tags:
                y[cfg.lb_to_id[ch]] = 1
            X = aud_feature.load(path)
            # reshape data to (n_block, n_time, n_freq)
            i += 1
            X3d = aud_utils.mat_2d_to_3d(X, agg_num, hop)
            X3d_all.append(X3d)
            y_all += [y] * len(X3d)

        print "Features loaded", i
        print 'All files loaded successfully'
        # concatenate list to array
        X3d_all = np.concatenate(X3d_all)
        y_all = np.array(y_all)

        return X3d_all, y_all
Beispiel #3
0
def GetAllData(fe_fd, csv_file, agg_num, hop):
    """
    Input: Features folder(String), CSV file(String), agg_num(Integer), hop(Integer).
    Output: Loaded features(Numpy Array) and labels(Numpy Array).
    Loads all the features saved as pickle files.
    """
    # read csv
    with open(csv_file, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)

    # init list
    X3d_all = []
    y_all = []
    i = 0
    for li in lis:
        # load data
        na = li[1]
        path = fe_fd + '/' + na + '.f'
        info_path = label_csv + '/' + na + '.csv'
        with open(info_path, 'rb') as g:
            reader2 = csv.reader(g)
            lis2 = list(reader2)
        tags = lis2[-2][1]

        y = np.zeros(len(labels))
        for ch in tags:
            y[lb_to_id[ch]] = 1
        X = aud_feature.load(path)
        # reshape data to (n_block, n_time, n_freq)
        i += 1
        X3d = aud_utils.mat_2d_to_3d(X, agg_num, hop)
        X3d_all.append(X3d)
        y_all += [y] * len(X3d)

    print "Features loaded", i
    print 'All files loaded successfully'
    # concatenate list to array
    X3d_all = np.concatenate(X3d_all)
    y_all = np.array(y_all)

    return X3d_all, y_all
Beispiel #4
0
    def get_train_data(self):
        """
        Loads all the features saved as pickle files.
        Input: Features folder(str), CSV file(str)
        Output: Loaded features(np array) and labels(np array).
        """
        feature = self.feature
        fe_fd = cfg.dev_fd + '/' + feature
        csv_file = cfg.label_csv
        agg_num = self.agg_num
        hop = self.hop
        # read csv
        with open(csv_file, 'rb') as f:
            reader = csv.reader(f)
            lis = list(reader)

        # init list
        X3d_all = []
        y_all = []
        i = 0
        for li in lis:
            # load data
            [na, lb] = li[0].split('\t')
            na = na.split('/')[1][0:-4]
            path = fe_fd + '/' + na + '.f'
            X = aud_feature.load(path)
            # reshape data to (n_block, n_time, n_freq)
            i += 1
            X3d = aud_utils.mat_2d_to_3d(X, agg_num, hop)
            X3d_all.append(X3d)
            y_all += [cfg.lb_to_id[lb]] * len(X3d)

        print "Features loaded", i
        print 'All files loaded successfully'
        # concatenate list to array
        X3d_all = np.concatenate(X3d_all)
        y_all = np.array(y_all)

        return X3d_all, y_all