├── run_jupyter.sh ├── jupyter_notebook_config.py ├── README.md ├── Dockerfile └── Label data.ipynb /run_jupyter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | jupyter notebook "$@" --NotebookApp.token=abc --allow-root 3 | -------------------------------------------------------------------------------- /jupyter_notebook_config.py: -------------------------------------------------------------------------------- 1 | import os 2 | from IPython.lib import passwd 3 | 4 | c.NotebookApp.ip = '*' 5 | c.NotebookApp.port = int(os.getenv('PORT', 8888)) 6 | c.NotebookApp.open_browser = False 7 | c.MultiKernelManager.default_kernel_name = 'python2' 8 | c.NotebookApp.password = '' 9 | c.NotebookApp.token = '' 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # batdetection 2 | Detecting the sounds bats make in my backyard. 3 | 4 | To run this code, install Docker. 5 | Steps to get it running: 6 | `docker run -p 8888:8888 rmeertens/batdetection` 7 | Then navigate in your browser to localhost:8888 8 | 9 | 10 | Post that explains what I did: http://www.pinchofintelligence.com/detecting-bats-recognising-sound-tensorflow/ 11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:latest 2 | # Various Python and C/build deps 3 | RUN apt-get update && apt-get install -y \ 4 | wget \ 5 | build-essential \ 6 | cmake \ 7 | git \ 8 | unzip \ 9 | pkg-config \ 10 | python-dev \ 11 | python-opencv \ 12 | libopencv-dev \ 13 | libav-tools \ 14 | libjpeg-dev \ 15 | libpng-dev \ 16 | libtiff-dev \ 17 | libjasper-dev \ 18 | libgtk2.0-dev \ 19 | python-numpy \ 20 | python-pycurl \ 21 | libatlas-base-dev \ 22 | gfortran \ 23 | webp \ 24 | python-opencv \ 25 | qt5-default \ 26 | libvtk6-dev \ 27 | zlib1g-dev 28 | 29 | COPY jupyter_notebook_config.py /root/.jupyter/ 30 | COPY run_jupyter.sh / 31 | RUN chmod +x /run_jupyter.sh 32 | RUN pip install Cython --install-option="--no-cython-compile" 33 | RUN pip install tflearn scikit-image scikit-learn pandas keras 34 | RUN pip install librosa 35 | WORKDIR "/notebooks" 36 | ADD . /notebooks 37 | CMD ["/run_jupyter.sh"] 38 | -------------------------------------------------------------------------------- /Label data.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Labeling sound data\n", 8 | "Last week I discovered that there are bats outside of my appartment. To detect when there is one I took a \"bat detector\", a device that brings the high pitched noise bats make back to hearable levels. To split the data into \"batsound\" and \"no sound\" I made this Jupyter notebook to label the data.\n", 9 | "\n", 10 | "Note that we use the librosa library to load the data. Humans can label either as bat (1) or no bat (0). Audiosamples of 1 second are saved to the bat and no-bat folders. \n" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "import librosa\n", 20 | "import os\n", 21 | "import numpy as np\n", 22 | "import matplotlib.pyplot as plt\n", 23 | "import IPython\n", 24 | "\n", 25 | "\n", 26 | "directory = \"batsounds\"\n", 27 | "filename = \"bats8.m4a\"\n", 28 | "openfile = os.path.join(directory, filename)\n", 29 | "\n", 30 | "print(\"Loading \" + openfile)\n", 31 | "soundarray, sr = librosa.load(openfile) # This operation can take a long time with large sound files\n", 32 | "\n", 33 | "# We take 1 second per sample, which comes down to sampling-rate variables per sample. \n", 34 | "maxseconds = int(len(X)/sr)\n", 35 | "for second in range(maxseconds-1):\n", 36 | " print(str(second) + \" out of \" + str(maxseconds))\n", 37 | " audiosample = np.array(soundarray[second*sr:(second+1)*sr])\n", 38 | " IPython.display.display(IPython.display.Audio(audiosample, rate=sr,autoplay=True))\n", 39 | " label = str(input(\"bat(1) or not (0)\"))\n", 40 | "\n", 41 | " outputfilename = os.path.join(\"labeled\", label, filename + str(second) + \".wav\")\n", 42 | " print(\"Saving to: \" + outputfilename)\n", 43 | " librosa.output.write_wav(outputfilename, audiosample, sr)\n" 44 | ] 45 | } 46 | ], 47 | "metadata": { 48 | "kernelspec": { 49 | "display_name": "Python 2", 50 | "language": "python", 51 | "name": "python2" 52 | }, 53 | "language_info": { 54 | "codemirror_mode": { 55 | "name": "ipython", 56 | "version": 2 57 | }, 58 | "file_extension": ".py", 59 | "mimetype": "text/x-python", 60 | "name": "python", 61 | "nbconvert_exporter": "python", 62 | "pygments_lexer": "ipython2", 63 | "version": "2.7.12" 64 | } 65 | }, 66 | "nbformat": 4, 67 | "nbformat_minor": 2 68 | } 69 | --------------------------------------------------------------------------------