1 year ago

#295576

test-img

Ran

ValueError: could not convert string to float: -- problem with lables

I'm getting the following error when trying to extract festues, I have to do the split before the feature extraction. The y contains the labels so not sure why I'm getting the error. data is wav files and the labels are text originally

     for cls in os.listdir(path):
        for sound in tqdm(os.listdir(os.path.join(path, cls))):
         wav  = librosa.load(os.path.join(os.path.join(path, cls, sound)), sr=16000)[0].astype(np.float32)
         tmp_samples.append(wav[0])
         tmp_labels.append(cls)
         
    tmp_labels=np.array(tmp_labels)    
   
    X_train, y_train , X_test ,  y_test  = train_test_split( tmp_samples, tmp_labels , test_size=0.60,shuffle=True) 
   
    
    encoder = LabelBinarizer()
    y_test = encoder.fit_transform(y_test) 
    
    minmax_scaler = MinMaxScaler()
    X_train = np.asarray( X_train ).reshape(-1,1)
    X_train = minmax_scaler.fit_transform( X_train )

    X_test = np.asarray( X_test ).reshape(-1,1)
    X_test = minmax_scaler.fit_transform( X_test )

   
    y_test = encoder.fit_transform(y_test)
    for x,y in zip(X_test,y_test):
       
        extract_features(x[0], y, model, plain_samples , plain_labels )





def extract_features(wav, cls, model, plain_samples, plain_labels):

    for feature in model(wav)[1]:
        plain_samples.append(feature)
        plain_labels.append(cls)
        

Error:

Traceback (most recent call last):
  File "optunaCopy.py", line 523, in <module>
    main(sys.argv[1:])
  File "optunaCopy.py", line 439, in main
    X_train, y_train , X_test ,  y_test,X_valid,y_valid  = create_dataset(path)
  File "optunaCopy.py", line 129, in create_dataset
    X_test = minmax_scaler.fit_transform( X_test )
  File "C:\Users\x\anaconda3\envs\yamnet\lib\site-packages\sklearn\base.py", line 844, in fit_transform
    return self.fit(X, **fit_params).transform(X)
  File "C:\Users\x\anaconda3\envs\yamnet\lib\site-packages\sklearn\preprocessing\_data.py", line 416, in fit
    return self.partial_fit(X, y)
  File "C:\Users\x\anaconda3\envs\yamnet\lib\site-packages\sklearn\preprocessing\_data.py", line 458, in partial_fit
    force_all_finite="allow-nan",
  File "C:\Users\x\anaconda3\envs\yamnet\lib\site-packages\sklearn\base.py", line 557, in _validate_data
    X = check_array(X, **check_params)
  File "C:\Users\x\anaconda3\envs\yamnet\lib\site-packages\sklearn\utils\validation.py", line 738, in check_array
    array = np.asarray(array, order=order, dtype=dtype)
  File "C:\Users\x\anaconda3\envs\yamnet\lib\site-packages\numpy\core\_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: 'hh'

python

machine-learning

encoder

train-test-split

0 Answers

Your Answer

Accepted video resources