0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

I made a CLI tool that automates Stable Diffusion

Last updated at Posted at 2025-08-15

In creative work and content production, image generation with Stable Diffusion (Stable Diffusion Web UI) has become an indispensable task. However, simple automation alone is insufficient—more efficient and reproducible workflows are required. This article provides detailed explanations of how to build professional-level image production workflows using automation tools, along with practical techniques.

CLI Interface in Action

CLI Interface

The actual execution screen in the terminal. You can see the colorful progress bars and real-time progress display.

Project Repository

Design Philosophy for Professional Workflows

Balancing Quality Management and Efficiency

In large-scale image production projects, both quality consistency and work efficiency are important. Manual work tends to create quality variations, while complete automation makes fine adjustments difficult. Effective workflows solve these challenges by combining the following elements:

Staged Quality Management
First perform test generation with a small number of settings, confirm expected quality is achieved, then proceed to full-scale batch processing. This avoids the risk of generating large quantities of low-quality images.

Configuration Templating
Create standard configuration templates for each project or use case, enabling efficient work while maintaining consistent quality.

Metadata Utilization
Leverage metadata attached to each image to analyze successful configurations and identify problematic settings, achieving continuous improvement.

Scalable Configuration Management

Large projects require managing hundreds to thousands of different configurations. Here are approaches for efficient configuration management:

Hierarchical Configuration Structure

prompts/
├── base-templates/
│   ├── character-base.jsonl      # Basic character generation settings
│   ├── landscape-base.jsonl      # Landscape base settings
│   └── portrait-base.jsonl       # Portrait base settings
├── projects/
│   ├── project-alpha/
│   │   ├── characters.jsonl
│   │   ├── backgrounds.jsonl
│   │   └── variations.jsonl
│   └── project-beta/
│       ├── marketing-materials.jsonl
│       └── product-shots.jsonl
└── experiments/
    ├── style-tests.jsonl
    ├── parameter-optimization.jsonl
    └── new-techniques.jsonl

This structure maintains project independence while enabling reuse of common configurations.

Advanced Configuration Techniques

Systematic Approach to Parameter Optimization

Finding optimal values for each parameter is crucial for effective image generation. Here are configuration examples for systematically adjusting parameters and comparing results:

CFG Scale Optimization

{"prompt": "masterpiece, 1girl, detailed portrait, professional lighting", "negative_prompt": "worst quality, bad quality, blurry", "width": 512, "height": 512, "sampler_name": "DPM++ 2M Karras", "steps": 25, "cfg_scale": 5, "seed": 12345, "batch_size": 1, "n_iter": 1, "hires_fix": false}
{"prompt": "masterpiece, 1girl, detailed portrait, professional lighting", "negative_prompt": "worst quality, bad quality, blurry", "width": 512, "height": 512, "sampler_name": "DPM++ 2M Karras", "steps": 25, "cfg_scale": 7, "seed": 12345, "batch_size": 1, "n_iter": 1, "hires_fix": false}
{"prompt": "masterpiece, 1girl, detailed portrait, professional lighting", "negative_prompt": "worst quality, bad quality, blurry", "width": 512, "height": 512, "sampler_name": "DPM++ 2M Karras", "steps": 25, "cfg_scale": 10, "seed": 12345, "batch_size": 1, "n_iter": 1, "hires_fix": false}
{"prompt": "masterpiece, 1girl, detailed portrait, professional lighting", "negative_prompt": "worst quality, bad quality, blurry", "width": 512, "height": 512, "sampler_name": "DPM++ 2M Karras", "steps": 25, "cfg_scale": 12, "seed": 12345, "batch_size": 1, "n_iter": 1, "hires_fix": false}
{"prompt": "masterpiece, 1girl, detailed portrait, professional lighting", "negative_prompt": "worst quality, bad quality, blurry", "width": 512, "height": 512, "sampler_name": "DPM++ 2M Karras", "steps": 25, "cfg_scale": 15, "seed": 12345, "batch_size": 1, "n_iter": 1, "hires_fix": false}

Using the same seed allows accurate comparison of CFG scale differences.

Sampler Comparison

{"prompt": "landscape, mountains, sunset, dramatic sky, cinematic", "negative_prompt": "worst quality, bad quality", "width": 768, "height": 512, "sampler_name": "Euler a", "steps": 25, "cfg_scale": 7, "seed": 54321, "batch_size": 1, "n_iter": 1, "hires_fix": true}
{"prompt": "landscape, mountains, sunset, dramatic sky, cinematic", "negative_prompt": "worst quality, bad quality", "width": 768, "height": 512, "sampler_name": "DPM++ 2M Karras", "steps": 25, "cfg_scale": 7, "seed": 54321, "batch_size": 1, "n_iter": 1, "hires_fix": true}
{"prompt": "landscape, mountains, sunset, dramatic sky, cinematic", "negative_prompt": "worst quality, bad quality", "width": 768, "height": 512, "sampler_name": "DPM++ SDE Karras", "steps": 25, "cfg_scale": 7, "seed": 54321, "batch_size": 1, "n_iter": 1, "hires_fix": true}
{"prompt": "landscape, mountains, sunset, dramatic sky, cinematic", "negative_prompt": "worst quality, bad quality", "width": 768, "height": 512, "sampler_name": "UniPC", "steps": 25, "cfg_scale": 7, "seed": 54321, "batch_size": 1, "n_iter": 1, "hires_fix": true}

