• Stars
    star
    155
  • Rank 239,758 (Top 5 %)
  • Language
    Python
  • Created over 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create animated art pieces with machine learning using a DCGAN. Procedurally generate tiles for any type of mosaic.

Art created with artificial intelligence

A deep convolutional generative adversarial network (DCGAN) is trained on pictures of art. Images are procedurally created from the generative neural network by sampling the latent space. Information on the neural network architecture can be found here: https://arxiv.org/abs/1511.06434. Use the procedurally generated images to create mosaics.

Dependencies

  • Python 3+
  • Keras, Tensorflow, Matplotlib, Numpy, PIL, Scikit-learn

Creating an animated mosaic

Load a pretrained model into animated_mosaic.py and then run the script. Creating a video will take about 10-30 minutes depending on the length because each frame is rendered individually. The images from the neural network will be saved to a directory called images/. Afterwards, a video can be created by stitching the images into a gif or mp4 with ffmpeg. For example:

ffmpeg -framerate 30 -i "fluidart_%05d.png" -c:v libx264 -pix_fmt yuv420p fluidart.mp4

Examples

I have included a pretrained model for generating space tiles

generator (space_128_64).h5 will create images like the one below. The images are generated from a latent parameter space of 128 dimensions and the output images will be 64 x 64. This network was trained on images of galaxies from the NASA image archive.

Thin film inference on the surface of a bubble

Fluid Art - 128x128px output from a 256 dimensional latent space trained on images of acrylic pour/fluid art after 10000 training epochs

Train your own model

  1. Download your favorite images to a new directory
  2. Change some parameters below like: directory, name, latent_dim, epochs, etc..
  3. Run the code
from dcgan import DCGAN, create_dataset

if __name__ == '__main__':

    x_train, y_train = create_dataset(128,128, nSlices=150, resize=0.75, directory='space/')
    assert(x_train.shape[0]>0)

    x_train /= 255 

    dcgan = DCGAN(img_rows = x_train[0].shape[0],
                    img_cols = x_train[0].shape[1],
                    channels = x_train[0].shape[2], 
                    latent_dim=32,
                    name='nebula_32_128')
                    
    dcgan.train(x_train, epochs=10000, batch_size=32, save_interval=100)

The neural network will create outputs during the training process to the folder: images/. This process could take a while depending on your computer. For comparison the two pretrained models used 15000 training epochs which took ~1-2 hours on a GTX 1070.

Creating a custom data set

The create_dataset function will cut random slices from images to create a new data set. This function requires you to put images in a new directory before hand

import matplotlib.pyplot as plt
import numpy as np

from dcgan import create_dataset 

# first resize the original image to 75% 
# then cut 100 random 128x128 subframes from each image in the directory 
x_train, y_train = create_dataset(128,128, nSlices=100, resize=0.75, directory='space/')

# scale RGB data between 0 and 1
x_train /= 255 

# plot results to make sure data looks good!
fig, axs = plt.subplots(4, 4)
for i in range(4):
    for j in range(4):
        axs[i,j].imshow( x_train[ np.random.randint(x_train.shape[0]) ] )
        axs[i,j].axis('off')
plt.show()

An example output should look like this:

If x_train is empty make sure you have .jpg or .png files in the directory where your images are stored (e.g. space/)

Ways to improve images

If your images are looking bad, try to increase the number of dimensions in your latent space. Sometimes adding more dropout into the layers of the generative model can help too. This was often my go to when the discriminator had an accuracy of 100% which hindered the generator from learning.

If you can think of a way to improve the image resolution and still have it train in a sensible time with 1 GPU, let me know!

More Repositories

1

Data-VisualizAR

Visualize data or 3D models (.obj) in augmented reality through the web with Google Poly, AR.js, flask.py (Mobile compatible)
C#
309
star
2

Neural-Nebula

A deep conv. generative adversarial network trained on nebula and images of space
Python
89
star
3

Signal-Alignment

Algorithms to align 1D signals via cross correlation and likelihood maximization.
Python
68
star
4

Exoplanet-Artificial-Intelligence

Machine learning is used to search for signals of transiting exoplanets in planetary search surveys (e.g. Kepler and TESS).
Python
40
star
5

Nbody-AI

A python 3 package for generating N-body simulations, computing transit timing variations (TTV) and retrieving orbit parameters from TTV measurements within a Bayesian framework using machine learning
Python
27
star
6

pyduino_webapi

Instructable tutorial on controlling an arduino device via a web api in python
Python
21
star
7

Exoplanet-Light-Curve-Analysis

A python package for modeling exoplanet light curves with nested sampling.
Python
17
star
8

brave_ad_clicker

A Python bot to automatically close ads on the Brave browser
Python
11
star
9

Mars-Machina

A deep conv. variational autoencoder is trained on digital terrain maps of Mars from HiRise/MRO. 3D surfaces are procedurally generated from the latent space in Unity
Python
11
star
10

pyduino_leapmotion

Instructable tutorial for building a hand tracking robotic arm using python, arduino and a leap motion controller.
Python
9
star
11

PhotometryTools

Tools for performing aperture and PSF photometry in real time
Python
7
star
12

Unity-Variational-Autoencoder

A variational autoencoder made with tensorflow loaded into Unity for the procedural generation of 3D surfaces
Python
7
star
13

HiRISE-3D-Model

A python tool for creating 3D Models (.obj, .glb, .gltf) of terrain maps in Blender
Python
6
star
14

Planetary-Collision-VR

3D visualizations of planetary collisions in virtual reality with SteamVR and Unity.
C#
5
star
15

Exo-Machina

A large language model, GPT-2, is trained on ~1.6M manuscript abstracts from the ArXiv. Fine-tuning is performed with the abstracts from NASA's ADS and the model is later used to generate text for a predictive keyboard
Python
4
star
16

GeneticNeuralNetwork

A custom genetic algorithm is used to optimize the architecture of a deep neural network
Python
3
star
17

Exoplanet-Mapping

A Spitzer IRAC data reduction pipeline and 3D exoplanet brightness model using spherical harmonics
Python
3
star
18

G-Force-Flow

In this physics based platformer you must traverse an artificial gravity field inside a spatially tessellated void. Convert gravitational potential energy into kinetic energy as you swing, jump and phase your way through obstacles.
3
star
19

Exoplanet-Ionization

Compute alkali abundances in exoplanetary atmospheres subject to ionizing radiation.
Python
2
star
20

Animated-LED-Strip

A programmable LED strip with animations from a Gemma M0 microcontroller and CircuitPython
Python
2
star
21

Exoplanet-Transit-Periodogram

A custom transit periodogram which includes limb darkening effects. A transit model is quickly optimized using a linear least sq approach in order to derive a robust S/N measurement for a range of periods, durations and mid-transit epochs.
Python
1
star
22

Stock-Suite

A collection of APIs and algorithms to trade stocks
Python
1
star
23

Art-with-Depth

a collection of A.I. generated images with depth maps rendered on the web with p5js + glsl shader
JavaScript
1
star
24

3D-Abstract-Frames

A simple smart contract and a python script for minting non-fungible tokens (ERC 721) using the Polygon blockchain
Solidity
1
star
25

Rayleigh-Scattering

Empirical fits to Rayleigh scattering cross section measurements in historic data of H2, N2 and CO2 (~300-900 nm).
Python
1
star
26

Exoplanet-Mass-Fractionation

Atmospheric escape calculation for the crossover mass at which a heavier second constituent will not be dragged along with a lighter constituent (i.e. H).
Python
1
star