Motion2Health is an open-source Python package and research framework for livestock health outcome prediction (Gamma-Glutamyl Transferase - GGT) using continuous triaxial accelerometry data and behavior classification.
- Package-First Modular Architecture: Includes high-level API wrappers, pre-trained PyTorch deep learning models, preprocessing pipelines, and a command-line interface (CLI).
- Unified Predictor Engine (
GGTPredictor): Simple Python API and CLI tool to run GGT outcome predictions using 12 pre-trained classical and deep learning workflows. - CLI Terminal Tool (
motion2health): Run predictions directly from your terminal or bash scripts without writing Python boilerplate code. - Automated Test Suite: Built-in
pytestcoverage for data preprocessing, neural network inference, and CLI execution. - 12 Benchmarking Workflows:
- Classical Tabular Models:
ElasticNet,LME,RandomForest,SVM - Deep Learning Models:
MultiScale-CNN + LSTM,MultiScale-CNN + Causal Transformer - Direct Sensor & Behavior-Disentangled Architectures
- Classical Tabular Models:
Install directly via pip:
pip install motion2healthOr install from source in editable mode:
git clone https://github.com/SydneyBioX/motion2health.git
cd motion2health
pip install -e .[dev]from motion2health import GGTPredictor
# Initialize predictor with the behavior-disentangled Random Forest model
predictor = GGTPredictor(workflow="behaviour_rf")
# Predict GGT outcome on Study Day 14
predicted_ggt = predictor.predict_ggt(
csv_path="data/sample_animal.csv",
baseline_ggt=32.0, # Pre-trial baseline GGT (U/L)
study_day=14 # Target day (-7 to 24)
)
print(f"Predicted GGT Value: {predicted_ggt:.2f} U/L")# Initialize deep learning Transformer workflow
predictor_dl = GGTPredictor(workflow="behaviour_transformer")
# Predict GGT with Monte Carlo Test-Time Augmentation (TTA)
predicted_ggt_dl = predictor_dl.predict_ggt(
csv_path="data/sample_animal.csv",
baseline_ggt=28.5,
study_day=7
)
print(f"Transformer Predicted GGT: {predicted_ggt_dl:.2f} U/L")Run predictions directly from the shell:
# Display package info and available model workflows
motion2health info
# Run prediction on a 1 Hz sensor CSV file
motion2health predict \
--csv data/sample_animal.csv \
--baseline-ggt 35.0 \
--study-day 10 \
--workflow direct_transformerOutput as JSON for automated pipelines:
motion2health predict --csv data/sample_animal.csv --baseline-ggt 35.0 --study-day 10 --jsonmotion2health/
├── motion2health/ # Package source code
│ ├── __init__.py # Package initialization & exports
│ ├── predictor.py # Main GGTPredictor class
│ ├── architectures.py # PyTorch neural net architectures (CNN/LSTM/Transformer)
│ ├── preprocessing.py # 1 Hz rolling feature extraction & validation
│ ├── cli.py # Command Line Interface (CLI) engine
│ └── models/ # Pre-trained model weight binaries
├── tests/ # Automated pytest unit test suite
│ ├── test_predictor.py
│ ├── test_preprocessing.py
│ └── test_cli.py
├── examples/ # Python usage examples
│ ├── basic_prediction.py
│ └── advanced_workflows.py
├── docs/ # User guides and architecture documentation
│ ├── user_guide.md
│ └── architectures/
├── paper/ # Research paper benchmark & reproduction scripts
│ ├── README.md
│ ├── evaluate.py
│ └── train_production_models.py
├── pyproject.toml # Build & package configuration
├── setup.py # Setuptools entrypoint
└── README.md
Run unit tests locally with pytest:
pytestResearch paper evaluation scripts, 5-fold cross-validation benchmarks, and SHAP explainability routines are located in the paper/ directory.
Distributed under the MIT License.