File size: 6,593 Bytes
80b58c8 | 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 | # Byte Dream - Setup Guide
## Quick Start (Windows)
### 1. Install Dependencies
#### Option A: Using pip (Recommended)
```cmd
cd "c:\Users\Enzo\Documents\Byte Dream"
pip install -r requirements.txt
```
#### Option B: Using conda
```cmd
cd "c:\Users\Enzo\Documents\Byte Dream"
conda env create -f environment.yml
conda activate bytedream
```
### 2. Verify Installation
```cmd
python quick_start.py
```
This will check if all dependencies are installed and test the model.
### 3. Generate Your First Image
#### Command Line
```cmd
python infer.py --prompt "A beautiful sunset over mountains, digital art" --output sunset.png
```
#### Web Interface
```cmd
python app.py
```
Then open http://localhost:7860 in your browser.
#### Python Script
```python
from bytedream import ByteDreamGenerator
generator = ByteDreamGenerator()
image = generator.generate(
prompt="A cyberpunk city at night with neon lights",
num_inference_steps=50,
guidance_scale=7.5
)
image.save("cyberpunk_city.png")
```
## Model Training
### Prepare Your Dataset
1. Collect images in a folder (JPG, PNG formats)
2. Optionally add .txt files with captions for each image
3. Run preparation script:
```cmd
python prepare_dataset.py --input ./my_images --output ./processed_data --size 512
```
### Train the Model
```cmd
python train.py --train_data ./processed_data --output_dir ./models/bytedream --epochs 100 --batch_size 4
```
Training time depends on:
- Dataset size
- Number of epochs
- CPU speed (expect several hours to days for CPU training)
## Hugging Face Deployment
### Upload to Hugging Face Hub
1. Get your Hugging Face token from https://huggingface.co/settings/tokens
2. Upload model:
```cmd
python upload_to_hf.py --model_path ./models/bytedream --repo_id your_username/bytedream --token YOUR_TOKEN
```
### Deploy to Spaces
1. Create Gradio app file (already included as `app.py`)
2. Go to https://huggingface.co/spaces
3. Click "Create new Space"
4. Choose Gradio SDK
5. Upload all project files
6. Select CPU hardware (COSTAR or similar)
7. Deploy!
## File Structure
```
Byte Dream/
βββ bytedream/ # Core package
β βββ __init__.py # Package initialization
β βββ model.py # Neural network architectures
β βββ pipeline.py # Generation pipeline
β βββ scheduler.py # Diffusion scheduler
β βββ generator.py # Main generator class
β βββ utils.py # Utility functions
βββ train.py # Training script
βββ infer.py # Command-line inference
βββ app.py # Gradio web interface
βββ main.py # High-level application API
βββ prepare_dataset.py # Dataset preparation
βββ upload_to_hf.py # Hugging Face upload
βββ quick_start.py # Quick start guide
βββ config.yaml # Configuration
βββ requirements.txt # Python dependencies
βββ environment.yml # Conda environment
βββ README.md # Documentation
βββ LICENSE # MIT License
```
## Usage Examples
### Basic Generation
```cmd
python infer.py -p "A dragon flying over castle" -o dragon.png
```
### Advanced Parameters
```cmd
python infer.py -p "Fantasy landscape" -n "ugly, blurry" -W 768 -H 768 -s 75 -g 8.0 --seed 42
```
### Batch Generation (Python)
```python
from bytedream import ByteDreamGenerator
generator = ByteDreamGenerator()
prompts = [
"Sunset beach, palm trees, tropical paradise",
"Mountain landscape, snow peaks, alpine lake",
"Forest path, sunlight filtering through trees"
]
images = generator.generate_batch(
prompts=prompts,
width=512,
height=512,
num_inference_steps=50
)
for i, img in enumerate(images):
img.save(f"landscape_{i}.png")
```
## Performance Optimization
### CPU Optimization
The model is already optimized for CPU, but you can:
1. Increase threads in `config.yaml`:
```yaml
cpu_optimization:
threads: 8 # Set to number of CPU cores
precision: fp32
```
2. Use fewer inference steps for faster generation:
```cmd
python infer.py -p "Quick preview" -s 20
```
3. Generate smaller images:
```cmd
python infer.py -p "Small image" -W 256 -H 256
```
### Memory Management
For systems with limited RAM:
1. Enable memory efficient mode (already default)
2. Generate one image at a time
3. Restart Python between batch generations
## Troubleshooting
### Import Errors
If you get import errors:
```cmd
pip install --upgrade torch transformers diffusers
```
### Memory Errors
Reduce image size or inference steps:
```cmd
python infer.py -p "Test" -W 256 -H 256 -s 20
```
### Slow Generation
CPU generation is slower than GPU. Expect:
- 256x256: ~30-60 seconds
- 512x512: ~2-5 minutes
- 768x768: ~5-10 minutes
Times vary by CPU speed and number of steps.
### Model Not Loading
The model needs trained weights. Either:
1. Train your own model using `train.py`
2. Download pretrained weights from Hugging Face
3. Use Stable Diffusion weights as base
## Tips for Better Results
### Writing Prompts
- Be specific and descriptive
- Include style references ("digital art", "oil painting")
- Mention lighting ("dramatic lighting", "soft sunlight")
- Add quality modifiers ("highly detailed", "4K", "masterpiece")
### Negative Prompts
Use to avoid common issues:
```
ugly, blurry, low quality, distorted, deformed, bad anatomy, extra limbs
```
### Parameters
- **Steps**: 20-30 (quick), 50 (good), 75-100 (best)
- **Guidance**: 5-7 (creative), 7-9 (balanced), 9-12 (strict)
- **Resolution**: Start with 512x512, increase if needed
## Advanced Features
### Custom Schedulers
Edit `config.yaml` to try different schedulers:
- DDIM (default) - Fast, deterministic
- EulerDiscrete - Alternative sampling
### Fine-tuning
Fine-tune on specific styles:
1. Collect 50-100 images in desired style
2. Prepare dataset
3. Train for 50-100 epochs with low learning rate (1e-6)
## Support
For issues and questions:
1. Check this guide first
2. Review README.md
3. Check code comments
4. Visit Hugging Face documentation
## Updates
Check for updates and improvements:
- New model architectures
- Better CPU optimization
- Additional features
- Bug fixes
Enjoy creating with Byte Dream! π¨
|