-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5d1285
commit 676d911
Showing
4 changed files
with
1,219 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
training/.ipynb_checkpoints/WaveNet-classifier-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"!{sys.executable} -m pip install librosa\n", | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"import os\n", | ||
"import librosa\n", | ||
"import librosa.display\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"from sklearn.preprocessing import LabelEncoder\n", | ||
"from keras.utils import to_categorical\n", | ||
"import h5py\n", | ||
"import math\n", | ||
"import pickle" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import pandas as pd\n", | ||
"import sys\n", | ||
"import tensorflow as tf\n", | ||
"from urllib.request import urlopen\n", | ||
"from keras.layers import Input, Dense, Lambda, Flatten, Reshape, Activation, Dropout, Add, TimeDistributed, Multiply, Conv1D, Conv2D, MaxPooling1D, AveragePooling1D\n", | ||
"from keras.models import Model, Sequential, load_model\n", | ||
"from keras import backend as K\n", | ||
"from keras import metrics\n", | ||
"from keras import optimizers\n", | ||
"from keras.callbacks import History, ModelCheckpoint" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"all_X = []\n", | ||
"all_Y = []\n", | ||
"fulldatasetpath = 'http://76.213.149.126:8080/audio/'\n", | ||
"metadata = pd.read_csv('http://76.213.149.126:8080/metadata/UrbanSound8K.csv')\n", | ||
"print(metadata)\n", | ||
"for index, row in metadata.iterrows():\n", | ||
" \n", | ||
" file_name = (fulldatasetpath) + 'fold'+str(row[\"fold\"])+'/' + str(row[\"slice_file_name\"])\n", | ||
" all_X.append(file_name.replace(\".wav\", \"_x.pkl\"))\n", | ||
" all_Y.append(file_name.replace(\".wav\", \"_y.pkl\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from sklearn.model_selection import train_test_split \n", | ||
"x_train, x_test, y_train, y_test = train_test_split(all_X, all_Y, test_size=0.2, random_state = 42)\n", | ||
"\n", | ||
"shapes = (tf.TensorShape([88200,1]), tf.TensorShape([10,1]))\n", | ||
"train_iter = zip(x_train, y_train)\n", | ||
"def gen_train():\n", | ||
" sample = next(train_iter)\n", | ||
" print (sample)\n", | ||
" return (list(np.array(pickle.load(urlopen(sample[0]))).reshape((1,88200))), np.array(pickle.load(urlopen(sample[1]))).reshape((1,10)))\n", | ||
"\n", | ||
"test_iter = zip(x_test, y_test)\n", | ||
"def gen_test():\n", | ||
" sample = next(test_iter)\n", | ||
" return (pickle.load(urlopen(sample[0])), pickle.load(urlopen(sample[1])))\n", | ||
"\n", | ||
"train_dataset = tf.data.Dataset.from_generator(generator=gen_train,output_types=(tf.float32,tf.float32),output_shapes=shapes)\n", | ||
"test_dataset = tf.data.Dataset.from_generator(generator=gen_test,output_types=(tf.float32,tf.float32),output_shapes=shapes)\n", | ||
"print(gen_train())" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.