Variation Generation Strategies

Techniques for efficiently generating diverse images with the same theme:

Gradual Prompt Changes

Create variations while maintaining consistency by gradually changing elements while preserving the base prompt:

{"prompt": "(by artgerm:0.8), 1girl, solo, office lady, business suit, professional, confident expression, modern office background", "negative_prompt": "worst quality, bad quality, amateur", "width": 680, "height": 1024, "sampler_name": "DPM++ 2M Karras", "steps": 30, "cfg_scale": 8, "seed": -1, "batch_size": 1, "n_iter": 3, "hires_fix": true}
{"prompt": "(by artgerm:0.8), 1girl, solo, office lady, business suit, professional, serious expression, modern office background", "negative_prompt": "worst quality, bad quality, amateur", "width": 680, "height": 1024, "sampler_name": "DPM++ 2M Karras", "steps": 30, "cfg_scale": 8, "seed": -1, "batch_size": 1, "n_iter": 3, "hires_fix": true}
{"prompt": "(by artgerm:0.8), 1girl, solo, office lady, business suit, professional, gentle smile, modern office background", "negative_prompt": "worst quality, bad quality, amateur", "width": 680, "height": 1024, "sampler_name": "DPM++ 2M Karras", "steps": 30, "cfg_scale": 8, "seed": -1, "batch_size": 1, "n_iter": 3, "hires_fix": true}
{"prompt": "(by artgerm:0.8), 1girl, solo, office lady, casual business attire, professional, friendly expression, modern office background", "negative_prompt": "worst quality, bad quality, amateur", "width": 680, "height": 1024, "sampler_name": "DPM++ 2M Karras", "steps": 30, "cfg_scale": 8, "seed": -1, "batch_size": 1, "n_iter": 3, "hires_fix": true}

Style-Unified Variations

An approach that unifies specific artist styles or techniques while changing content:

{"prompt": "(by studio ghibli:1.2), magical forest, ancient trees, soft sunlight, mystical atmosphere, detailed environment", "negative_prompt": "worst quality, bad quality, dark, horror", "width": 1024, "height": 768, "sampler_name": "Euler a", "steps": 28, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 2, "hires_fix": true}
{"prompt": "(by studio ghibli:1.2), floating island, clouds, peaceful village, soft sunlight, mystical atmosphere, detailed environment", "negative_prompt": "worst quality, bad quality, dark, horror", "width": 1024, "height": 768, "sampler_name": "Euler a", "steps": 28, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 2, "hires_fix": true}
{"prompt": "(by studio ghibli:1.2), crystal cave, glowing crystals, underground lake, soft sunlight, mystical atmosphere, detailed environment", "negative_prompt": "worst quality, bad quality, dark, horror", "width": 1024, "height": 768, "sampler_name": "Euler a", "steps": 28, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 2, "hires_fix": true}

Efficient Execution Strategies

Batch Design for Time Optimization

Strategies for efficiently performing large-scale image generation:

Priority-Based Execution

Generate high-importance images first, ensuring critical deliverables are secured even if interruption becomes necessary midway:

# High priority configuration file
npm start -- --configs-file prompts/high-priority.jsonl --save-meta

# After completion, execute medium priority
npm start -- --configs-file prompts/medium-priority.jsonl

# Finally execute low priority
npm start -- --configs-file prompts/low-priority.jsonl

Resource-Efficient Configuration

Achieve stable execution by adjusting configurations considering hardware resources:

{"prompt": "high quality portrait", "negative_prompt": "worst quality", "width": 512, "height": 512, "sampler_name": "Euler a", "steps": 20, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 5, "hires_fix": false}

By avoiding large image sizes or high step counts and instead increasing iteration count, you can generate many variations while controlling memory usage.

Workflow Improvement Through Metadata Utilization

Use metadata file information to continuously improve workflows:

Analyzing Success Patterns

# Extract successful configurations from metadata files
npm start -- --save-meta --configs-file analysis-test.jsonl

Analyze generated metadata files to identify configuration patterns that produced particularly good results, using them as reference for future configuration creation.

Ensuring Configuration Reproducibility

Use seed values saved in metadata to perform additional generation under the same conditions as liked images:

{"prompt": "same prompt", "negative_prompt": "same negative prompt", "width": 512, "height": 512, "sampler_name": "Euler a", "steps": 20, "cfg_scale": 7, "seed": 2605429855, "batch_size": 1, "n_iter": 10, "hires_fix": false}

Production Environment Operations

Quality Management Process

