TINY DREAM

Mar 16, 2023 | Data Science

An embedded, Header Only, Stable Diffusion Inference C++ Library

Latest News

Introducing PixLab’s Tiny Dream

Tiny Dream is a powerful, header-only, dependency-free partially uncensored, Stable Diffusion implementation written in C++ with a primary focus on CPU efficiency and a smaller memory footprint. It runs remarkably fast on average consumer hardware, requiring only 1.7 ~ 5.5 GB of RAM to execute. Tiny Dream does not enforce Nvidia GPUs presence, making it versatile for various environments. Its design allows for easy embedding into larger codebases (host programs) with a user-friendly C++ API. The possibilities are virtually endless, extending to the boundaries of Stable Diffusion’s latent manifold.

Features

For the extensive list of features, please refer to the official documentation here.

  • OpenCV Dependency Free: The only required header is stb_image_write.h for saving images to disk.
  • Smallest, Run-Time Memory Footprint: Optimized for running Stable Diffusion in inferences.
  • Straightforward to Integrate on Existing Codebases: Just drop tinydream.hpp and stb_image_write.h into your source tree with the Pre-trained Models Assets.
  • Reasonably fast on Intel/AMD CPUs: Optimized with TBB threading and SSE/AVX vectorization.
  • Support for Real-ESRGAN: A Super Resolution Network Upscaler.
  • Full Support for Words Priority: Guides the model’s attention on specific keywords surrounded by parentheses.
  • Support for Output Metadata: Allows linking metadata to your output images.
  • Support for Stable Diffusion Extra Parameters: Adjusts parameters to refine the output.

Getting Started with Tiny Dream

Integrating Tiny Dream into your existing codebase is straightforward. Here’s how to do it:

Download Tiny Dream

  • Download the latest public release of Tiny Dream and extract the package in your desired directory.
  • Visit the downloads section to access Tiny Dream source code and Pre-Trained Models Assets.

Embedding Tiny Dream

  • The Tiny Dream source code comprises only two header files: tinydream.hpp and stb_image_write.h.
  • Simply drop these two C++ header files into your source tree. Then, instantiate a new tinyDream object as illustrated in the pseudo C++ code below:
  • #include "tinydream.hpp"
    
    // Main Entry Point. The only required argument is the Positive Prompt.
    // A Negative Prompt (words separated by commas) is highly recommended though.
    int main(int argc, char *argv[]) {
        tinyDream td; // stack allocated tinyDream object
        std::cout << tinyDream::about() << std::endl; // Library info
    
        // Check for prompts
        if (argc < 2) {
            std::cout << "Missing Positive (and potentially Negative) Prompt: Describe something you'd like to see generated..." << std::endl;
            return -1;
        }
    
        std::string positivePrompt = argv[1];
        std::string negativePrompt;
        if (argc > 2) negativePrompt = argv[2];
    
        td.dream(positivePrompt, negativePrompt);
        return 0; 
    }
    
  • The provided code is akin to cooking a recipe: follow the steps sequentially to create the perfect dish, or in this case, a generated image!

Learn the Fundamentals (C++ API)

  • The above code is designed to be user-friendly for any C++ programmer. The full C++ integration code for embedding Tiny Dream is available here.
  • For a comprehensive overview of the methods used in Tiny Dream, refer to the C++ API Reference Guide.

Project Roadmap

We have exciting enhancements planned for Tiny Dream, which can be found on the Roadmap page.

  • Move the tensor library to a less bloated alternative with a focus on CPU performances.
  • Introduce a Cross-Platform GUI implemented with Dear ImGUI.
  • Provide a Web-Assembly port for broader compatibility.
  • Enable output in dynamic formats like SVG or PSD instead of static PNGs.
  • Develop a proof of concept APK for Android.

Official Docs & Resources

Pre-Trained Models Assets Downloads Getting Started Guide Licensing C++ API Reference Guide Project Roadmap Features

Related Projects

Explore the following production-ready projects developed by PixLab and Symisc Systems:

  • SOD – An Embedded, Dependency-Free, Computer Vision C/C++ Library.
  • FACEIO – Cross Browser, Passwordless Facial Authentication Framework.
  • PixLab Annotate – Online Image Annotation, Labeling, Segmentation Tool.
  • ArtASCII – Real-Time ASCII Art Rendering C Library.
  • UnQLite – An Embedded, Transactional Key-Value Database Engine.

Troubleshooting

In case you run into issues, verify that:

  • You have the correct version of your compiler (C++17 or later).
  • The required libraries and headers are correctly linked.
  • Your prompts are correctly formatted and provided in the command line.

For assistance or further insights, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox