Coder Social home page Coder Social logo

zhardie / neural-net-random-art Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tuanle618/neural-net-random-art

0.0 1.0 0.0 6.47 MB

Repository for creating random abstract art using fully connected neural networks

License: MIT License

Jupyter Notebook 98.05% Python 1.95%

neural-net-random-art's Introduction

neural-net-random-art

Create a grayscale or colour image with predefined size image_height and image_width using fully connected neural networks.
The generation of images only requires python numpy and matplotlib.
Medium article can be found here.

Usage

You can either have a look at the jupyter notebook nb_random_art.ipynb if you want to understand the algorithm and check out several settings of the method.
For fast image generation is is recommended to use the python main programm file random_art.py

Dependencies: Python 3

numpy==1.15.3
matplotlib==3.0.0
seaborn==0.9.0

Execution

For the random_art.py programm argparse is used to define several input parameters:

parser = argparse.ArgumentParser(description="Generate random art with a deep neural network")
parser.add_argument("-img_height", metavar="", type=int, default=512,
                   help="Image height of created random art. Default is 512") 
parser.add_argument("-img_width", metavar="", type=int, default=512,
                   help="Image width of created random art. Default is 512") 
parser.add_argument("-colormode", metavar="", type=str, default="RGB",
                   help="How image color should be generated. Options are ['BW', 'RGB', 'CMYK', 'HSV', 'HSL']. By default this
                    value is 'RGB'")    
parser.add_argument("-alpha", metavar="", type=str, default="False",
                   help="Whether or not to add a alpha channel for the image. Default is False")
parser.add_argument("-n_images", metavar="", type=int, default=1,
                   help="Number of images to generate. Default is 1")    
parser.add_argument("-n_depth", metavar="", type=int, default=10,
                   help="Number of layers for the neural network. Default is 10") 
parser.add_argument("-n_size", metavar="", type=int, default=15,
                   help="Number of neurons in each hidden layer. Default is 15")
parser.add_argument("-activation", metavar="", type=str, default="tanh",
                   help="Activation function to apply on the hidden layers. Default is 'tanh'")      
parser.add_argument("-z1", metavar="", type=float, default=-0.618,
                   help="Input variable 1 to insert determinism into the random art. The value should be between -1 and 1. Default 
                    is -0.618")    
parser.add_argument("-z2", metavar="", type=float, default=+0.618,
                   help="Input variable 2 to insert determinism into the random art. The value should be between -1 and 1. Default 
                   is +0.618")
args = parser.parse_args()

So in order to create 1 RGB image of size 400x500, no alpha channel, a dense net with 15 layers, each laying having 15 neurons, type in following command in the shell:

python random_art.py -img_height 400 -img_width 500 -colormode RGB -alpha False -n_images 1 -n_depth 15 -n_size 15

Examples

Following commands were used [default params were used] to get the images stored in the result subdirectory:

python random_art.py -img_height 512 -image_width 512 -colormode BW -alpha False -n_images 5

E.g, leading to following 2 random images (resized in order to have next to each other):

python random_art.py -img_height 512 -img_width 512 -colormode RGB -alpha False -n_images 10

E.g, leading to following 2 random images (resized in order to have next to each other):

python random_art.py -img_height 512 -img_width 512 -colormode CYMYK -alpha False -n_images 5

E.g, leading to following 2 random images (resized in order to have next to each other):

python random_art.py -img_height 512 -img_width 512 -colormode HSV -alpha False -n_images 5

E.g, leading to following 2 random images (resized in order to have next to each other):

python random_art.py -img_height 512 -img_width 512 -colormode HSL -alpha False -n_images 5

E.g, leading to following 2 random images (resized in order to have next to each other):

You can try out different input arguments (larger networks and neurons, different actiation functions etc..) as suggested in the Jupyter Notebook, to see what images will be created.
For example the following images are created by deeper neural nets.
Image 1: n_depth=15 and n_size=25, Image 2: n_depth=25 and n_size=45:

License

Code under MIT License.

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.