File size: 8,885 Bytes
338d95d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# CompI Phase 1.E: Personal Style Fine-tuning with LoRA
## π― Overview
Phase 1.E enables you to train **personalized artistic styles** using LoRA (Low-Rank Adaptation) fine-tuning on Stable Diffusion. This allows you to create AI art that reflects your unique artistic vision or mimics specific artistic styles.
**LoRA Benefits:**
- β
**Lightweight**: Only trains a small adapter (~10-100MB vs full model ~4GB)
- β
**Fast**: Training takes minutes to hours instead of days
- β
**Flexible**: Can be combined with different base models
- β
**Efficient**: Runs on consumer GPUs (8GB+ VRAM recommended)
## π οΈ Tools Provided
### 1. **Dataset Preparation** (`compi_phase1e_dataset_prep.py`)
- Organize and validate your style images
- Generate appropriate training captions
- Resize and format images for optimal training
- Create train/validation splits
### 2. **LoRA Training** (`compi_phase1e_lora_training.py`)
- Full LoRA fine-tuning pipeline with PEFT integration
- Configurable training parameters and monitoring
- Automatic checkpoint saving and validation
- Memory-efficient training with gradient checkpointing
### 3. **Style Generation** (`compi_phase1e_style_generation.py`)
- Generate images using your trained LoRA styles
- Interactive and batch generation modes
- Adjustable style strength and parameters
- Integration with existing CompI pipeline
### 4. **Style Management** (`compi_phase1e_style_manager.py`)
- Manage multiple trained LoRA styles
- Cleanup old checkpoints and organize models
- Export style information and analytics
- Switch between different personal styles
## π Quick Start Guide
### Step 1: Install Dependencies
```bash
# Install LoRA training dependencies
pip install peft datasets bitsandbytes
# Verify installation
python -c "import peft, datasets; print('β
Dependencies installed')"
```
### Step 2: Prepare Your Style Dataset
```bash
# Organize your style images in a folder
mkdir my_artwork
# Copy 10-50 images of your artistic style to my_artwork/
# Prepare dataset for training
python src/generators/compi_phase1e_dataset_prep.py \
--input-dir my_artwork \
--style-name "my_art_style" \
--trigger-word "myart"
```
**Dataset Requirements:**
- **10-50 images** (more is better, but 20+ is usually sufficient)
- **Consistent style** across all images
- **512x512 pixels** recommended (will be auto-resized)
- **High quality** images without watermarks or text
### Step 3: Train Your LoRA Style
```bash
# Start LoRA training
python run_lora_training.py \
--dataset-dir datasets/my_art_style \
--epochs 100 \
--learning-rate 1e-4
# Or with custom settings
python run_lora_training.py \
--dataset-dir datasets/my_art_style \
--epochs 200 \
--batch-size 2 \
--lora-rank 8 \
--lora-alpha 32
```
**Training Tips:**
- **Start with 100 epochs** for initial testing
- **Increase to 200-500 epochs** for stronger style learning
- **Monitor validation loss** to avoid overfitting
- **Use gradient checkpointing** if you run out of memory
### Step 4: Generate with Your Style
```bash
# Generate images with your trained style
python run_style_generation.py \
--lora-path lora_models/my_art_style/checkpoint-1000 \
"a cat in myart style" \
--variations 4
# Interactive mode
python run_style_generation.py \
--lora-path lora_models/my_art_style/checkpoint-1000 \
--interactive
```
## π Advanced Usage
### Training Configuration
```bash
# High-quality training (slower but better results)
python run_lora_training.py \
--dataset-dir datasets/my_style \
--epochs 300 \
--learning-rate 5e-5 \
--lora-rank 16 \
--lora-alpha 32 \
--batch-size 1 \
--gradient-checkpointing
# Fast training (quicker results for testing)
python run_lora_training.py \
--dataset-dir datasets/my_style \
--epochs 50 \
--learning-rate 2e-4 \
--lora-rank 4 \
--lora-alpha 16
```
### Style Management
```bash
# List all trained styles
python src/generators/compi_phase1e_style_manager.py --list
# Get detailed info about a style
python src/generators/compi_phase1e_style_manager.py --info my_art_style
# Clean up old checkpoints (keep only 3 most recent)
python src/generators/compi_phase1e_style_manager.py --cleanup my_art_style --keep 3
# Export styles information to CSV
python src/generators/compi_phase1e_style_manager.py --export my_styles_report.csv
```
### Generation Parameters
```bash
# Adjust style strength
python run_style_generation.py \
--lora-path lora_models/my_style/checkpoint-1000 \
--lora-scale 0.8 \
"portrait in myart style"
# High-quality generation
python run_style_generation.py \
--lora-path lora_models/my_style/checkpoint-1000 \
--steps 50 \
--guidance 8.0 \
--width 768 \
--height 768 \
"landscape in myart style"
```
## π¨ Best Practices
### Dataset Preparation
1. **Consistent Style**: All images should represent the same artistic style
2. **Quality over Quantity**: 20 high-quality images > 100 low-quality ones
3. **Diverse Subjects**: Include various subjects (people, objects, landscapes)
4. **Clean Images**: Remove watermarks, text, and irrelevant elements
5. **Proper Captions**: Use consistent trigger words in captions
### Training Tips
1. **Start Small**: Begin with 50-100 epochs to test
2. **Monitor Progress**: Check validation loss and sample generations
3. **Adjust Learning Rate**: Lower if loss oscillates, higher if learning is slow
4. **Use Checkpoints**: Save frequently to avoid losing progress
5. **Experiment with LoRA Rank**: Higher rank = more capacity but slower training
### Generation Guidelines
1. **Include Trigger Words**: Always use your trigger word in prompts
2. **Adjust Style Strength**: Use `--lora-scale` to control style intensity
3. **Combine with Techniques**: Mix with existing CompI style/mood systems
4. **Iterate and Refine**: Generate multiple variations and select best results
## π§ Troubleshooting
### Common Issues
**Out of Memory Error:**
```bash
# Reduce batch size and enable gradient checkpointing
python run_lora_training.py \
--dataset-dir datasets/my_style \
--batch-size 1 \
--gradient-checkpointing \
--mixed-precision
```
**Style Not Learning:**
- Increase epochs (try 200-500)
- Check dataset consistency
- Increase LoRA rank (try 8 or 16)
- Lower learning rate (try 5e-5)
**Generated Images Don't Match Style:**
- Include trigger word in prompts
- Increase LoRA scale (try 1.2-1.5)
- Train for more epochs
- Check dataset quality
**Training Too Slow:**
- Reduce image resolution to 512x512
- Use mixed precision training
- Enable gradient checkpointing
- Reduce LoRA rank to 4
## π File Structure
```
Project CompI/
βββ datasets/ # Prepared training datasets
β βββ my_art_style/
β βββ train/ # Training images
β βββ validation/ # Validation images
β βββ train_captions.txt # Training captions
β βββ dataset_info.json # Dataset metadata
βββ lora_models/ # Trained LoRA models
β βββ my_art_style/
β βββ checkpoint-100/ # Training checkpoints
β βββ checkpoint-200/
β βββ training_info.json # Training metadata
βββ src/generators/
β βββ compi_phase1e_dataset_prep.py # Dataset preparation
β βββ compi_phase1e_lora_training.py # LoRA training
β βββ compi_phase1e_style_generation.py # Style generation
β βββ compi_phase1e_style_manager.py # Style management
βββ run_lora_training.py # Training launcher
βββ run_style_generation.py # Generation launcher
```
## π― Integration with CompI
Phase 1.E integrates seamlessly with existing CompI tools:
1. **Combine with Phase 1.B**: Use LoRA styles alongside predefined styles
2. **Evaluate with Phase 1.D**: Assess your LoRA-generated images systematically
3. **UI Integration**: Add LoRA styles to Streamlit/Gradio interfaces
4. **Batch Processing**: Generate multiple variations for evaluation
## π Next Steps
After mastering Phase 1.E:
1. **Experiment with Multiple Styles**: Train different LoRA adapters for various artistic approaches
2. **Style Mixing**: Combine multiple LoRA styles for unique effects
3. **Advanced Techniques**: Explore Textual Inversion, DreamBooth, or ControlNet integration
4. **Community Sharing**: Share your trained styles with the CompI community
5. **Phase 2 Preparation**: Use personal styles as foundation for multimodal integration
---
**Happy Style Training! π¨β¨**
Phase 1.E opens up endless possibilities for personalized AI art generation. With LoRA fine-tuning, you can teach the AI to understand and replicate your unique artistic vision, creating truly personalized creative content.
|