Staged Review System

  1. Pre-production: Validate concepts with small-scale tests
  2. Pilot generation: Confirm quality with limited batches
  3. Full production: Full-scale bulk generation
  4. Post-production: Analyze results and identify improvement points

Automated Quality Checks

Incorporate reference image generation for quality checking into configuration files:

{"prompt": "quality reference, detailed face, perfect lighting, masterpiece", "negative_prompt": "worst quality, bad quality", "width": 512, "height": 512, "sampler_name": "DPM++ 2M Karras", "steps": 30, "cfg_scale": 8, "seed": 100, "batch_size": 1, "n_iter": 1, "hires_fix": true}

Placing this configuration at the beginning of each batch enables monitoring generation quality consistency.

Risk Management and Failure Response

Configuration Backup Strategy

# Automate daily backups
cp prompts/current-project.jsonl "backups/project-$(date +%Y%m%d).jsonl"

Minimizing Failure Impact Through Staged Execution

Divide large batches into smaller units to limit impact when failures occur:

# Execute large batches in divided parts
npm start -- --configs-file batch-part1.jsonl
npm start -- --configs-file batch-part2.jsonl
npm start -- --configs-file batch-part3.jsonl

Performance Monitoring

Recording and Analyzing Execution Time

# Measure execution time
time npm start -- --configs-file performance-test.jsonl

Monitoring Resource Usage

Monitor system resource usage to find optimal configuration parameters.

Throughput Optimization

Compare processing speeds with different configurations to identify efficient parameter combinations.

Advanced Customization Techniques

Dynamic Configuration Using Environment Variables

Perform flexible configuration management using environment variables for different environments and purposes:

# Development environment execution
SD_WEBUI_URL=http://localhost:7860 OUTPUT_DIR=dev-output npm start

# Production environment execution  
SD_WEBUI_URL=http://production-server:7860 OUTPUT_DIR=production-output npm start

# High-quality settings execution
CONFIGS_FILE=prompts/high-quality.jsonl npm start -- --save-meta

Project-Specific Workflows

Character Design Workflow

{"prompt": "character design sheet, 1girl, front view, side view, back view, simple background, reference sheet", "negative_prompt": "worst quality, bad quality", "width": 1024, "height": 768, "sampler_name": "DPM++ 2M Karras", "steps": 35, "cfg_scale": 8, "seed": -1, "batch_size": 1, "n_iter": 3, "hires_fix": true}
{"prompt": "character portrait, 1girl, detailed face, expression sheet, multiple expressions", "negative_prompt": "worst quality, bad quality", "width": 768, "height": 768, "sampler_name": "DPM++ 2M Karras", "steps": 35, "cfg_scale": 8, "seed": -1, "batch_size": 1, "n_iter": 5, "hires_fix": true}

Commercial Content Production Workflow

{"prompt": "product photography, professional lighting, clean background, commercial quality", "negative_prompt": "amateur, bad lighting, cluttered", "width": 1024, "height": 1024, "sampler_name": "DPM++ 2M Karras", "steps": 40, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 10, "hires_fix": true}
{"prompt": "lifestyle photography, natural lighting, authentic setting, commercial quality", "negative_prompt": "amateur, bad lighting, staged", "width": 1024, "height": 768, "sampler_name": "DPM++ 2M Karras", "steps": 40, "cfg_scale": 7, "seed": -1, "batch_size": 1, "n_iter": 8, "hires_fix": true}

Approaches for Continuous Improvement

Data-Driven Optimization

Continuously improve workflows through analysis of generation results and metadata:

Defining Success Metrics

  • Generation quality consistency
  • Processing time efficiency
  • Resource usage optimization
  • Configuration reproducibility

Establishing Improvement Cycles

  1. Data Collection: Gather execution data from metadata files
  2. Analysis: Identify success patterns and problem patterns
  3. Hypothesis: Formulate improvement proposals
  4. Experimentation: Validate hypotheses with small-scale tests
  5. Implementation: Incorporate effective improvements into workflows

Team Collaboration Best Practices

Configuration Standardization

Create standard configuration templates to maintain consistent quality among team members.

Knowledge Sharing

Build systems for sharing successful configurations and troubleshooting knowledge within teams.

Version Control

Enable change history tracking and rapid recovery during problems through configuration file version control.

Summary

Professional-level Stable Diffusion image production requires strategic workflow design beyond simple automation. By combining the techniques introduced in this article, you can build production environments that balance quality, efficiency, and reproducibility.

Key Success Points

  1. Staged Approach: Start with small-scale tests and gradually scale up
  2. Data Utilization: Continuous improvement using metadata
  3. Risk Management: Design to minimize impact when failures occur
  4. Team Collaboration: Quality improvement through standardization and knowledge sharing

Through these practices, you can dramatically improve both productivity and quality in Stable Diffusion image production. Continue building more effective workflows through ongoing improvement and optimization.


Project Repository

You can find the complete source code, detailed documentation, practical configuration examples, and contribution guidelines for the tool introduced in this article.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?