![]() model = StableDiffusion(img_height=512, img_width=512, jit_compile=False) In addition, we also specify that we do not want to just-in-time compile the model with XLA (more details in the JIT compilation via XLA section). Each of these values must be a multiple of 128, and will be rounded to the nearest value if they are not. Below, we specify both the image height and width as 512 pixels. When we instantiate the Stable Diffusion model, we have the option to pass in some arguments. modify the inpainting region with sliders, so feel free to follow along there if you wish: Colab NotebookĪll of the advanced image generation and inpainting code can be found in main.py. The Colab notebook linked below makes it easy to e.g. ![]() We'll now take a look at advanced usage, both for image generation and inpainting. How to Use Stable Diffusion in Keras - Advanced Alternatively, jump down to the JIT compilation via XLA section to see how Keras can boost the speed of Stable Diffusion. That all it takes to use Stable Diffusion in Keras! In the next section, we'll look at more advanced usage like inpainting. The following image of "Iron Man making breakfast" is generated and saved to. With a terminal opened in the project directory, you can run the above script by entering the following command, which runs the simple.py script: python simple.pyĪgain, you may need to use python3 instead of python. Finally, we save the image to the filepath. We select the first (and only) image from the batch as img and then convert it to a Pillow Image via fromarray(). If we want, in addition, to save the image, we can import and use Pillow: from keras_cv.models import StableDiffusion We then use the text_to_image() method of this model to generate an image and save it to the img variable. We first import the StabelDiffusion class from Keras and then create an instance of it, model. Img = model.text_to_image("Iron Man making breakfast") We can use Stable Diffusion in just three lines of code: from keras_cv.models import StableDiffusion Step 3 - Install dependenciesįinally, install all required dependencies by running the below command: pip install -r requirements.txt How to Use Stable Diffusion in Keras - Basic You may need to use python3 instead of python if you have both Python 2 and Python 3 installed on your machine. If you want to keep all dependencies for this project isolated on your system, create and activate virtual environment: python -m venv venv git clone Ĭd stable-diffusion-keras Step 2 - Create a virtual environment ![]() Open a terminal and execute the below command to clone the project repository using git and then navigate into the project directory. To set up Stable Diffusion in Keras locally on your machine, follow along with the below steps. If you do not want to install anything on your computer, click on the button below to open the associated Colab notebook and follow along from there. Additionally, we look at how XLA can serve to significantly boost the efficiency of Stable Diffusion in Keras. We provide a thorough Colab notebook so you can get started right away in a GPU runtime. In this article, we will look at how to generate and inpaint images with Stable Diffusion in Keras. Recently, the ability to modify images via inpainting was also incorporated into the Keras implementation of Stable Diffusion. Stable Diffusion has been integrated into Keras, allowing users to generate novel images in as few as three lines of code. (Image from the Stable Diffusion Discord) Since its release, many different projects have been spun out of it, making it easier than ever to generate images like the one below with just a few simple words. Stable Diffusion was released earlier this year, providing the world with powerful text-to-image capabilities.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |