Action segmentation framework built with PyTorch Lightning
Project description
Lightning Action
A modern action segmentation framework built with PyTorch Lightning for behavioral analysis.
Features
- Modern Architecture: Built with PyTorch Lightning for scalable and reproducible training
- Multiple Backbones: Support for TemporalMLP, RNN (LSTM/GRU), and Dilated TCN architectures
- Command-line Interface: Easy-to-use CLI for training and inference
- Comprehensive Logging: Built-in metrics tracking and visualization with TensorBoard
- Extensive Testing: Full test coverage for reliable development
Installation
Prerequisites
- Python 3.10+
- PyTorch with CUDA support (optional, for GPU training)
Install from Source
git clone https://github.com/paninski-lab/lightning-action.git
cd lightning-action
pip install -e .
Dependencies
Core dependencies include:
pytorch-lightning- Training frameworktorch- Deep learning backendnumpy- Numerical computingpandas- Data manipulationscikit-learn- Machine learning utilitiestensorboard- Experiment tracking
Quick Start
1. Prepare Your Data
Organize your data in the following structure:
data/
├── markers/
│ ├── experiment1.csv
│ ├── experiment2.csv
│ └── ...
├── labels/
│ ├── experiment1.csv
│ ├── experiment2.csv
│ └── ...
└── features/ # optional, hand-crafted featurization of markers or other video representations
├── experiment1.csv
├── experiment2.csv
└── ...
2. Create a Configuration File
Create a YAML configuration file (see configs/segmenter_example.yaml):
data:
data_path: /path/to/your/data
input_dir: markers
transforms: # optional, defaults to ZScore
- ZScore
model:
input_size: 10
output_size: 4
backbone: temporalmlp
num_hid_units: 256
num_layers: 2
optimizer:
type: Adam
lr: 1e-3
training:
num_epochs: 100
batch_size: 32
device: cpu # or 'gpu'
3. Train a Model
Using the CLI:
litaction train --config configs/my_config.yaml --output-dir runs/my_experiment
Using the Python API:
from lightning_action.api import Model
# Load model from config
model = Model.from_config('configs/my_config.yaml')
# Train model
model.train(output_dir='runs/my_experiment')
4. Generate Predictions
Using the CLI:
litaction predict --model-dir runs/my_experiment --data-dir /path/to/data --input-dir markers --output-dir predictions/
Using the Python API:
# Load trained model
model = Model.from_dir('runs/my_experiment')
# Generate predictions
model.predict(
data_path='/path/to/data',
input_dir='markers',
output_dir='predictions/'
)
See configs/README.md for detailed configuration options.
Monitoring Training with TensorBoard
Lightning Action automatically logs training metrics to TensorBoard. To visualize your training progress:
-
Launch TensorBoard after starting training:
tensorboard --logdir /path/to/your/runs/directory
-
Set the correct logdir: Use the deepest directory that contains all your model directories. For example:
# If your models are in: # runs/experiment1/ # runs/experiment2/ # runs/baseline/ # Launch TensorBoard with: tensorboard --logdir runs/
-
Open your browser and navigate to
http://localhost:6006to view the TensorBoard dashboard. -
Available metrics include:
- Training and validation loss
- Training and validation accuracy
- Training and validation F1 score
- Learning rate schedules
Tip: Keep TensorBoard running while training multiple experiments to compare results in real-time.
Development
Running Tests
# Install development dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run with coverage
pytest --cov=lightning_action
Code Style
The project uses:
flake8for lintingisortfor import sorting- Maximum line length: 99 characters
Project Structure
lightning_action/
├── api/ # High-level API for model usage
├── cli/ # Command-line interface
├── data/ # Data loading and preprocessing
├── models/ # Model architectures
│ └── backbones/ # Backbone implementations
└── tests/ # Test suite
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Run the test suite (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citation
If you use this framework in your research, please cite:
@software{lightning_action,
title = {Lightning Action: A PyTorch Lightning Framework for Action Segmentation},
author = {Whiteway, Matt},
url = {https://github.com/paninski-lab/lightning-action},
year = {2024}
}
Acknowledgments
This framework is built upon the work of:
- PyTorch Lightning for the training framework
- PyTorch for the deep learning backend
- Previous action segmentation work from the Paninski Lab
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lightning_action-1.0.0.tar.gz.
File metadata
- Download URL: lightning_action-1.0.0.tar.gz
- Upload date:
- Size: 65.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a533a2095acf6e2133a5e659434130cb97122e9c109c34569177c245e1fbf742
|
|
| MD5 |
96cea4d55b0fb3ce39c1eb880e8b6386
|
|
| BLAKE2b-256 |
5ab965b31d0dda80b962c5da450f1921040e8b48a6cfdad8fb4c7939ce1f56e8
|
File details
Details for the file lightning_action-1.0.0-py3-none-any.whl.
File metadata
- Download URL: lightning_action-1.0.0-py3-none-any.whl
- Upload date:
- Size: 86.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cd255a49324443db503c203248ee7703d89f9979ac18a936301e868bc3888ab
|
|
| MD5 |
5b199438538c1b2a419e4dcd2b8cadda
|
|
| BLAKE2b-256 |
99b2bf9ddfa47f39292847255c1ff9a53ba765e3808fc125be4929ac6cacf40f
|