question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stable Diffusion model clearing

See original GitHub issue

It would be nice to have a function that unloads modules from memory, otherwise when repeatedly using the StableDiffusion class, RAM overflow occurs

import keras_cv

import matplotlib.pyplot as plt


def plot_images(images):
    plt.figure(figsize=(20, 20))
    for i in range(len(images)):
        plt.subplot(1, len(images), i + 1)
        plt.imshow(images[i])
        plt.axis("off")

    plt.show()

for i in range(2):
    model = keras_cv.models.StableDiffusion(img_width=512 // (i + 1), img_height=512 // (i + 1))
    images = model.text_to_image("photograph of an astronaut riding a horse", batch_size=2)
    plot_images(images)

# Some other stuff 

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
freedomtancommented, Dec 20, 2022

move the line

model = keras_cv.models.StableDiffusion(img_width=512, img_height=512)

out of the loop. You only need to construct the pipeline once.

0reactions
Neizvestnyjcommented, Dec 23, 2022

or if you do need to clear the model, simply del model would work?

No, I try different methods, but RAM is overflow. I know that model optimized for 512*512, but it is not unloaded from memory after execution, which is why 4GB of memory is just so full.

Would you mind trying this instead? https://stackoverflow.com/questions/52133347/how-can-i-clear-a-model-created-with-keras-and-tensorflowas-backend

Yes, I’ve already tried it, it doesn’t help, 2 starts already takes about 8 GB of RAM

Read more comments on GitHub >

github_iconTop Results From Across the Web

README.md · stabilityai/stable-diffusion-2-1 at main
This model card focuses on the model associated with the Stable Diffusion v2-1 model, codebase available here. This stable-diffusion-2-1 ...
Read more >
How does Stable Diffusion work? - YouTube
StableDiffusion explained. How does an AI generate images from text? How do Latent Diffusion Models work? If you want answers to these ...
Read more >
Runway Released a Stable Diffusion-Powered Tool ... - 80 Level
Runway has released an Erase and Replace tool powered by Stable Diffusion that can change parts of images with whatever you tell the...
Read more >
Diffusion Models: A Practical Guide - Scale AI
With the Release of Dall-E 2, Google's Imagen, Stable Diffusion, and Midjourney, diffusion models have taken the world by storm, ...
Read more >
What are Stable Diffusion Models and Why are they a Step ...
Figure 1: Latent Diffusion Model (Base Diagram:[3], Concept-Map Overlay: Author). In this article you will learn about a recent advancement in Image ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found