This workflow changes paper/ink/scan texture while preserving glyph geometry.
Install core dependencies:
pip install torch torchvision diffusers accelerate transformers opencv-python safetensors peft datasets tqdmOr install the project-wide unified dependency file:
pip install -r requirements.txtBase models used by default:
stabilityai/stable-diffusion-xl-base-1.0diffusers/controlnet-canny-sdxl-1.0
Generate square crops from real pecha pages using Canny edge density sampling.
python cli.py prepare-texture-lora-dataset \
--input_dir /path/to/real_pecha_pages \
--output_dir /path/to/texture_lora_dataset \
--crop_size 1024 \
--num_crops_per_page 12 \
--min_edge_density 0.025 \
--seed 42Outputs:
- Crops:
/path/to/texture_lora_dataset/images/*.png - Metadata:
/path/to/texture_lora_dataset/metadata.jsonl
Single-process run:
python cli.py train-texture-lora \
--dataset_dir /path/to/texture_lora_dataset \
--output_dir /path/to/texture_lora_output \
--resolution 1024 \
--batch_size 1 \
--lr 1e-4 \
--max_train_steps 1500 \
--rank 16 \
--lora_alpha 16 \
--mixed_precision fp16 \
--gradient_checkpointing \
--seed 42Distributed/multi-GPU run (recommended when available):
accelerate launch scripts/train_texture_lora_sdxl.py \
--dataset_dir /path/to/texture_lora_dataset \
--output_dir /path/to/texture_lora_output \
--resolution 1024 \
--batch_size 1 \
--lr 1e-4 \
--max_train_steps 1500 \
--rank 16 \
--lora_alpha 16 \
--mixed_precision fp16 \
--gradient_checkpointing \
--seed 42Outputs:
- LoRA weights:
/path/to/texture_lora_output/texture_lora.safetensors - Config:
/path/to/texture_lora_output/training_config.json
Conservative defaults for structure preservation:
strength=0.2(hard-clamped to<=0.25)controlnet_scale=2.0guidance_scale=1.0
python cli.py texture-augment \
--input_dir /path/to/synthetic_renders \
--output_dir /path/to/synthetic_textured \
--strength 0.2 \
--steps 28 \
--guidance_scale 1.0 \
--controlnet_scale 2.0 \
--seed 123With LoRA:
python cli.py texture-augment \
--input_dir /path/to/synthetic_renders \
--output_dir /path/to/synthetic_textured \
--lora_path /path/to/texture_lora_output/texture_lora.safetensors \
--lora_scale 0.8 \
--strength 0.2 \
--controlnet_scale 2.0 \
--seed 123You can also run scripts directly:
python scripts/prepare_texture_lora_dataset.py ...python scripts/train_texture_lora_sdxl.py ...python scripts/texture_augment.py ...