运行FSDKaggle2018音频模型训练脚本时出现此错误。
我在网上寻找了类似的问题,但是找不到类似的情况。
它是指其他脚本“ lib_train.py”中的一行,
sampler_instance = sampler_class(ratio = flat_ratio, random_state = random_state)
但是不确定我应该对这里的“比率”做些什么!
请问如何解决此问题?
import sys
sys.path.append('../..')
from lib_train import *
conf.model = 'alexnet'
conf.logdir = 'logs_alexbased'
conf.best_weight_file = 'best_alexbased_weight.h5'
# 1. Load Meta data
DATAROOT = Path.home() / '/dir/to/audio/folder'
#Data frame for training dataset
df_train = pd.read_csv(DATAROOT / '/dir/to/csv')
#Plain y_train label
plain_y_train = np.array([conf.label2int[l] for l in df_train.label])
# 2. Preprocess data if it's not ready
def fsdkaggle2018_map_y_train(idx_train, plain_y_train):
return np.array([plain_y_train[i] for i in idx_train])
def fsdkaggle2018_make_preprocessed_train_data():
conf.folder.mkdir(parents=True, exist_ok=True)
if not os.path.exists(conf.X_train):
XX = mels_build_multiplexed_X(conf, [DATAROOT/'/dir/to/audio/folder'/fname for fname in df_train.fname])
X_train, y_train, X_test, y_test = \
train_valid_split_multiplexed(conf, XX, plain_y_train, demux=True)
np.save(conf.X_train, X_train)
np.save(conf.y_train, y_train)
np.save(conf.X_test, X_test)
np.save(conf.y_test, y_test)
fsdkaggle2018_make_preprocessed_train_data()
# 3. Load all dataset & normalize
X_train, y_train = load_audio_datafiles(conf, conf.X_train, conf.y_train, normalize=True)
X_test, y_test = load_audio_datafiles(conf, conf.X_test, conf.y_test, normalize=True)
print('Loaded train:test = {}:{} samples.'.format(len(X_train), len(X_test)))
# 4. Train folds
history, model = train_classifier(conf, fold=0,
dataset=[X_train, y_train, X_test, y_test],
model=None,
init_weights=None, # from scratch
#init_weights='../../model/mobilenetv2_fsd2018_41cls.h5'
)
# 5. Evaluate
evaluate_model(conf, model, X_test, y_test)
print('___ training finished ___')
错误日志:
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
Type "copyright", "credits" or "license" for more information.
IPython 7.13.0 -- An enhanced Interactive Python.
runfile('/home/aaa/Desktop/Project/apps/fsdkaggle2018/train_alexbased.py', wdir='/home/aaa/Desktop/Project/apps/fsdkaggle2018')
{'sampling_rate': 44100, 'duration': 1, 'hop_length': 347, 'fmin': 20, 'fmax': 22050, 'n_mels': 128, 'n_fft': 2560, 'model': 'mobilenetv2', 'labels': ['Unknown-Noise', 'IC6-UAV-Detected'], 'folder': PosixPath('.'), 'n_fold': 1, 'normalize': 'samplewise', 'valid_limit': None, 'random_state': 42, 'test_size': 0.01, 'samples_per_file': 5, 'batch_size': 32, 'learning_rate': 0.0001, 'epochs': 500, 'verbose': 2, 'best_weight_file': 'best_mobilenetv2_weight.h5', 'rt_process_count': 1, 'rt_oversamples': 10, 'pred_ensembles': 10, 'runtime_model_file': 'model/mobilenetv2_fsd2018_41cls.pb', 'label2int': {'Unknown-Noise': 0, 'IC6-UAV-Detected': 1}, 'num_classes': 2, 'samples': 44100, 'rt_chunk_samples': 4410, 'mels_onestep_samples': 4410, 'mels_convert_samples': 48510, 'dims': [128, 128, 1], 'metric_save_ckpt': 'val_loss', 'metric_save_mode': 'auto', 'logdir': 'logs', 'data_balancing': 'over_sampling', 'X_train': 'X_train.npy', 'y_train': 'y_train.npy', 'X_test': 'X_test.npy', 'y_test': 'y_test.npy', 'steps_per_epoch_limit': None, 'aug_mixup_alpha': 1.0, 'eval_ensemble': True, 'what_is_sample': 'log mel-spectrogram', 'use_audio_training_model': True}
Using TensorFlow backend.
normalize samplewise
normalize samplewise
Loaded train:test = 765:10 samples.
<Before> Current category distribution = {'Unknown-Noise': 520, 'IC6-UAV-Detected': 245}
Traceback (most recent call last):
File "/home/aaa/Desktop/Project/apps/fsdkaggle2018/train_alexbased.py", line 43, in <module>
init_weights=None, # from scratch
File "/home/aaa/Desktop/Project/apps/fsdkaggle2018/lib_train.py", line 328, in train_classifier
Xtrain, ytrain = balance_dataset(conf, Xtrain, ytrain)
File "/home/aaa/Desktop/Project/apps/fsdkaggle2018/lib_train.py", line 238, in balance_dataset
X, y = balance_class_by_over_sampling(X, y) if conf.data_balancing == 'over_sampling' \
File "/home/aaa/Desktop/Project/apps/fsdkaggle2018/lib_train.py", line 175, in balance_class_by_over_sampling
return _balance_class(X, y, 'max', RandomOverSampler, random_state)
File "/home/aaa/Desktop/Project/apps/fsdkaggle2018/lib_train.py", line 168, in _balance_class
sampler_instance = sampler_class(ratio=flat_ratio, random_state=random_state)
File "/usr/local/lib/python3.6/dist-packages/imblearn/utils/_validation.py", line 640, in inner_f
return f(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'ratio'