A sophisticated AI-powered music composition system using transformer neural networks for generating beautiful melodies.
π Major Updates:
- β
Interactive Training - Just run
python train.pyand configure everything interactively - β GPU Auto-Detection - Automatically detects and configures GPU for 10x speed boost
- β Beautiful Progress Bars - Real-time training progress in both CLI and GUI
- β Performance Optimizations - Mixed precision, XLA compilation, optimized data pipeline
- β Modern GUI - Redesigned interface with live progress tracking
- β Smart Defaults - Automatically adjusts model complexity based on hardware
- Transformer Architecture with multi-head attention
- Relative Position Encoding for musical context
- GPU Acceleration with automatic mixed precision
- Configurable Model Size (2-6 layers, 128-512D embeddings)
- MIDI File Support - Train on your own MIDI collections
- Event-Based Tokenization - Handles notes, timing, dynamics
- Multiple Time Signatures - 4/4, 3/4, 6/8, and more
- Key Signature Detection - Automatic musical key analysis
- Interactive Training Setup - No command-line arguments needed
- Real-Time Progress Bars - See exactly what's happening
- Modern GUI Interface - Beautiful ttkbootstrap design
- Smart Hardware Detection - Optimizes for CPU or GPU automatically
- GPU Training: ~2 minutes per epoch (10x faster than CPU)
- CPU Training: ~20 minutes per epoch (optimized for CPU-only systems)
- Automatic Optimization - XLA, mixed precision, memory growth
- Efficient Data Pipeline - Caching, prefetching, parallel processing
# Clone the repository
git clone https://github.com/yourusername/Melodia.git
cd Melodia
# Install with GPU support (recommended)
pip install -r requirements.txt
# Verify GPU detection
python -c "import tensorflow as tf; print(f'GPUs: {len(tf.config.list_physical_devices(\"GPU\"))}')"# Just run this - it will ask you everything!
python train.pyThe script will guide you through:
- π Data directory selection
- π§ Model configuration (auto-optimized for your hardware)
- π Training parameters with smart defaults
- β‘ Performance optimizations
- π Real-time training with progress bars
# Fast 3-epoch test with minimal model
python quick_train.py# Launch the modern GUI
python melodia_gui.py| Hardware | Time/Epoch | 10 Epochs | Model Size | Notes |
|---|---|---|---|---|
| GPU | ~2 min | ~20 min | 4 layers, 256D | Recommended |
| CPU | ~20 min | ~3.3 hours | 2 layers, 128D | Slower but works |
GPU Benefits:
- π 10x faster training
- π§ Larger models (better quality)
- β‘ Mixed precision (2x memory efficiency)
- π₯ XLA compilation (additional speedup)
$ python train.py
π΅ Welcome to Melodia Interactive Training! π΅
π΅ ============================================ π΅
MELODIA INTERACTIVE TRAINING SETUP
π΅ ============================================ π΅
π DATA CONFIGURATION
------------------------------
Training data directory [data]: <Enter>
β
Found 7 MIDI files
π§ MODEL CONFIGURATION
------------------------------
π Checking GPU availability...
β
Found 1 GPU(s): GPU 0: /physical_device:GPU:0
π GPU detected - you can use larger models!
Embedding dimension [256]: <Enter>
Number of transformer layers [4]: <Enter>
...
π ESTIMATED TRAINING TIME:
GPU: ~40 minutes (0.7 hours)
βΆοΈ Start training? [Y/n]: y
π STARTING TRAINING...
Epochs: 20%|ββββββ | 2/10 [04:32<18:08, 136.05s/epoch, loss=0.7234, acc=0.812, time=2.3m]
Training: 67%|βββββββ | 402/603 [01:43<00:51, loss=0.7234]# Generate music from trained model
python generate.py --model_dir models --output_dir outputs --num_samples 3 --style jazz
# Output: Generated 3 MIDI files in outputs/python melodia_gui.py
# Click "Start Training" to see beautiful progress bars!Melodia/
βββ π train.py # Interactive training (main entry point)
βββ π quick_train.py # Fast test training
βββ π generate.py # Music generation
βββ π melodia_gui.py # Modern GUI interface
βββ π demo.py # Basic functionality demo
βββ π data/ # Training MIDI files
βββ π melodia/ # Core library
β βββ π model/ # Neural network architecture
β βββ π training/ # Training pipeline with progress bars
β βββ π data/ # Data processing & MIDI loading
β βββ π generation/ # Music generation
β βββ π evaluation/ # Model evaluation metrics
βββ π models/ # Saved model checkpoints
βββ π outputs/ # Generated music files
βββ π tests/ # Unit tests
# Place MIDI files in the data directory
data/
βββ song1.mid
βββ song2.mid
βββ ...python train.py
# Follow the interactive prompts!Watch the beautiful progress bars show:
- β Epoch Progress - Overall training progress
- β Batch Progress - Within-epoch progress
- β Loss/Accuracy - Real-time metrics
- β Time Estimates - How long remaining
python generate.py --model_dir models --num_samples 5- Embedding Dimension: 128 (fast) to 512 (high quality)
- Transformer Layers: 2 (fast) to 6 (complex)
- Attention Heads: 4 (simple) to 12 (detailed)
- Sequence Length: 256 (short) to 1024 (long contexts)
- Batch Size: 8 (CPU) to 32 (GPU)
- Learning Rate: 0.0001 to 0.01
- Epochs: 10 (quick) to 200 (thorough)
- Validation Split: 0.1 (10% validation)
- GPU: Automatic mixed precision, XLA compilation
- CPU: Optimized threading, smaller models
- Memory: Dynamic GPU memory growth
- π Data Directory Selection with file browser
- π§ Model Configuration with intelligent defaults
- π Training Parameters with validation
- π Live Progress Bars with real-time metrics
- β±οΈ Time Estimates and completion tracking
- πΌ Model Selection with file browser
- π΅ Style Selection (Classical, Jazz, Folk, Blues)
- βοΈ Generation Parameters (temperature, samples)
- π― Output Configuration with preview
from melodia.config import ModelConfig, TrainingConfig
from melodia.training.trainer import Trainer
# Custom model configuration
model_config = ModelConfig(
embedding_dim=256,
num_layers=4,
num_heads=8,
max_sequence_length=512
)
# Custom training configuration
training_config = TrainingConfig(
batch_size=16,
learning_rate=0.001,
max_epochs=50
)import tensorflow as tf
# Configure GPU memory growth (done automatically)
gpus = tf.config.list_physical_devices('GPU')
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)# Run unit tests
python -m pytest tests/ -v
# Test specific components
python -m pytest tests/test_model.py -v
python -m pytest tests/test_training.py -v- β Use batch sizes 16-32
- β Enable mixed precision (automatic)
- β Use larger models (4-6 layers)
- β Train for more epochs (50-200)
- β Use batch sizes 4-8
- β Use smaller models (2-3 layers)
- β Reduce sequence length (256-512)
- β Train for fewer epochs (10-30)
- β Use multiple MIDI files for variety
- β Ensure consistent time signatures
- β Include diverse musical styles
- β Preprocess long pieces into chunks
"No GPU found"
# Install GPU support
pip install tensorflow[and-cuda]
# Verify CUDA installation
nvidia-smi"Training too slow"
# Use quick training for testing
python quick_train.py
# Or reduce model size in interactive setup
python train.py
# Choose smaller embedding_dim and num_layers"Out of memory"
# Reduce batch size in training configuration
# GPU: Try batch_size 8 instead of 16
# CPU: Try batch_size 4 instead of 8"MIDI files not loading"
# Check file format
# Ensure files are standard MIDI (.mid or .midi)
# Check data directory contains MIDI filesWe welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Run the tests (
python -m pytest) - Submit a pull request
# Clone for development
git clone https://github.com/yourusername/Melodia.git
cd Melodia
# Install in development mode
pip install -e .
# Install development dependencies
pip install -r requirements-dev.txtThis project is licensed under the MIT License - see the LICENSE file for details.
- TensorFlow team for the amazing ML framework
- music21 for comprehensive music analysis tools
- ttkbootstrap for the beautiful modern GUI components
- tqdm for the excellent progress bar library
- π§ Email: your.email@example.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
Made with β€οΈ for music and AI enthusiasts
Transform your MIDI collections into AI-powered music generation with beautiful progress tracking and modern interfaces! π΅β¨