-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for image generation using Consistency Models using Diffu…
…sers (#490) * add: example for LCM * add: colab badges
- Loading branch information
1 parent
cc3bf73
commit 2ee0fd3
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Image Generation with Consistency Models using 🤗 Diffusers\n", | ||
"\n", | ||
"[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/wandb/examples/blob/master/colabs/diffusers/lcm-diffusers.ipynb)\n", | ||
"\n", | ||
"This notebook demonstrates the following:\n", | ||
"- Performing text-conditional image-generations with the [Consistency Models](https://huggingface.co/docs/diffusers/api/pipelines/consistency_models) using [🤗 Diffusers](https://huggingface.co/docs/diffusers).\n", | ||
"- Manage image generation experiments using [Weights & Biases](http://wandb.ai/site).\n", | ||
"- Log the prompts, generated images and experiment configs to [Weigts & Biases](http://wandb.ai/site) for visalization.\n", | ||
"\n", | ||
"![](./assets/diffusers-autolog-4.gif)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install diffusers transformers accelerate wandb > install.log" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import random\n", | ||
"\n", | ||
"import torch\n", | ||
"from diffusers import DiffusionPipeline\n", | ||
"\n", | ||
"import wandb\n", | ||
"from wandb.integration.diffusers import autolog" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Initialize the diffusion pipeline for latent consistency model\n", | ||
"pipeline = DiffusionPipeline.from_pretrained(\"SimianLuo/LCM_Dreamshaper_v7\")\n", | ||
"pipeline = pipeline.to(torch_device=\"cuda\", torch_dtype=torch.float32)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Define the prompts, negative prompts, and seed.\n", | ||
"prompt = [\n", | ||
" \"a photograph of an astronaut riding a horse\",\n", | ||
" \"a photograph of a dragon\"\n", | ||
"]\n", | ||
"\n", | ||
"# Make the experiment reproducible by controlling randomness.\n", | ||
"# The seed would be automatically logged to WandB.\n", | ||
"generator = torch.Generator(device=\"cpu\").manual_seed(10)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Call WandB Autolog for Diffusers. This would automatically log\n", | ||
"# the prompts, generated images, pipeline architecture and all\n", | ||
"# associated experiment configs to Weights & Biases, thus making your\n", | ||
"# image generation experiments easy to reproduce, share and analyze.\n", | ||
"autolog(init=dict(project=\"diffusers_logging\"))\n", | ||
"\n", | ||
"# call the pipeline to generate the images\n", | ||
"images = pipeline(\n", | ||
" prompt,\n", | ||
" num_images_per_prompt=2,\n", | ||
" generator=generator,\n", | ||
" num_inference_steps=10,\n", | ||
")\n", | ||
"\n", | ||
"# End the experiment\n", | ||
"wandb.finish()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters