This example showcases inference of text to image models like Stable Diffusion 1.5, 2.1, LCM. The application doesn't have many configuration options to encourage the reader to explore and modify the source code. For example, change the device for inference to GPU. The sample features ov::genai::Text2ImagePipeline
and uses a text prompt as input source.
Users can change the sample code and play with the following generation parameters:
- Change width or height of generated image
- Generate multiple images per prompt
- Adjust a number of inference steps
- Play with guidance scale (read more details)
- (SD 1.x, 2.x only) Add negative prompt when guidance scale > 1
The --upgrade-strategy eager
option is needed to ensure optimum-intel
is upgraded to the latest version.
It's not required to install ../../requirements.txt for deployment if the model has already been exported.
pip install --upgrade-strategy eager -r ../../requirements.txt
optimum-cli export openvino --model dreamlike-art/dreamlike-anime-1.0 --task stable-diffusion --weight-format fp16 dreamlike_anime_1_0_ov/FP16
stable_diffusion ./dreamlike_anime_1_0_ov/FP16 'cyberpunk cityscape like Tokyo New York with tall buildings at dusk golden hour cinematic lighting'
Prompt: cyberpunk cityscape like Tokyo New York with tall buildings at dusk golden hour cinematic lighting
Models can be downloaded from OpenAI HiggingFace. This sample can run the following list of models, but not limitied to:
- botp/stable-diffusion-v1-5
- stabilityai/stable-diffusion-2
- stabilityai/stable-diffusion-2-1
- dreamlike-art/dreamlike-anime-1.0
- SimianLuo/LCM_Dreamshaper_v7
- Image generated with HuggingFace / Optimum Intel is not the same generated by this C++ sample:
C++ random generation with MT19937 results differ from numpy.random.randn()
and diffusers.utils.randn_tensor
. So, it's expected that image generated by Python and C++ versions provide different images, because latent images are initialize differently. Users can implement their own random generator derived from ov::genai::Generator
and pass it to Text2ImagePipeline::generate
method.