infer_hf_stable_diffusion
Ikomia HUB

infer_hf_stable_diffusion

GitHub

About

1.1.1
MIT

Stable diffusion models from Hugging Face.

Task: Image generation
Stable Diffusion
Hugging Face
Stability-AI
text-to-image
Generative

Run stable diffusion models from Hugging Face.

Astronaute xl

🚀 Use with Ikomia API

1. Install Ikomia API

We strongly recommend using a virtual environment. If you're not sure where to start, we offer a tutorial here.

pip install ikomia

2. Create your workflow

from ikomia.dataprocess.workflow import Workflow
from ikomia.utils.displayIO import display

# Init your workflow
wf = Workflow()

# Add algorithm
algo = wf.add_task(name="infer_hf_stable_diffusion", auto_connect=False)

# Run  
wf.run()

# Display the image
display(algo.get_output(0).get_image())

☀️ Use with Ikomia Studio

Ikomia Studio offers a friendly UI with the same features as the API.

  • If you haven't started using Ikomia Studio yet, download and install it from this page.

  • For additional guidance on getting started with Ikomia Studio, check out this blog post.

📝 Set algorithm parameters

  • model_name (str) - default 'stabilityai/stable-diffusion-2-base': Name of the stable diffusion model. Other model available:
    • CompVis/stable-diffusion-v1-4
    • runwayml/stable-diffusion-v1-5
    • stabilityai/stable-diffusion-2-base
    • stabilityai/stable-diffusion-2
    • stabilityai/stable-diffusion-2-1-base
    • stabilityai/stable-diffusion-2-1
    • stabilityai/stable-diffusion-xl-base-1.0
  • prompt (str): Input prompt.
  • negative_prompt (str, optional): The prompt not to guide the image generation. Ignored when not using guidance (i.e., ignored if guidance_scale is less than 1).
  • num_inference_steps (int) - default '50': Number of denoising steps (minimum: 1; maximum: 500).
  • guidance_scale (float) - default '7.5': Scale for classifier-free guidance (minimum: 1; maximum: 20).
  • seed (int) - default '-1': Seed value. '-1' generates a random number between 0 and 191965535.
from ikomia.dataprocess.workflow import Workflow
from ikomia.utils.displayIO import display

# Init your workflow
wf = Workflow()

# Add algorithm
algo = wf.add_task(name = "infer_hf_stable_diffusion", auto_connect=False)

algo.set_parameters({
    'model_name': 'stabilityai/stable-diffusion-xl-base-1.0',
    'prompt': 'Astronaut on Mars during sunset',
    'guidance_scale': '7.5',
    'negative_prompt': 'low resolution',
    'num_inference_steps': '50',
    'seed': '1981651'
})

# Run directly on your image
wf.run()

# Display the image
display(algo.get_output(0).get_image())

🔍 Explore algorithm outputs

Every algorithm produces specific outputs, yet they can be explored them the same way using the Ikomia API. For a more in-depth understanding of managing algorithm outputs, please refer to the documentation.

import ikomia
from ikomia.dataprocess.workflow import Workflow

# Init your workflow
wf = Workflow()

# Add algorithm
algo = wf.add_task(name="infer_hf_stable_diffusion", auto_connect=False)

# Run 
wf.run()

# Iterate over outputs
for output in algo.get_outputs():
    # Print information
    print(output)
    # Export it to JSON
    output.to_json()

Developer

  • Ikomia
    Ikomia

License

MIT License
Read license full text

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

PermissionsConditionsLimitations

Commercial use

License and copyright notice

Liability

Modification

Warranty

Distribution

Private use

This is not legal advice: this description is for informational purposes only and does not constitute the license itself. Provided by choosealicense.com.