Most of the requirements come with python or will already be installed in most conda environments, however, all non-standard ones are listed below.
pillow
scipy
numpy
- Create a folder called "Things" and fill it with the images you want to use to create the target image
- Run things2pickle.py to create an index of all the images. This can be run again to update the index at any time
- Put the target image in the folder and give it the name "target.png"
- Run thingsAI.py
config.json is used to change some of the optional settings in ThingsAI. Each option as well as their accepted settings are explained below.
- MinSizeMode - true/false - Enables the minsize mode. If enabled, images will be no smaller than a set percentage of the target
- MinSize - 0 to 1 decimal - The minimum size of each image if minsize mode is enabled. Expressed as decimal percentage of the target image
- Mutation rate - 0 to 1 decimal - The rate at which mutations occur
- Population size - integer - The size of the population
- SurvivalRate - 0 to 1 decimal - Percentage of the top of the population that will be kept
- GenerationCycles - integer - The number of cycles in each generation
- GIF - true/false - Enables the creation of a gif of the evolution with each frame being a new addition to the canvas. Use with caution as the process can be slowed down.
- SampleRate - To speed up the algorithm, the scoring algorithm can be set to sample every Nth pixel. The default is 1, which samples every pixel.
- Backstep - By default, the best scoring image can be 2000 points further from the target than the current canvas. This allows the image constantly change and prevents the algorithm from getting stuck. This value can be used to change how far back adding a "thing" can take the image. One step back and two steps forward!
Each generation begins by creating a population (defined in config,default 1000) and assigning them each a random position, rotation, and scale. At the start of the first cycle, each image is placed into a temporary canvas, then scored based on how much closer it gets the canvas to the target image. At the end of each cycle, the population is sorted based on score and the top percentage (defined in config) of the population is kept. This surviving population then generates mutated offspring. By default the top 25% survives and each then produces 3 offspring to generate the next 1000 item population. This repeats for a number of cycles (defined in config, default 10). At the end of the final cycle, the best image is permanently added to the canvas and the current canvas is saved as product.png. At any point product.png can be viewed and the process can be terminated. If GIF mode is enabled, each canvas will also be added to the end of the product.gif to generate an animation of the evolution process.