evolutionary-diffusion

Applying Evolutionary Computing to Embeddings of Diffusion Models

https://github.com/malthee/evolutionary-diffusion

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.6%) to scientific vocabulary

Keywords

aesthetics ai-detection clip-iqa clip-score colab colab-notebook diffusion-models evolutionary-algorithms genetic-algorithm image-generation jupyter jupyter-notebook laion nsga-ii optimization python stable-diffusion torch
Last synced: 4 months ago · JSON representation ·

Repository

Applying Evolutionary Computing to Embeddings of Diffusion Models

Basic Info
  • Host: GitHub
  • Owner: malthee
  • License: mit
  • Language: Jupyter Notebook
  • Default Branch: main
  • Homepage:
  • Size: 37.6 MB
Statistics
  • Stars: 11
  • Watchers: 3
  • Forks: 2
  • Open Issues: 0
  • Releases: 0
Topics
aesthetics ai-detection clip-iqa clip-score colab colab-notebook diffusion-models evolutionary-algorithms genetic-algorithm image-generation jupyter jupyter-notebook laion nsga-ii optimization python stable-diffusion torch
Created about 2 years ago · Last pushed 5 months ago
Metadata Files
Readme Changelog License Citation

README.md

Evolutionary-Diffusion

Combining Evolutionary Computing with Diffusion Models

Images

Audio

Try it out in Google Colab

| Notebook | Link | |--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Genetic Algorithm | Genetic Algorithm | | Island Genetic Algorithm | Island Genetic Algorithm | | NSGA | Genetic Algorithm |

Image results will be saved in your Google Drive in the folder evolutionary. Each generation creates a new folder where the images will be saved in. You can change the folders in the notebook.

Sometimes Google Collab causes dependency problems which break the notebook. If you have any issues executing this in a Collab environment, please do not hesitate to create a new issue.

Running locally

Optionally but recommended to use a venv. Clone the repo or download the .zip, then install the dependencies via:

pip install -e ".[all]" 

Now you are ready to go with the notebooks or custom code. CUDA and MPS are supported.

Example - Creating the most Aesthetic Image

Optimizing for Aesthetics using the Aesthetics Predictor V2 from LAION with a GA and SDXL-Turbo

Optimizing the aesthetics predictor as a maximization problem, the algorithm came to a max Aesthetics score of 8.67. This score is higher than the examples from the real LAION English Subset dataset have, with the red line showing the limit. A wide variety of prompts (inspired by parti prompts) was used for the initial population.

https://github.com/malthee/evolutionary-diffusion-results/assets/18032233/4841d671-639a-4ac4-b7a8-ee5a66fab28d

Ga200Gen100PopFitnessChartAesthetics

Parameters: ```python populationsize = 100 numgenerations = 200 batch_size = 1 elitism = 1

creator = SDXLPromptEmbeddingImageCreator(pipelinefactory=setuppipeline, batchsize=batchsize, inferencesteps=3) evaluator = AestheticsImageEvaluator()
crossover = PooledArithmeticCrossover(0.5, 0.5) mutation
arguments = UniformGaussianMutatorArguments(mutationrate=0.1, mutationstrength=2, clamprange=(-900, 900)) mutationargumentspooled = UniformGaussianMutatorArguments(mutationrate=0.1, mutationstrength=0.3, clamprange=(-8, 8)) mutator = PooledUniformGaussianMutator(mutationarguments, mutationargumentspooled) selector = TournamentSelector(tournamentsize=3) ```

Example - Island GA with Artists on each Island

Performing an Island GA by creating random embeddings and mixing them with artist embeddings to get mixtures of styles and new ideas.

| | | | | | --- | --- | --- | --- | | Mark Rothko chairs | Sketching Person Picasso | Dali Angles Crazy | Landscape Van Gogh |
| Character Walls Unique | Pattern Colorful | Woman Butterfly Landscape | Green Car City

More images

Example - Improving Audiobox Aesthetics Score

Starting from noisy random samples, evolving to better sounds. Using the sum of all fitness criteria Audiobox Aesthetics offers.

https://github.com/user-attachments/assets/25be32eb-188b-483a-a787-9cea4d7f5eeb

