Giter Site home page Giter Site logo

welpo / png-to-pt-embedding Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 16 KB

A standalone Python tool for converting PNG image embeddings into PyTorch .pt files for Stable Diffusion models.

License: GNU General Public License v3.0

Python 100.00%
stable-diffusion stable-diffusion-embedding stable-diffusion-webui

png-to-pt-embedding's Introduction

PNG Embeddings to PyTorch Converter

This is a standalone Python script for converting PNG image embeddings generated by AUTOMATIC1111/stable-diffusion-webui into PyTorch .pt files.

Installation

  1. Clone or download this repository to your local machine.

  2. Open a terminal or command prompt and navigate to the directory containing the repository.

  3. Install the required packages by running the following command:

pip install -r requirements.txt

Usage

  1. Navigate to the directory containing the script (alternatively, you can place the script in your system's $PATH to run it from anywhere).

  2. Run the script using the following command:

python png_embedding_to_pt.py <path/to/image1.png> <path/to/image2.png> … -o <output_dir>

For example:

python png_embedding_to_pt.py embeddings/1.png embeddings/2.png -o pt_embeddings

This will save the .pt files to the pt_embeddings directory.

How it works

This script does the following:

  1. Loads the input PNG images
  2. Crops out any black borders
  3. Splits the least significant 4 bits of the RGB values into upper and lower data blocks, with columns of all black pixels separating them
  4. XORs the upper and lower data blocks with pseudo-random blocks to reveal the original data
  5. Combines the upper and lower blocks into a full data block
  6. Decompresses the data block using zlib to get the raw JSON data
  7. Decodes the JSON using a custom JSON decoder to convert PyTorch Tensors
  8. Saves the final embedding Torch Tensors to .pt files

Code adapted from AUTOMATIC1111/stable-diffusion-webui.

License

This script is licensed under the GNU General Public License version 3.

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.