Giter Site home page Giter Site logo

hubin858130 / stable-diffusion-streamlit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lowinli/stable-diffusion-streamlit

0.0 0.0 0.0 54.87 MB

Quantized stable-diffusion cutting down memory 75%, testing in streamlit, deploying in container

License: Other

Shell 4.21% Python 95.79%

stable-diffusion-streamlit's Introduction

Streamlit App

中文说明 | English

stable-diffusion-streamlit

1. Introduction

  • Create beautiful apps using Streamlit to test CompVis/stable-diffusion-v1-4 model quantized by OnnxRuntime cutting down memory 75%.
    • Streamlit:
      • an open-source app framework for Machine Learning and Data Science teams. Create beautiful web apps in minutes.
    • CompVis/stable-diffusion-v1-4:
      • a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
    • OnnxRuntime:
      • a cross-platform, faster inference and lower costs accelerator for machine learning models.

2. Getting Started

2.1. Deployment

  • docker-compose up -d
version: "2.3"
services:
  stable-diffusion-streamlit-onnxquantized:
    container_name: stable-diffusion-streamlit-onnxquantized
    image: lowinli98/stable-diffusion-streamlit-onnxquantized:v0.2
    expose:
      - 8501
    ports:
      - "8501:8501"
    environment:
      - APP_TITLE=Stable Diffusion Streamlit
    restart: always
    volumes:
      - /etc/localtime:/etc/localtime
      - ./volume:/app/pages/model/result

2.2. Usage

  • 2.2.1. Copy an awesome prompt from Blogs like best-100-stable-diffusion-prompts or 50-text-to-image-prompts-for-ai

  • 2.2.2. Open http://localhost:8501 and click "文本转图片" on the left sidebar.

  • 2.2.3. Fix the runtime parameters, paste your prompt into the text area and click the "开始生成" button.

  • 2.2.4. Wait for a while until the progress bar goes to the end, then you will get a generated image.

  • 2.2.5. Click "画廊" on the left sidebar to see all the images you had generated.

3. Quantization Performance

  • The model in the docker container has been quantized by OnnxRuntime in the building of the docker image.

  • The quantized model will be smaller and cut down the inference time a little(UINT8), while the performance of the image generated is almost the same as the original model.

  • This is an amazing feature because CompVis/stable-diffusion-v1-4 can be deployed on most home computers. The following table shows the comparison of the quantized model and the original model.


model memory used inference 49 steps waste time
pytorch 5.2GB 6m56s
onnx 5.0GB 4m34s
onnx-quantized(UINT8) 1.3GB 4m29s
  • CPU:

    • Intel(R) Xeon(R) CPU E5-2650 v3 @ 2.30GHz
    • 10 core
  • image generated by PyTorch model

  • image generated by Onnx model

  • image generated by Onnx-Quantized(UINT8) model

4. Streamlit Progress Bar

To generate an awesome image, the model needs to be inferences with many steps. So it will take a long time to finish the whole pipeline. To make the user experience better, a progress bar is added to show the pipeline progress. With another thread in Python, the progress bar can be updated by the pipeline scheduler counter.

5. To Do

6. Get Help

7. Acknowledgements

stable-diffusion-streamlit's People

Contributors

lowinli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.