Skip to content

Add Stable Diffusion portrait generation script - #927

Open
banti0238-afk wants to merge 1 commit into
CompVis:mainfrom
banti0238-afk:banti0238-afk-super-bassoon
Open

Add Stable Diffusion portrait generation script#927
banti0238-afk wants to merge 1 commit into
CompVis:mainfrom
banti0238-afk:banti0238-afk-super-bassoon

Conversation

@banti0238-afk

Copy link
Copy Markdown

Overview

Adds a standalone Python script to generate portrait images using Stable Diffusion v1.5 with CPU-optimized inference settings.

Changes

  • generate_portrait.py: New script for generating portraits with the following features:
    • Uses the Hugging Face diffusers library for easy model loading and inference
    • Optimized for CPU execution with attention slicing and reduced inference steps (20 instead of default 50)
    • Disables safety checker to improve performance on CPU-constrained environments
    • Generates 512x512 images using a professional photography prompt template
    • Automatically creates output directory and saves results as PNG

Implementation Details

  • Model: runwayml/stable-diffusion-v1-5 from Hugging Face Hub
  • Inference steps: 20 (reduced from default 50 for faster CPU generation)
  • Guidance scale: 7.5
  • Image size: 512x512
  • Output: outputs/hot_woman_portrait.png

Usage

python generate_portrait.py

The script will automatically download the model on first run and generate the image. Typical CPU generation time: 15-30 minutes.

Notes

  • Requires: torch, diffusers, transformers, pillow, scipy, safetensors
  • GPU (CUDA) detection supported for faster inference when available
  • Memory optimized with attention slicing for systems with limited resources

- Create optimized CPU inference script for generating portrait images
- Disable safety checker to improve performance on CPU
- Use attention slicing to reduce memory consumption
- Reduced inference steps (20) for faster generation on CPU
- Generate 512x512 portrait with professional photography prompt

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant