pandas:AttributeError:'dict'对象没有属性'transform'

时间:2018-04-23 19:26:45

标签: python python-3.x pandas

我对python和pandas很新,而且我遇到了错误。我正在使用audiofiles,我需要从audiostream中提取一些功能。

def load_features(self, audio_file):
    def stereo_to_mono(x):
        # stereo to mono
        if len(x.shape) > 1 and x.shape[1] > 1:
            print('Converting stereo to mono')
            x = x.mean(axis=1)
        return x

    def cut_or_pad_to_length(x, duration, fs):
        desired_length = int(round(duration * fs))
        length = len(x)
        diff = length - desired_length
        abs_diff = abs(diff)
        if diff < 0:
            print('Padding')
            # put the short signal in the middle
            pad_before = abs_diff // 2
            pad_after = abs_diff - pad_before
            x = np.lib.pad(x, (pad_before, pad_after), 'constant')
        elif diff > 1:
            print('Cutting')
            # cut the beginning
            x = x[0:desired_length]
        return x

    def adjust_input(x, fs):
        x = stereo_to_mono(x)
        x = cut_or_pad_to_length(x, 2.0, fs)
        return x

    #x is data, fs is samplerate
    x, fs = sf.read(audio_file)
    x0 = adjust_input(x, fs)

    # pitchgram
    x_features = self.ch.transform(x0)

    if self.scaler is not None:
        x_features = self.scaler.transform(x_features.reshape(1, -1)) \

    # 1 data point with 2D features
    x_features = x_features.reshape(1, *x_features.shape)

    return x_features

    def predict_class_label(self, audio_file):
    x_features = self.load_features(audio_file)
    instrument_class = np_utils.probas_to_classes(self.model.predict(x_features, verbose=0))[0]
    label = self.instr_family_le.inverse_transform(instrument_class)
    return label

这给了我以下错误:

     File "C:/dipl0m/ml-master/instrument-classification/predict.py", line 104, in predict_probabilities
x_features = self.load_features(audio_file)
     File "C:/dipl0m/ml-master/instrument-classification/predict.py", line 87, in load_features
x_features = self.ch.transform(x0)
     AttributeError: 'dict' object has no attribute 'transform'

但是xx0似乎不像字典,因为我像他们一样操作列表,但转换给了我那个错误......或者我错了?无法弄清楚很久。

0 个答案:

没有答案