This repository contains a minimal demo (demo.py) that loads example multichannel data (male Drosophila melanogaster courtship song), uses a TensorFlow Keras classifier to detect pulses, and plots/saves results.
Code and models were originally developed by Minseung Choi @minseungchoi, and were adapted for python 3 and tf.keras by Frederic Roemschied.
Preprint: Roemschied et al., bioRxiv (2025)
- Python 3.9
- TensorFlow (tested with 2.19)
- NumPy
- SciPy
- h5py
- Matplotlib
Optional (only if you want GPU acceleration): CUDA and cuDNN versions compatible with your TensorFlow installation.
Using mamba or conda (recommended on Windows):
mamba create -n py39tf python=3.9 -y
conda activate py39tf
# Install core packages from conda-forge
mamba install -c conda-forge numpy scipy matplotlib h5py -y
# Install TensorFlow (CPU build). For GPU builds, follow TensorFlow's Windows GPU install guide.
pip install "tensorflow==2.19.0"If you prefer a single pip environment:
python -m venv .venv
.venv\Scripts\activate # Windows
pip install --upgrade pip
pip install numpy scipy matplotlib h5py tensorflow==2.19.0Notes:
- If you have an NVIDIA GPU and want GPU acceleration, install a TensorFlow GPU build compatible with your CUDA/cuDNN versions. See the official TensorFlow Windows GPU guide: https://www.tensorflow.org/install
- You can adjust the
tensorflowversion if needed, but ensure it supports Python 3.9.
- Ensure the workspace contains the example data and model:
CLdata/20161213-155154bin_example_4314723_4347189.matmodels/dm_pnp_cnn_170411_3_maxCh_weights_tfkeras.h5
- Activate the environment you created (see above).
- Run the demo:
python demo.pyThis will:
- Load the example
.matfile fromCLdata/. - Load the classifier from
models/dm_pnp_cnn_170411_3_maxCh_weights_tfkeras.h5. - Show plots and save
figures/pulse_detection_demo.png.
If the model file is missing, demo.py will print model not found at <path>; ensure the model file is present at the path configured in demo.py (models/dm_pnp_cnn_170411_3_maxCh_weights_tfkeras.h5).
- Import errors: confirm you're running under the environment where packages were installed.
- TensorFlow errors on Windows: try installing a different TensorFlow build (CPU vs GPU) matching your system.
- If plotting doesn't display, ensure a GUI backend is available, or save-only by commenting out
plt.show()indemo.py.
demo.py— main demo scriptCLdata/— example .mat datamodels/— contains the Keras.h5modelfigures/— output images