Skip to content

murthylab/closed_loop_song_segmenter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLsegmenterDemo

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)

Environment requirements

  • 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.

Create an environment (recommended: mambaforge / conda)

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.0

Notes:

  • 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 tensorflow version if needed, but ensure it supports Python 3.9.

Run the demo

  1. Ensure the workspace contains the example data and model:
    • CLdata/20161213-155154bin_example_4314723_4347189.mat
    • models/dm_pnp_cnn_170411_3_maxCh_weights_tfkeras.h5
  2. Activate the environment you created (see above).
  3. Run the demo:
python demo.py

This will:

  • Load the example .mat file from CLdata/.
  • 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).

Troubleshooting

  • 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() in demo.py.

Files of interest

  • demo.py — main demo script
  • CLdata/ — example .mat data
  • models/ — contains the Keras .h5 model
  • figures/ — output images

About

CNN-based fast Drosophila song segmenter for closed-loop applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%