<jupyter_start><jupyter_text>Interface 2018/12 Snack sound classificationClassification task of 6 snack bag shaking sounds.https://shop.cqpub.co.jp/hanbai/books/MIF/MIF201812.htmlThis notebook download, convert and preprocess dataset.<jupyter_code>import sys
sys.path.append('../..')
from lib_train import *
%matplotlib inline

DATAROOT = Path('Snack/data')<jupyter_output>{'sampling_rate': 44100, 'duration': 2, 'hop_length': 694, 'fmin': 20, 'fmax': 22050, 'n_mels': 128, 'n_fft': 2560, 'model': 'mobilenetv2', 'labels': ['babystar', 'bbq', 'corn', 'kappaebi', 'potechi', 'vegetable'], 'folder': PosixPath('.'), 'n_fold': 1, 'valid_limit': None, 'random_state': 42, 'test_size': 0.2, 'samples_per_file': 1, 'batch_size': 32, 'learning_rate': 0.0001, 'metric_save_ckpt': 'val_acc', 'epochs': 100, 'verbose': 2, 'best_weight_file': 'best_model_weight.h5', 'rt_process_count': 1, 'rt_oversamples': 10, 'pred_ensembles': 10, 'runtime_model_file': None, 'label2int': {'babystar': 0, 'bbq': 1, 'corn': 2, 'kappaebi': 3, 'potechi': 4, 'vegetable': 5}, 'num_classes': 6, 'samples': 88200, 'rt_chunk_samples': 4410, 'mels_onestep_samples': 4410, 'mels_convert_samples': 92610, 'dims': [128, 128, 1], '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',[...]<jupyter_text>Prepare dataset<jupyter_code>! wget http://www.cqpub.co.jp/interface/download/2018/12/Snack-data.zip
! unzip -q Snack-data.zip
! rm Snack-data.zip
! echo Listing sub folders:
! ls Snack/data
! echo Listing some of files:
! ls Snack/data/jack | head
files = list(DATAROOT.glob('*/*[0-9].wav'))
X_files = [str(f) for f in files]
y_labels = [str(f.name).split('_')[0] for f in files]
print('Classes', sorted(list(set(y_labels))))
y = [conf.label2int[y] for y in y_labels]
# Train
train_files = sorted([f for f in files if f.stem[-6] in '1'])
y_labels = [str(f.name).split('_')[0] for f in train_files]
y_train = [conf.label2int[y] for y in y_labels]
XX = mels_build_multiplexed_X(conf, train_files)
X_train, y_train = mels_demux_XX_y(XX, y_train)
np.save('X_train.npy', X_train)
np.save('y_train.npy', y_train)
X_train.shape, y_train.shape
# Valid
valid_files = sorted([f for f in files if f.stem[-6] in '2'])
y_labels = [str(f.name).split('_')[0] for f in valid_files]
y_valid = [conf.label2int[y] for y in y_labels]

XX = mels_build_multiplexed_X(conf, valid_files)
X_valid, y_valid = mels_demux_XX_y(XX, y_valid)
np.save('X_valid.npy', X_valid)
np.save('y_valid.npy', y_valid)
X_valid.shape, y_valid.shape
# Valid - list of mic for each samples
mic_valid = [str(f.parent.name) for f in valid_files]
np.save('mic_valid.npy', mic_valid)
mic_valid[:5]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18267148014440432, 'fraction_numerical': 0.04043321299638989, 'mean_word_length': 6.489189189189189, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '245705', 'license': 'MIT', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1129, 'n_words': 254, 'path': 'apps/IF201812/IF201812-Preprocess.ipynb', 'repo_name': 'sgarbirodrigo/ml-sound-classifier', 'size': '2770'}