{"nbformat": 4, "cells": [{"cell_type": "code", "outputs": [], "source": ["# This Python 3 environment comes with many helpful analytics libraries installed\n", "# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n", "# For example, here's several helpful packages to load in \n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "# Input data files are available in the \"../input/\" directory.\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n", "\n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n", "\n", "# Any results you write to the current directory are saved as output."], "metadata": {"_cell_guid": "53cb44d7-8ba1-4043-a2e6-9840ad6c1ba6", "_uuid": "957e632c99fdb4f920551e051490e5d68d75391b"}, "execution_count": 1}, {"cell_type": "code", "outputs": [], "source": ["ss = pd.read_csv('../input/sample_submission.csv')\n", "ss.head()"], "metadata": {"_cell_guid": "aca51784-92cb-4ee7-aa4e-60770f8e34ae", "_uuid": "ec5ca9870ac2d53977b7e2b7199875dd7053a1b4"}, "execution_count": 2}, {"cell_type": "code", "outputs": [], "source": ["!ls -l ../input/ ../input/train"], "metadata": {"scrolled": true, "_cell_guid": "496c5756-4411-4e14-bf94-0fbcc973dee7", "_uuid": "ead8449a6187b8d65a87f51a8772ccae031cbef9"}, "execution_count": 3}, {"cell_type": "code", "outputs": [], "source": ["#%pycat ../input/train/README.md"], "metadata": {"collapsed": true, "_cell_guid": "42291b34-79d1-410e-81f1-f198f99042ad", "_uuid": "890b7bdae773cd939111f78070453d1d68ca30f0"}, "execution_count": 4}, {"cell_type": "code", "outputs": [], "source": ["!ls -F ../input/train/audio"], "metadata": {"_cell_guid": "5d5d5eeb-2a1e-4197-9245-6315515b2b46", "_uuid": "14a8640d4f057c7ef6715e6c437d0fe6685dbe4a"}, "execution_count": 5}, {"cell_type": "code", "outputs": [], "source": ["import os"], "metadata": {"collapsed": true, "_cell_guid": "2de54ccc-76d6-4b8b-a199-a55e4cdcb494", "_uuid": "7e61f075b1119c923ee5d610c8d9ad36916a3dc6"}, "execution_count": 6}, {"cell_type": "code", "outputs": [], "source": ["labels_ = !ls -d ../input/train/audio/[a-z]*/\n", "labels = [os.path.basename(os.path.dirname(p)) for p in labels_]\n", "print(len(labels), labels)"], "metadata": {"scrolled": true, "_cell_guid": "83a61070-6b8c-4589-8369-239df23577a3", "_uuid": "0bdb334b0678d1f5618d5ee30be3648c2d696284"}, "execution_count": 7}, {"cell_type": "markdown", "source": ["Note: There are only 12 possible labels for the Test set: yes, no, up, down, left, right, on, off, stop, go, silence, unknown.\n", "The unknown label should be used for a command that is not one one of the first 10 labels or that is not silence."], "metadata": {"_cell_guid": "1e749b59-cc15-4dfa-ae54-44ebabdea5ca", "_uuid": "de1ba48086be91e67976f35b2ace999eecbd6095"}}, {"cell_type": "code", "outputs": [], "source": ["!head -10 ../input/train/testing_list.txt"], "metadata": {"_cell_guid": "3fdbe6a2-4bdf-4e72-9205-046906be9085", "_uuid": "efdb1a87ee313b872c5845473b1953c2b4e8b2a0"}, "execution_count": 8}, {"cell_type": "code", "outputs": [], "source": ["!head -10 ../input/train/validation_list.txt"], "metadata": {"_cell_guid": "fa8ecd9a-f6a4-47c8-9b79-9045d00e797a", "_uuid": "7c473aa4b5e865caa8e8c3349a42240b43c7b107"}, "execution_count": 9}, {"cell_type": "code", "outputs": [], "source": ["!ls -l ../input/train/audio/_background_noise_/"], "metadata": {"_cell_guid": "a687915b-1187-4a9b-8248-8c8053efbd21", "_uuid": "b952da9051d677567261e075c0e69f5d5db6194b"}, "execution_count": 10}, {"cell_type": "code", "outputs": [], "source": ["%pycat ../input/train/audio/_background_noise_/README.md"], "metadata": {"collapsed": true, "_cell_guid": "ce8404c8-258b-4627-bb60-4666cddbea95", "_uuid": "fd475ca9ffe0ce4720ced87ae5ca54a2029bdf37"}, "execution_count": 11}, {"cell_type": "code", "outputs": [], "source": ["from IPython.display import display,Audio,Image,HTML"], "metadata": {"collapsed": true, "_cell_guid": "93b85cff-5431-4983-9864-69bddbe0f57d", "_uuid": "dae22cdd7ca5fe14542e8df444a5307b56d7dcd3"}, "execution_count": 12}, {"cell_type": "code", "outputs": [], "source": ["noise_list = !ls ../input/train/audio/_background_noise_/*.wav\n", "noise_list"], "metadata": {"scrolled": true, "_cell_guid": "84469487-38b6-4fe7-a0a8-f28407376133", "_uuid": "a639d5c3697f5ae8b273dd0c2510fcb4b1b8549d"}, "execution_count": 13}, {"cell_type": "code", "outputs": [], "source": ["for w in noise_list[0:3]:\n", "    display(HTML('<h4>{:s}</h4>'.format(os.path.basename(w))))\n", "    display(Audio(w))"], "metadata": {"_cell_guid": "f9e94cd8-7ece-4f43-a725-6115a1070256", "_uuid": "fdcc86eea376cde3cca1beb41058107be2b1decb"}, "execution_count": 14}, {"cell_type": "code", "outputs": [], "source": ["import librosa"], "metadata": {"collapsed": true, "_cell_guid": "b4ef2d2a-fca6-4b94-a596-eac7a5fd1e4f", "_uuid": "22d53a1db6ca210742a9dfc1028750f382fdae1c"}, "execution_count": 15}, {"cell_type": "code", "outputs": [], "source": ["bed_list = !ls ../input/train/audio/{labels[0]}/*.wav\n", "bed_list[-5:]"], "metadata": {"_cell_guid": "d98c0b96-92a7-4eb8-8373-aabd7d2ee9ef", "_uuid": "e3d5bc8cd95b524ec47c9963f0c7cecf76ca575e"}, "execution_count": 16}, {"cell_type": "code", "outputs": [], "source": ["for w in bed_list[-3:]:\n", "    display(HTML('<h4>{:s}</h4>'.format(os.path.basename(w))))\n", "    display(Audio(w))"], "metadata": {"_cell_guid": "b5be051e-f8d0-44c3-877f-e93dfa008c14", "_uuid": "47a6f11ffbc8227c7b60a94e33ca35d29ec56b76"}, "execution_count": 17}, {"cell_type": "code", "outputs": [], "source": ["bird_list = !ls ../input/train/audio/{labels[1]}/*.wav\n", "bird_list[-5:]"], "metadata": {"_cell_guid": "7fbb8e2a-ca46-4e54-b55b-d25a7a72b4ee", "_uuid": "8ec46b3e2db2c17a31fcc1eaa79d99dded4d0e68"}, "execution_count": 18}, {"cell_type": "code", "outputs": [], "source": ["yy1, sr1 = librosa.load(bird_list[0], sr=None, dtype=np.float32)\n", "yy1      = librosa.resample(yy1, sr1, 16000)\n", "print(yy1.shape)\n", "display(Audio(yy1,rate=16000))"], "metadata": {"_cell_guid": "b0151248-89a3-46f5-878c-321fe7f1cad2", "_uuid": "53392ee6d35baa31082909b12b0e8311b7e2df64"}, "execution_count": 19}, {"cell_type": "code", "outputs": [], "source": ["%matplotlib inline\n", "import matplotlib.pyplot as plt"], "metadata": {"collapsed": true, "_cell_guid": "597d4ce9-195d-45eb-84af-d4ec6ab1f474", "_uuid": "860483b54c32c2c94ff775c5bda2278926293e44"}, "execution_count": 20}, {"cell_type": "code", "outputs": [], "source": ["import time"], "metadata": {"collapsed": true, "_cell_guid": "d83dae0d-5359-4985-8054-476cba155e1f", "_uuid": "8a56fc652458b8b0bf87dba187a4e98b35e81bce"}, "execution_count": 21}, {"cell_type": "code", "outputs": [], "source": ["def display_wave(yy, sr=16000, filename=None, figsize=None, ylim=None, delay=None):\n", "    if figsize is None: figsize=(6,0.75)\n", "    if ylim is None: ylim=[-0.65,0.65]\n", "    if delay is None: delay=0.2\n", "    display(Audio(yy, rate=sr, filename=filename))\n", "    plt.figure(figsize=figsize)\n", "    plt.ylim(ylim)\n", "    plt.plot(np.arange(len(yy), dtype=np.float32)/sr,yy)\n", "    plt.show()\n", "    time.sleep(delay)\n"], "metadata": {"collapsed": true, "_cell_guid": "c20393b3-6286-44a7-a828-469167e0fdc2", "_uuid": "dc5cbbb5af50d48a0aecf40fa8993cfb1096a167"}, "execution_count": 22}, {"cell_type": "code", "outputs": [], "source": ["display_wave(yy1)"], "metadata": {"_cell_guid": "a13948e2-83f2-451c-bb81-f207c5f511d6", "_uuid": "51ff4ff62d45302030934d472dd8643269a63354"}, "execution_count": 23}, {"cell_type": "code", "outputs": [], "source": ["import tensorflow as tf\n", "print(tf.__version__)"], "metadata": {"_cell_guid": "c7bce8b5-7861-4de7-9d5a-17e3f8e28dce", "_uuid": "581fd16a9560d8d529ab9e46f15ec211774be4de"}, "execution_count": 24}, {"cell_type": "code", "outputs": [], "source": [], "metadata": {"collapsed": true, "_cell_guid": "c211776b-070d-4865-84d2-e97c3f8b60fd", "_uuid": "07e4b99b8e8e91f1560ebc3e5f6f883758f31569"}, "execution_count": null}], "nbformat_minor": 1, "metadata": {"language_info": {"mimetype": "text/x-python", "pygments_lexer": "ipython3", "version": "3.6.3", "name": "python", "nbconvert_exporter": "python", "codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py"}, "kernelspec": {"name": "python3", "display_name": "Python 3", "language": "python"}}}