https://github.com/user-attachments/assets/17f4bef7-1f5a-47a4-8f29-e4f42519a4fe

Detailed Results and Notebooks

More detailed results can be found in a separate repository dedicated to the results of the experiments: https://github.com/malthee/evolutionary-diffusion-results

Evaluators

Image Creators

Current supported creators working in the prompt embedding space: * SDXLPromptEmbeddingImageCreator: Supports the SDXL pipeline, creates both prompt- and pooled-prompt-embeddings. * SDPromptEmbeddingImageCreator: Only has prompt-embeddings, is faster but produces less quality results than SDXL.

Audio Creators

Supporting only AudioLDM because it works simply on the CLAP embedding space (suitable for this kind of operation). Other embeddings have shown to not work well with evolutionary operations (like the T5 encoder for example) * AudioLDMSoundCreator: Works with any AudioLDMPipeline, default is audioldm-l-full

Package Structure and Base Classes

Package Diagram

Solution Candidate Class Diagram

(Pre-Testing) Evaluating Models for Evolutionary use

There are multiple notebooks exploring the speed and quality of models for generation and fitness-evaluation. These notebooks also allow for simple inference so that any model can be tried out easily.

  • diffusionmodelcomparison: tries out different diffusion models with varying arguments (inference steps, batch size) to find out the optimal model for image generation in an evolutionary context (generation speed & quality)
  • clip_evaluators: uses torch metrics with CLIPScore and CLIP IQA. CLIPScore could define the fitness for "prompt fulfillment" or "image alignment" while CLIP IQA has many possible metrics like "quality, brightness, happiness..."
  • aidetectionevaluator: uses a pre-trained model for AI image detection. This could be a fitness criteria to minimize "AI-likeness" in images.
  • aesthetics_evaluator: uses a pre-trained model from the maintainers of the LAION image dataset, which scores an image 0-10 depending on how "aesthetic" it is. Could be used as a maximization criteria for the fitness of images.
  • clamp_range: testing the usual prompt-embedding min and max values for different models, so that a CLAMP range can be set in the mutator for example. Using the parti prompts.
  • crossovermutationexperiments: testing different crossover and mutation strategies to see how they work in the prompt embedding space
  • embedding_relations: experimenting with TensorBoard and integrating it into our embedding model

Owner

  • Name: Marcel Salvenmoser
  • Login: malthee
  • Kind: user
  • Location: Austria, Hagenberg

Software Engineer, FH Hagenberg, Austria

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: Evolutionary Diffusion
message: Please cite this software using these metadata.
type: software
authors:
  - given-names: Marcel
    family-names: Salvenmoser
    affiliation: University of Applied Sciences Upper Austria
repository-code: 'https://github.com/malthee/evolutionary-diffusion'
repository-artifact: 'https://github.com/malthee/evolutionary-diffusion-results'
abstract: >-
  Applying Evolutionary Computing to Diffusion Models
  generating Images, Sound and Artwork driven by Fitness
keywords:
  - diffusion
  - evolution
  - genetic algorithm
  - island model
  - latent space
  - clip
  - prompt embedding
  - laion
  - jupyter
  - python
  - torch
  - exploration
license: MIT

GitHub Events

Total
  • Issues event: 3
  • Watch event: 5
  • Issue comment event: 2
  • Push event: 20
  • Fork event: 1
  • Create event: 3
Last Year
  • Issues event: 3
  • Watch event: 5
  • Issue comment event: 2
  • Push event: 20
  • Fork event: 1
  • Create event: 3

Committers

Last synced: almost 2 years ago

All Time
  • Total Commits: 20
  • Total Committers: 2
  • Avg Commits per committer: 10.0
  • Development Distribution Score (DDS): 0.25
Past Year
  • Commits: 20
  • Committers: 2
  • Avg Commits per committer: 10.0
  • Development Distribution Score (DDS): 0.25
Top Committers
Name Email Commits
Marcel Salvenmoser 1****e 15
Marcel Salvenmoser s****l@g****m 5

Issues and Pull Requests

Last synced: almost 2 years ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • malthee (2)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

setup.py pypi
  • matplotlib >=3.7
  • tqdm >=4.66.0