Coder Social home page Coder Social logo

evo-clip-sketch's Introduction

Sketching with Evolutionary Algorithms and CLIP

Implementation of Evoltionary CLIP Sketches, a gym-like environment for painting simple sketches and integration of an evolutionary algorithm to search a good solution for an input text. The repository uses OpenAI's CLIP (https://github.com/openai/CLIP) to parse the input text and calculate a reward/fitness for the gym environment and evolutionary algorithm.

The work is inspired by Google Brain's Modern Evolution Strategies for Creativity: Fitting Concrete Images and Abstract Concepts (https://arxiv.org/pdf/2109.08857.pdf & https://github.com/google/brain-tokyo-workshop/tree/master/es-clip), which investigates an bstract image generation process. This repository provides an easy-to-use and challenging image generation environment which can be efficiently run on CPUs.

The available evolutionary algorithm for sketch finding is PGPE, a derivative-free policy gradient estimation algorithm (https://github.com/nnaisense/pgpelib). The algorithm works sufficiently better for this environment compared to standard evolutionary strategies (at least for my initial experiments), but I will add the code and configuration parameter to run these as well. The idea to test PGPE is also inspired by Google Brain's mentioned work.

Instructions

  1. Clone this repo.
git clone https://github.com/patrickraoulphilipp/evo-clip-sketch
cd evo-clip-sketch
  1. (optional) Create a virtualenv. The implementation has been tested for Python 3.9.
virtualenv venv
source venv/bin/activate
  1. Install all dependencies. You need both pgelib and CLIP, which will be automatically installed from their respective git repos.
pip install -r requirements.txt .
  1. Set parameters in config.py. For now, all relevant parameters are to be set in as dictionary. The most important ones to get started are target_words to set the textual goal for the sketch and max_steps to set the number of relative points to be selected. target_dir enables to set the target directory to save the best sketches in the process.
config = {
    'target_words' : 'a cat', # text for calculating CLIP-based fitness
    'max_steps' : 20, # number of relative points for one episode/sktech
    'target_dir' : '/PATH/TO/FOLDER/', # folder for saving generated sketches
    ...
}
  1. Run main.py to start the search process. You will a continuous stream of sketches that are being testes by the evolutionary algorithm. Only the sketches which improve the best global reward/fitness are saved.
python main.py

evo-clip-sketch's People

Contributors

patrickraoulphilipp avatar

Watchers

 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.