{"cells":[{"metadata":{"_cell_guid":"cd692b21-fb9d-4418-85d9-1264afb9ecd7","_uuid":"eecfb54d6ab07df8f7f30d32f1f84ff5f0029142"},"cell_type":"markdown","source":"Work through https://keras.io/getting-started/sequential-model-guide/ on freesound data set"},{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\nimport scipy.io.wavfile\nimport keras\nprint(os.listdir(\"../input\"))","execution_count":19,"outputs":[]},{"metadata":{"_cell_guid":"e83d25d4-ceec-4caf-b66f-c5b1f507b4f3","_uuid":"765181bb3212b5f8ca5080942db766adeecffa74","trusted":true},"cell_type":"code","source":"audio_paths = []\nfor line in os.listdir('../input/audio_train'):\n    audio_path = '../input/audio_train/' + line.strip()\n    audio_paths.append(audio_path)\naudio_paths[:10]","execution_count":20,"outputs":[]},{"metadata":{"_cell_guid":"6821526f-c113-42a0-82c8-593ddbc23dae","_uuid":"b1720c58bd4102f3de7f5e36f04c497f3739580e","trusted":true},"cell_type":"code","source":"x_train = np.random.random((1000, 5))\nx_train","execution_count":21,"outputs":[]},{"metadata":{"_cell_guid":"dbcd3e80-daab-4dc7-bf0a-670a98714c6a","_uuid":"d856f5925e3afad5576c929de786be159a7aa558","trusted":true},"cell_type":"code","source":"y_train = keras.utils.to_categorical([0], num_classes=1)\ny_train","execution_count":22,"outputs":[]},{"metadata":{"_cell_guid":"8dbc072d-abaa-4454-881f-e8e03d2085e1","_uuid":"f3237e6c960dab8630dc2040f09d0e6828747b2f","trusted":true},"cell_type":"code","source":"fs, data = scipy.io.wavfile.read('../input/audio_train/513f4971.wav')\ndata","execution_count":24,"outputs":[]},{"metadata":{"_cell_guid":"db6b4aa6-e4f8-423b-978f-e583e0e2fd09","_uuid":"ed8bc0831286550b7c072b779b3f7fb790a34ff1","trusted":true},"cell_type":"code","source":"data.shape","execution_count":25,"outputs":[]},{"metadata":{"_cell_guid":"2a71e1a8-0965-486b-abf5-29de1185e052","_uuid":"4e8fd045f7db6ac8374fab1510ef13f4226ae363","trusted":true},"cell_type":"code","source":"x_train = [data]\nx_train","execution_count":26,"outputs":[]},{"metadata":{"_cell_guid":"3df94222-9b76-487e-80be-95b98bfa6093","_uuid":"99d1f4d8e8380e96221512f25325337e3da2a989","trusted":true},"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import Dense, Dropout, Activation\nfrom keras.optimizers import SGD\n\nmodel = Sequential()\n# Dense(64) is a fully-connected layer with 64 hidden units.\n# in the first layer, you must specify the expected input data shape:\n# here, 20-dimensional vectors.\nmodel.add(Dense(64, activation='relu', input_shape=data.shape[1:]))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(64, activation='relu'))\nmodel.add(Dropout(0.5))\nmodel.add(Dense(1, activation='softmax'))\n\nsgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)\nmodel.compile(loss='categorical_crossentropy',\n              optimizer=sgd,\n              metrics=['accuracy'])\n\nmodel.fit(x_train, y_train, epochs=20)","execution_count":27,"outputs":[]},{"metadata":{"_cell_guid":"0c810f89-fb14-480a-a8f5-be3b992a7d07","_uuid":"86cd0d7f52e5200791e56d084dd6add9b8069310","trusted":true},"cell_type":"code","source":"score = model.evaluate(x_test, y_test, batch_size=128)\n","execution_count":28,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":1}